RAK3172 Remote Code Update

I have RAK3172 module and RAK7268C Gateway. I use the gateway in basic station mode. I want to remotely update or change the code of my Rak3172 module. How can I do it?

You can’t do that as you won’t be able to upload code through LORA Link !


What you want to do is FUOTA? Firmware update over LoRaWAN?

We are working on that feature, it might be available end of 2024.

@beegee How does it work ? How do you send binary data through Lora ?

LoRaWAN has a protocol defined to use downlinks to the device for a firmware upgrade over LoRa.

But it is not easy to implement. Many things that have to be solved:

  • switch to Class C for the update
  • dual bank flash to make sure a working firmware is left if the update fails (missing packets)
  • no complete firmware updates, only diffs

And there is more to it. You need in addition to the LoRaWAN server an Update server from where devices for update are selected, firmware versions are handled, …

It is not something to be done in short time.

Understood thanks. So, can I change the variables or parameters in the RAK3172 code by downlinking through AWS?

Changing variables or parameters are something different than a firmware update.

Is your RAK3172 using the standard AT command firmware and controlled by a host MCU or are you running a custom firmware built with RUI3 on the device?

Case 1, host MCU & RAK3172 controlled through AT commands
You can send downlinks to the device from AWS (don’t ask me how, I never used AWS).
Your host MCU can get the downlink packet with the parameter or variable change and change settings of the RAK3172 through AT commands.

Case 2, RAK3172 with custom firmware
The firmware will receive the downlinks through a callback, then your firmware has to check what should be changed and apply it.

I’m using the code I wrote with RUI3. Can you give an example of reading and changing downlink data? I know how to downlink from AWS, but I haven’t been able to read and modify it from the Arduino IDE yet.

Not a really simple example, but my Modbus Master firmware is using downlinks to set/reset a Modbus coil.

It implements the RX callback, analysis the received packet and then performs a Modbus write action.

Thank you for your help

Thanks a lot @beegee for explanations on how it works and makes sense although quite tricky to implement properly !

I am currently utilizing Case 1. I have a Seeed Studio XIAO SAMD21 MCU that sends AT commands to a RAK3172. We are connected to the things network and are using TagoIO to send downlink data to the things network. When we send data with the rak3172 the downlink is received on the RAK module but we cant figure out how to save that downlink value into a variable on the Seeed module using arduino.

When we manually type “AT+RECV=?” into the serial monitor we get a response from the module that prints the downlink payload as follows: AT+RECV=payload. How do we get that payload to save into a variable on the arduino Seeed MCU?

I have tried using the following code to capture downlink data:
ATgateStatus = “AT+SEND=1:” + gateStatus + randomNumber;
char receivedData[50]; // Allocate a buffer to store the received data
int bytesRead = Serial1.readBytesUntil(‘F’, receivedData, 50);
receivedData[bytesRead] = ‘\0’; // Null-terminate the string

We tried ending the payload data with ‘F’ to help the above readBytesUntil function work properly but we arent getting the ‘AT+RECV=payload’ like when we manually type into the serial monitor, instead we are getting a bunch of random commands and responses that the rak module normally employs. Is there anyway to have the rak module send the payload data to the Seeed MCU?

If a data packet is received from the server, it triggers an asynchronous event and the RAK3172 is sending an +EVT:xxxxx over the UART to your SAMD21:

You have to check your UART for this message, then you can use AT+RECV=? to get the data packet.

1 Like

In addition, when the RAK3172 sends something over the UART (asynchronous event or response to an AT command), it is terminated with /r/n, so you can read from UART until you get this sequence.

1 Like