RAK7268, Problem Decoding CayenneLPP

My device is sending a CayenneLPP payload to the RAK7268 which passed on the MQTT message to my local Mosquitto instance. No cloud, no TTN, etc… The RAK7268 is running the latest firmware V1.3.1.

The Base64 payload sent from the device is:

“data”: “AGdtdAFodAIA/gMByA==”,
“data_encode”: “base64”,

The RAK7268 decoded the payload to:
“object”: {
“temperature”: 2802,
“humidity”: 58,
“analogOutput”: 4.56

However, the correct decoding should be:
Base64 to hex of data above

00 67 6d 74 (temperature) = 28020/10 = 2802
01 68 74 (humidity) = 116 (116/2) = 58
02 00 fe (digital input) = 254 (max battery)
03 01 c8 (digital output) = 200

Is this a bug, or could I be doing something wrong. Thanks.

For your help, you can use this site to determine the conversion:

Are you implying that

“AGdnwAFoegIA/g==” (base64) converted to hex isn’t “006767c001687a0200fe”

The temperate and humidity information from the payload is decoded correctly. There is no conversion for the DigitalOutput sensor and the “analogOutput” is wrong.

So it appears that the RAK gateway is receiving the correct information from the device, however, it’s not producing the correct MQTT message.

what’s your device ?

It’s a custom design based on the RAK3172 (STM32WL). I’m using STM32CubeIDE and the LoRaWAN_End_node code.

Here is a section of the key code contained in lora_app.c: Thanks!

CayenneLppAddTemperature(channel++, tempC);
CayenneLppAddRelativeHumidity(channel++, humidity1);
CayenneLppAddDigitalInput(channel++, GetBatteryLevel());
CayenneLppAddDigitalOutput(channel++, 200);
AppData.BufferSize = CayenneLppGetSize();

/* USER CODE BEGIN SendTxData_1 */

/* USER CODE END SendTxData_1 */

… ten thousand feet in the air…

could you change your code with this and paste the result:

CayenneLppAddTemperature(0, tempC);
CayenneLppAddRelativeHumidity(1, humidity1);
CayenneLppAddDigitalInput(2, GetBatteryLevel());
CayenneLppAddDigitalOutput(3, 200);

No luck - here is the entire MQTT received message:

Message 3 received on application/1/device/ac1f09fffxxxxxxx/rx
“applicationID”: “1”,
“applicationName”: “rak_mqtt_test”,
“devEUI”: "ac1f09fffxxxxxxx”,
“deviceName”: “RAK3172_ClassC”,
“timestamp”: 1646632692,
“fCnt”: 4,
“fPort”: 2,
“data”: “AGdtugFocAIA/gMByA==”,
“data_encode”: “base64”,
“object”: {
“temperature”: 2809,
“humidity”: 56,
“analogOutput”: 4.56
“adr”: true,
“rxInfo”: [
“gatewayID”: "ac1f09fffxxxxxxx”,
“loRaSNR”: 13.5,
“rssi”: -13,
“location”: {
“latitude”: 0,
“longitude”: 0,
“altitude”: 0
“txInfo”: {
“frequency”: 903100000,
“dr”: 3

TL;DR: Cayenne LPP decoding in RAK7268 is half-baked.
Some details:
I had the same problem. The Cayenne LPP decoding in the gateway is limited and does not support some data types. I tested it a bit and “temperature”, “humidity” and “analog input” values seem to work, while “digital input”, “digital output” etc. do not. I used " ElectronicCats/CayenneLPP: Library for Arduino compatible with Cayenne Low Power Payload (github.com)" to encode the data, which should be close enough to standard.
You can either:
a) Use the actually working data types and reinterpret them later (I use “analog input” type for all non-supported types and parse later by sequence).
b) Turn off Cayenne LPP decoding and do the full decode yourself.
Of course, a proper implementation of Cayenne LPP decoding in the gateway by the RAK developers would be the preferred option :slight_smile:

I did some tests with your code like this;

#################### KELENA TEST ################################
lpp.add_temperature(0, 2802)
lpp.add_relative_humidity(1, 58)
lpp.add_digital_input(2, 254)
lpp.add_digital_output(3, 200)
#################### KELENA TEST ################################

and here’s my result:


I suspect your LORAWAN Mac version you’re using…

Did another test by changing the LORAWAN Mac version from 1.0.2 to 1.0.3 in the Device-profile, and nothing was found under objectJSON, after this changes ???

So in my case I used PYCOM lopy (1.0.2) for my test.

According to RAK3172 specs:
The module complies with Class A, ClassB, Class C of LoRaWAN 1.0.3 specifications
So, validate that you defined your device with Mac version 1.0.3


Thanks for looking into this. I’ve tried changing gateway setting to both LoRaWAN 1.0.2 and 1.0.3. Neither setting had any effect. I’m puzzled because the uplink data from the device seems correct, yet the gateway isn’t decoding it as expected. Could there be another gateway setting that could effect the decoding?

Franki - thanks for your feedback. I might pursue one of your recommendations if necessary. It’s odd that ric2498 was able to get the correct decoding.

Could you paste the device profile from your application server that you’re using ?

Maybe there might be a new firmware we are both not using?
I doubt the MAC setting would do anything here, the decoder works on already received data.
Edit: There is a new firmware version 1.3.2, but there are no release notes for it.

I just tried version 1.3.2. No help. :slightly_frowning_face:

I was not too hopeful.
BTW, where (on what device/platform) do you use the decoded data? Can you implement the decoding on your own?


RAK7268; Connection with LNS

Depending on the selected region, the gateway is already partially preconfigured and you only have to select the respective LoRaWAN network server. To connect to an LNS, the RAK7268 supports various communication options, including the classic UDP option, but also Basic Station or an MQTT bridge for servers like ChirpStack (or Datacake).

Based on these information’s for RAK7268, could you give more details on your configuration ?

The MQTT messages are consumed by Home Assistant. It’s possible to have Home Assistant do the decoding, however there will be a learning curve for myself. Not where I wanted to spend my time. Might involve writing an integration or similar. I might have to do this. :frowning:

Sure - happy to give you whatever configuration information is needed. First a simple description on the data flow. My device (sensor) sends it’s CayenneLPP payload to the RAK7268 (US915, ClassC, OTAA).
I’m intending the RAK7268 to decode the CayenneLPP payload and send the data via an MQTT message to a local Mosquitto server on the local network. Home Assistant subscribes to the MQTT messages and acts on the sensor data. This all works just fine except that only the CayenneLPP temperature and humidity data decoding works. Does the RAK7268 conform to CayenneLPP as implemented by myDevices, ElectronicCats, or STM32WL SDK? Here is my configuration screen for the LoraWAN Network Settings:

The Application Server Configuration:

Let me know if any other information is needed.

Well, I can help you by showing what I did. I send all the unsupported data types as analogInput from my MQTT device (Arduino snippet).

  lpp.addTemperature(1, temp.temperature);
  lpp.addRelativeHumidity(2, humidity.relative_humidity);
  lpp.addAnalogInput(3, digitalRead(D0));
  lpp.addAnalogInput(4, digitalRead(D1));
  lpp.addAnalogInput(5, digitalRead(D2));
  lpp.addAnalogInput(6, digitalRead(D3));

In HA I read this as one big sensor and parse it by sequence like this (value template is just one big line) to get a useable JSON result:

- sensor:
  - name: "Postaja 1"
    platform: mqtt
    state_topic: application/2/device/2cf7f1203230408d/rx
    value_template: "{{value.split(',')[0]}},{{value.split(',')[1]}},{{value.split(',')[2]}},{{value.split(',')[3] | regex_replace(find='Input', replace='Input2', ignorecase=False)}},{{value.split(',')[4] | regex_replace(find='Input', replace='Input3', ignorecase=False)}},{{value.split(',')[5] | regex_replace(find='Input', replace='Input4', ignorecase=False)}}"

After that I can take the big sensor JSON output and split it using template sensors:

- sensor:
  - name: temperatura_rak_1
    state: '{{(states("sensor.rak_1") | from_json).temperature | float(default=0)}}'
    unit_of_measurement: '°C'
  - name: vlaznost_rak_1
    state: '{{(states("sensor.rak_1") | from_json).humidity | float(default=0)}}'
    unit_of_measurement: '%'
  - name: baterija_rak_1
    state: '{{(states("sensor.rak_1") | from_json).analogInput | float(default=0)}}'
    unit_of_measurement: 'V'
  - name: kakovost_zraka_rak_1
    state: '{{(states("sensor.rak_1") | from_json).analogInput2 | int(default=0)}}'
    unit_of_measurement: ''