I’m currently developing a intregation code with BME280 and a heltec wifi lora 32 v2 board. I’m adapting the code from GitHub - ph2lb/LoRaWAN_TTN_Env_Node: BME280 and Adruino ProMini based enviromental node with LMIC ABP. in order to send the temperature, humidity and pressure to my chirpstack server. I have to change the library used in the original code in order to use the BM280 library from platformio and removed other code that I will not use.
The problem I’m currently having is when the the Lora sends the payload to the server, the data that comes in the uplink is corrupted.
This is how I’m building the data:
int t = (int)(temp);
int p = (int)(pressure);
int h = (int)(humidity);
unsigned char mydata[5];
mydata[0] = h & 0xFF;
mydata[1] = t >> 8;
mydata[2] = t & 0xFF;
mydata[3] = p >> 8;
mydata[4] = p & 0xFF;
LMIC_setTxData2(1, mydata, sizeof(mydata), 0);
And this is how is comming in the uplink package: * data:"LQAgA+Q=" If you translate from basecode64 it will result in trash-code. Why is happening this?
So you translate LQAgA+Q= and get 2d 00 20 03 e4? What program do you use to translate base64 to byte? I’m using the same page I translate a “hello world” in past tests directly from base64, not to byte
None, I’m just using chirpstack in order to recieve the data from the LoRa Device and translating the data manually. I know it may sound weird but this is just for testing the communication between LoRa, Gateway and server.
mydata[0] = h & 0xFF;
mydata[1] = t >> 8;
mydata[2] = t & 0xFF;
mydata[3] = p >> 8;
mydata[4] = p & 0xFF;
Humidity goes into byte 0 (and is truncated to the range 0 to 255). Temperature goes into bytes 1 and 2 (most significant bits in byte 1, i.e. big endian format). Pressure goes into bytes 3 and 4 (big endian as well).
Careful, these are numbers denoted in hexadecimal, so you should write a 0x in front of them to signify that it’s not a decimal number. With the hex digit system being (0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f) corresponding to (0…15). Then see that hex to decimal conversion for 2-digit hex values can be done by writing 16 * left_digit + right_digit, so:
0x2d
0x2 * 16 + 0xd
2 * 16 + 13
32 + 13
45
Since these are just different displayed strings from the same underlying numerical value you won’t have to do that conversion in code. Underlying it’s all just integers.
However usually the goal is not to decode the frame payload in Chirpstack anyways, but the integration you have configured in Chirpstack where the data is forwarded to, e.g. a HTTP, InfluxDB, MQTT, Azure, AWS,… (all listed at https://www.chirpstack.io/application-server/integrate/sending-receiving/) server so depending on where the data is pushed to it needs decoding logic in a different language there on the server.