Hello,
I’m new to LoRa and ChirpStack especially, I have a LoRa node that sends some sensor data in a specific type “t19.11h43.39p931.14g397.29f8000a10s10”. I send it like that because sometimes the data I send should look like this “t19.11h43.39p931.14g397.29fnansn” - n stands for None, so I just don’t add this field in my JSON. The problem is that my code works perfectly in the browser, but on the server I get errors. My function looks like this:
function Decode(fPort, bytes, variables) {
var jsonObject = new Object();
var temp;
var humidity;
var pressure;
var gas;
var frequency;
var amplitude;
var seconds;
var message = atob(bytes);
message = message.split(/(?=[thpgfas])/g);
var i;
for (i of message) {
switch(i[0]) {
case 't':
var str = i.slice(1);
temp = parseFloat(str);
break;
case 'h':
var str = i.slice(1);
humidity = parseFloat(str);
break;
case 'p':
var str = i.slice(1);
pressure = parseFloat(str);
break;
case 'g':
var str = i.slice(1);
gas = parseFloat(str);
break;
case 'f':
var str = i.slice(1);
frequency = parseFloat(str);
break;
case 'a':
var str = i.slice(1);
amplitude = parseFloat(str);
break;
case 's':
var str = i.slice(1);
seconds = parseFloat(str);
break;
}
}
if (!isNaN(temp)) {
jsonObject.temp = temp;
}
if (!isNaN(humidity)) {
jsonObject.humidity = humidity;
}
if (!isNaN(pressure)) {
jsonObject.pressure = pressure;
}
if (!isNaN(gas)) {
jsonObject.gas = gas;
}
if (!isNaN(frequency)) {
jsonObject.frequency = frequency;
}
if (!isNaN(amplitude)) {
jsonObject.amplitude = amplitude;
}
if (!isNaN(seconds)) {
jsonObject.seconds = seconds;
}
return jsonObject;
}
So, does someone have an idea of what is getting wrong with my code?
Best regards!