Lorawan error 4: Error with data length after second payload

Wireless communications in Waspmote, topologies, node types...
Post Reply
gfnord
Posts: 3
Joined: Mon Sep 09, 2019 8:14 pm
Company: Astra Smart Systems

Lorawan error 4: Error with data length after second payload

Post by gfnord » Tue Sep 10, 2019 7:16 pm

TL;DR: LoRaWAN.sendConfirmed and LoRaWAN.sendUnconfirmed fails on third and nexts after sending two successful payloads of 21 bytes size, shows error 4: Error with data length. With 5 bytes payload size it works without issue.

Hi, I think I got bug on API v42 on LoRaWAN.sendConfirmed and LoRaWAN.sendUnconfirmed functions.

I setup a Plug&Sense with 3 gases sensors/temp&humidity probes with Lorawan 915 Mhz transceiver.

I noticed when I have a payload with size of 21 bytes the P&S sends first and second payloads successfully but it fails on 3rd, 4th and so on. The payload is not received by the gateway and the application shows the error code 4, that means "Error with data length". I can confirm this happens with LoRaWAN.sendConfirmed and LoRaWAN.sendUnconfirmed functions, sending hex string or byte array.

After this I decided to reduce the payload to only 5 bytes to test, and in this case the same code sends the payload successful every time, using both functions, confirmed and unconfirmed.

I also tested using Data Rate 4 and Data Rate 3. I'm sending the payload every 4 minutes. Both have same behaviour. Using the test lorawan code it works without any issue.

Here are the relevant parts of my code:

// Create the byte array to be sent by lorawan
uint8_t payload[21];
uint16_t payload_size = sizeof(payload);
uint8_t payload_small[5];
uint16_t payload_small_size = sizeof(payload_small);

uint8_t socket = SOCKET0; //Lora socket

float concentrationA; // Stores the concentration level in ppm of SOCKET A
float concentrationB; // Stores the concentration level in ppm of SOCKET B
float concentrationC; // Stores the concentration level in ppm of SOCKET C
float temperature; // Stores the temperature in ºC
float humidity; // Stores the realitve humidity in %RH
float pressure; // Stores the pressure in Pa

// Read enviromental variables
temperature = bme.getTemperature();
humidity = bme.getHumidity();
pressure = bme.getPressure();

concentrationA = gas_A_sensor.getConc();
concentrationB = gas_B_sensor.getConc();
concentrationC = gas_C_sensor.getConc();

// Clear the buffer of payload
memset(payload,0x00,sizeof(payload));
memset(payload_small,0x00,sizeof(payload_small));

uint8_t battery_level = PWR.getBatteryLevel();
uint16_t temp = temperature * 100;
uint16_t humi = humidity * 100;
uint32_t pres = pressure * 100;
uint32_t concA = concentrationA * 100;
uint32_t concB = concentrationB * 100;
uint32_t concC = concentrationC * 100;

// Full payload
payload[0] = temp >> 8;
payload[1] = temp;
payload[2] = humi >> 8;
payload[3] = humi;
payload[4] = pres >> 24;
payload[5] = pres >> 16;
payload[6] = pres >> 8;
payload[7] = pres;
payload[8] = concA >> 24;
payload[9] = concA >> 16;
payload[10] = concA >> 8;
payload[11] = concA;
payload[12] = concB >> 24;
payload[13] = concB >> 16;
payload[14] = concB >> 8;
payload[15] = concB;
payload[16] = concC >> 24;
payload[17] = concC >> 16;
payload[18] = concC >> 8;
payload[19] = concC;
payload[20] = battery_level;

// Small payload
payload_small[0] = battery_level;
payload_small[1] = temp >> 8;
payload_small[2] = temp;
payload_small[3] = humi >> 8;
payload_small[4] = humi;


error = LoRaWAN.ON(socket);
error = LoRaWAN.joinABP();
error = LoRaWAN.sendConfirmed(PORT, payload, payload_size);

libelium-dev
Posts: 27967
Joined: Mon Sep 28, 2009 1:06 pm

Re: Lorawan error 4: Error with data length after second payload

Post by libelium-dev » Wed Sep 11, 2019 2:19 pm

Hi,

The data rate changes automatically according to the network coverage. When the data rate is 0, the maximum payload is 11 bytes. You can check the maximun payload in the following table
http://www.libelium.com/downloads/docum ... df#page=38

We recommend that the payload doesn't exceed 11bytes for proper operation in a LoRaWAN US network. If the data rate is 0 and the payload is greater than 11, the sending will report error 4.

Regards

gfnord
Posts: 3
Joined: Mon Sep 09, 2019 8:14 pm
Company: Astra Smart Systems

Re: Lorawan error 4: Error with data length after second payload

Post by gfnord » Thu Sep 12, 2019 8:34 pm

Hi, thank you for the explanation.

But I have set the data rate to 2, fixed during the setup.

error = LoRaWAN.setDataRate(2);

Which means the maximum payload size is up to 129 bytes.

I did not explicity disabled the ADR so, I'll do it and test again. I agree with you to keep the payload below 11 bytes on LoRaWAN US network once I have the ADR enabled, but is not this case.

gfnord
Posts: 3
Joined: Mon Sep 09, 2019 8:14 pm
Company: Astra Smart Systems

Re: Lorawan error 4: Error with data length after second payload

Post by gfnord » Thu Sep 12, 2019 10:38 pm

Okay, I fixed the code adding
LoRaWAN.setADR("off");
before
LoRaWAN.sendConfirmed(PORT, payload, payload_size);
since I noticed on the third time the ADR changed to ON automatically.

libelium-dev
Posts: 27967
Joined: Mon Sep 28, 2009 1:06 pm

Re: Lorawan error 4: Error with data length after second payload

Post by libelium-dev » Mon Sep 16, 2019 9:51 am

Glad to hear that you solved the issue!

The data rate changes when the coverage is good although the ADR was set to off. So it is needed to force the data rate in each loop.

Regards

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest