CubeCell Capsule TTN Payload Decoder for BMP180

Is there a payload decoder for the CubeCell Capsule BMP180? I am using the unmodified example sketch for Arduino and can see the received payload in the TTN.
I am using one from here https://github.com/HelTecAutomation/CubeCell-Arduino/tree/master/libraries/LoRa/examples/LoRaWAN/LoRaWAN_Sensors
for the HDC1080 Light Sensor that works well and have tried the Multisensor example without success. I am a newb when it comes to JS. Any help is appreciated.

this should help:

Thanks, I was hoping that there was a ready made solution, but I am sure I will learn more about payload encoding from your link.

Cheers

temperature is a 4 bytes and start at byte 0 in that example to decode it you would do as follow:

function Decoder(bytes, Port) {
         var result = {};
         var temp= ((bytes[3]) << 24) | ((bytes[2]) << 16) | ((bytes[1]) << 8) | (bytes[0]);
//same goes for pressure: which starts at byte 4 so:
         var pressure= ((bytes[7]) << 24) | ((bytes[6]) << 16) | ((bytes[5]) << 8) | (bytes[4]);

//same goes for altitude which starts at byte 8:
        var altitude= ((bytes[11]) << 24) | ((bytes[10]) << 16) | ((bytes[9]) << 8) | (bytes[8]);

//voltage is represented by 2 bytes starting at byte 12:
        var batteryVoltage= (bytes[13] << 8) | (bytes[12]);

        result = {
            "temperature": temp,
            "pressure": pressure,
            "altitude": altitude,
            "batteryVoltage": batteryVoltage,
       }
     return result;
}

i hope the above and this helps.

Thanks. I can see what the Javascript code is doing but the output is not right. Here is a typical payload
CDCC9DC200F4F547470AEAC40F64
but, decoded payload looks like this.

“decoded_payload”: {
“altitude”: -991294905,
“batteryVoltage”: 25615,
“pressure”: 1207301120,
“temperature”: -1029845811

I have tried reversing the byte order to no avail. Arduino sketch byte order looks like it should be ok.

This is an extract from the Arduino sketch(Heltec LoraWAN example)
unsigned char *puc;
puc = (unsigned char *)(&temperature);
appDataSize = 14;
appData[0] = puc[0];
appData[1] = puc[1];
appData[2] = puc[2];
appData[3] = puc[3];

puc = (unsigned char *)(&pressure);
appData[4] = puc[0];
appData[5] = puc[1];
appData[6] = puc[2];
appData[7] = puc[3];

puc = (unsigned char *)(&altitude);
appData[8] = puc[0];
appData[9] = puc[1];
appData[10] = puc[2];
appData[11] = puc[3];

appData[12] = (uint8_t)(batteryVoltage>>8);
appData[13] = (uint8_t)batteryVoltage;

I am at a loss for further things to try.

since you are dealing with floats, you will need to convert the bytes back to float, so try this for the decoder:

function tofloat32(a1,a2,a3,a4){
                                var s=(a1&0xff)>>7;
                                var E=(a1<<1&0xff)|a2>>7;
                                var M0=(a2&0x7f)<<16|a3<<8|a4;
                                var M=1;
                                for(var i=0;i<23;i++)
                                {
                                  if(M0>>i&0x01==1)
                                    {
                                      M=M+Math.pow(2,i-23);
                                    }
                                }
                                var result=Math.pow(-1,s)*M*Math.pow(2,E-127);
                                return result;
                                }

function Decoder(bytes, Port)
{
                                var temperature = tofloat32(bytes[3],bytes[2],bytes[1],bytes[0]);
                      var  pressure = tofloat32(bytes[7],bytes[6],bytes[5],bytes[4]);
                   	var altitude = tofloat32(bytes[11],bytes[10],bytes[9],bytes[8]);
              
      								var voltge = bytes[12]<<8|bytes[13];
      								
      							           var result={
                                    "sensor":{
                                               "Temperature":temperature,
                                      		 "Humidity":pressure,
                                      		 "altitude": altitude,
                                      		 "Voltge":voltge,
                                      		 
                                             }
                                  }
                         return  result;
                      }
1 Like

Yes, that’s the one. It works fine. Thank you. For a while I doubted it worked as I was getting a crazy temperature value but maybe I have a faulty sensor as I have confirmed via the serial port on the Heltec capsule that the same value was sent so more investigation required.

I have learned some more so thanks again.