Hi Nick,
Yes i spend few more hours and i figured that the data is fixed and is sent straight from the sensor over to the network like that.
My problem now (im guessing) is that I am able to decode the payload but the order in which the payload is decoded or sent is not correct and the “Helium Cargo API” cant located the GPS. (displays GPS NOT FIX)
HOWEVER, if i take the HEX string tester from the decoder and i send it via the RAK Console with the at+send=lora:1:0188053797109D5900DC140802017A0768580673256D0267011D040214AF0371FFFFFFDDFC2E im able to get the data correctly.
Based on the Helium Dev Release Notes they point out that the payload has to be in the following order:
Total Payload:
12 Bytes without Battery Voltage
14 Bytes with Battery Voltage
Packed in the following order:
Order of Payload:
int32_t Latitude in Degrees
int32_t Longitude in Degrees
int16_t Elevation in Meters
int16_t Speed in mph
uint16_t Battery Voltage (Optional)
But the decoded payload comes in on the debuger like this:
*"decoded": {*
* "payload": {*
* "altitude": "340.5m",*
* "latitude": "13.3239°",*
* "longitude": "-747.291°"*
Here is the whole function for the decoder i have set up:
*> // ttn application function to decode uplink data.*
* > // Decode decodes an array of bytes into an object.*
* > // - port contains the LoRaWAN fPort number*
* > // - bytes is an array of bytes, e.g. [225, 230, 255, 0]*
* > // The function must return an object*
* > // for RAK, return {*
* > // "DecodeDataHex": {} // RAK5205 sensor data in Hex format*
* > // "DecodeDataObj": {} // RAK5205 sensor data object.*
* > // }*
* > // The function prototype cannot be modified.*
* > function Decoder(bytes, port) {*
* > var decoded = {"DecodeDataHex": {}, "DecodeDataObj": {}};*
* > var hexString=bin2HexStr(bytes);*
* > decoded.DecodeDataHex = hexString;*
* > decoded.DecodeDataObj = rakSensorDataDecode(hexString);*
* > *
* > return decoded;*
* > }*
* > *
* > // convert array of bytes to hex string.*
* > // e.g: 0188053797109D5900DC140802017A0768580673256D0267011D040214AF0371FFFFFFDDFC2E*
* > function bin2HexStr(bytesArr) {*
* > var str = "";*
* > for(var i=0; i<bytesArr.length; i++) {*
* > var tmp = (bytesArr[i] & 0xff).toString(16);*
* > if(tmp.length == 1) {*
* > tmp = "0" + tmp;*
* > }*
* > str += tmp;*
* > }*
* > return str;*
* > }*
* > *
* > // convert string to short integer*
* > function parseShort(str, base) {*
* > var n = parseInt(str, base);*
* > return (n << 16) >> 16;*
* > }*
* > *
* > // convert string to triple bytes integer*
* > function parseTriple(str, base) {*
* > var n = parseInt(str, base);*
* > return (n << 8) >> 8;*
* > }*
* > *
* > // decode Hex sensor string data to object*
* > function rakSensorDataDecode(hexStr) {*
* > var str = hexStr;*
* > var myObj = {};*
* > var environment = {};*
* > var magnetometer = {};*
* > *
* > while (str.length > 4) {*
* > var flag = parseInt(str.substring(0, 4), 16);*
* > switch (flag) {*
* > case 0x0768:// Humidity*
* > environment.humidity = ((parseShort(str.substring(4, 6), 16) * 0.01 / 2) * 100).toFixed(1) + '% RH';*
* > str = str.substring(6);*
* > break;*
* > case 0x0673:// Atmospheric pressure*
* > environment.barometer = (parseShort(str.substring(4, 8), 16) * 0.1).toFixed(2) + "hPa";*
* > str = str.substring(8);*
* > break;*
* > case 0x0267:// Temperature*
* > environment.temperature = (parseShort(str.substring(4, 8), 16) * 0.1).toFixed(2) + "°C";*
* > str = str.substring(8);*
* > break;*
* > case 0x0188:// GPS*
* > var gps = {};*
* > gps.latitude = (parseTriple(str.substring(4, 10), 16) * 0.0001).toFixed(4) + "°";*
* > gps.longitude = (parseTriple(str.substring(10, 16), 16) * 0.0001).toFixed(4) + "°";*
* > gps.altitude = (parseTriple(str.substring(16, 22), 16) * 0.01).toFixed(1) + "m";*
* > myObj.gps = gps;*
* > str = str.substring(22);*
* > break;*
* > case 0x0371:// Triaxial acceleration*
* > var acceleration = {};*
* > acceleration.x = (parseShort(str.substring(4, 8), 16) * 0.001).toFixed(3) + "g";*
* > acceleration.y = (parseShort(str.substring(8, 12), 16) * 0.001).toFixed(3) + "g";*
* > acceleration.z = (parseShort(str.substring(12, 16), 16) * 0.001).toFixed(3) + "g";*
* > myObj.acceleration = acceleration;*
* > str = str.substring(16);*
* > break;*
* > case 0x0402:// air resistance*
* > environment.gasResistance = (parseShort(str.substring(4, 8), 16) * 0.01).toFixed(2) + "KΩ";*
* > str = str.substring(8);*
* > break;*
* > case 0x0802:// Battery Voltage*
* > myObj.battery = (parseShort(str.substring(4, 8), 16) * 0.01).toFixed(2) + "V";*
* > str = str.substring(8);*
* > break;*
* > case 0x0586:// gyroscope*
* > var gyroscope = {};*
* > gyroscope.x = (parseShort(str.substring(4, 8), 16) * 0.01).toFixed(2) + "°/s";*
* > gyroscope.y = (parseShort(str.substring(8, 12), 16) * 0.01).toFixed(2) + "°/s";*
* > gyroscope.z = (parseShort(str.substring(12, 16), 16) * 0.01).toFixed(2) + "°/s";*
* > myObj.gyroscope = gyroscope;*
* > str = str.substring(16);*
* > break;*
* > case 0x0902:// magnetometer x*
* > magnetometer.x = (parseShort(str.substring(4, 8), 16) * 0.01).toFixed(2) + "μT";*
* > str = str.substring(8);*
* > break;*
* > case 0x0a02:// magnetometer y*
* > magnetometer.y = (parseShort(str.substring(4, 8), 16) * 0.01).toFixed(2) + "μT";*
* > str = str.substring(8);*
* > break;*
* > case 0x0b02:// magnetometer z*
* > magnetometer.z = (parseShort(str.substring(4, 8), 16) * 0.01).toFixed(2) + "μT";*
* > str = str.substring(8);*
* > break;*
* > default:*
* > str = str.substring(7);*
* > break;*
* > }*
* > }*
* > if(Object.getOwnPropertyNames(environment).length > 0) {*
* > myObj.environment = environment;*
* > }*
* > if(Object.getOwnPropertyNames(magnetometer).length > 0) {*
* > myObj.magnetometer = magnetometer;*
* > }*
* > *
* > return myObj;*
* > }*
Here a screenshot when the sensor send it automatically and get decoded using the tool:
Any idea why am i getting the decoded message is that order instead of the correct one?