Sensor values BME; Dragino LA66 LoRaWAN Module

Hello,

I am an absolute beginner in Lora. That’s why I propably already have made several stupid mistakes.

The idea is to transport sensorreadings every half hour (BME280; temperature, humidity, pressure) to the Things Network. Therefore, the sensor is plugged into a Dragino shield (LA66 LoRaWAN Shield). An example sketch provided by Dragino on their website (Dropbox - Log-Temperature-Sensor-and-send-data-to-TTN - Simplify your life), is modified by including the code for the sensorreadings.

Unfortunately, it is a struggle to include the pressure reading in the payload. I assume, this must be a long integer (temperature and humidity are short integers). Whatever I have done so far, it was not a succes….

Below the code which include sensor readings for temperature and humidity (correct values):

void loop() {

//digitalWrite(BEE_VCC, HIGH); // keep rn2483 running

// pick up sensor value

float celsius = bme.readTemperature();

float percentage = bme.readHumidity();

char sensor_data_buff[128]="\0";

//translate float value to int 16 bit and long to get rid of the .

int16_t temperature = (int16_t)(celsius * 100);

int16_t humidity = (int16_t)(percentage * 100);

long pressure = bme.readPressure();

//confirm status,Fport,payload length,payload(HEX)

snprintf(sensor_data_buff,128,"AT+SENDB=%d,%d,%d,%02X%02X%02X%02X",0,2,4,(short)(temperature)>>8 & 0xFF,(short)(temperature) & 0xFF,(short)(humidity)>>8 & 0xFF,(short)(humidity) & 0xFF);

ss.println(sensor_data_buff);

When pressure included, pressure value is zero….:

void loop() {

//digitalWrite(BEE_VCC, HIGH); // keep rn2483 running

// pick up sensor value

float celsius = bme.readTemperature();

float percentage = bme.readHumidity();

char sensor_data_buff[128]="\0";

//translate float value to int 16 bit and long to get rid of the .

int16_t temperature = (int16_t)(celsius * 100);

int16_t humidity = (int16_t)(percentage * 100);

long pressure = bme.readPressure();

//confirm status,Fport,payload length,payload(HEX)

snprintf(sensor_data_buff,128,"AT+SENDB=%d,%d,%d,%02X%02X%02X%02X",0,2,4,(short)(temperature)>>8 & 0xFF,(short)(temperature) & 0xFF,(short)(humidity)>>8 & 0xFF,(short)(humidity) & 0xFF,(long)(pressure)>>8 & 0xFF,(long)(pressure) & 0xFF);

ss.println(sensor_data_buff);

The following payload formatter (Javascript) is used:

function decodeUplink(input) {

var temperature = (input.bytes[0] << 8 | input.bytes[1]);

var humidity = (input.bytes[2] << 8 | input.bytes[3]);

var pressure = (input.bytes[4] << 8 | input.bytes[5]);

return {

data: {

Temperature: temperature / 100,

Humidity: humidity / 10,

Pressure: pressure / 100

}

}

}

What could possibly be wrong?

Kind regards,
Pim.

Welcome

Can you please format your post and place all text, code with the post formatting tool </> makes it easier for the volunteers to read toy post.

Here you are only dealing with positive numbers, what happens if your sensor reads - 25?

Barometric pressure is in the region of 1000, so hex FF represents what decimal amount?

Read here a bit