Hi everyone,
After modify the marshaler i have thinked that all looks good to get the mqtt message but today i try to integrate it in a application and … i constat that i have not a readable json message.
look at the end inside objectJSON
specialy concerning the “\”
{
"applicationID":"3",
"applicationName":"sondehumtemp",
"deviceName":"node01",
"devEUI":"YMWo//kkk8c=",
"rxInfo":
[
{
"gatewayID":"3KYy//4XXXXX",
"timeSinceGPSEpoch":null,
"rssi":-67,
"crcStatus":"CRC_OK"
}
],
"txInfo":
{
"frequency":867900000,
"modulation":"LORA",
"loRaModulationInfo":
{
"bandwidth":125,
"spreadingFactor":12,
"codeRate":"4/5",
"polarizationInversion":false
}
},
"adr":true,
"fCnt":529,
"fPort":8,
"data":"CAIBbgdoXQZzJXcCZwDNBAIC4g==",
"objectJSON":"
{
\"DecodeDataHex\":\"0802016e07685d06732577026700cd040202e2\",
\"DecodeDataObj\":
{
\"battery\":\"3.66V\",
\"environment\":
{
\"barometer\":\"959.10hPa\",
\"gasResistance\":\"7.38KΩ\",
\"humidity\":\"46.5% RH\",
\"temperature\":\"20.50°C\"
}
}
}",
"tags":{}
}
Why i get this backslash symbol “\” ?? as it announce a special charatere…
i suppose there is a mistake in my codec…
but i dont see why this backslash is added…
rak72xx payload codec from https://github.com/RAKWireless/RUI_LoRa_node_payload_decoder/blob/master/RUISensorDataDecoder_for_ChirpStack.js
// chirpstack application function to decode uplink data.
// Decode decodes an array of bytes into an object.
// - fPort 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 Decode(fPort, bytes) {
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;
}
i would like to add that i integrate a postgresql DB and no problem…
an futhermore i have done some query in this DB with grafana without troubles too…
someone could help me?