Hello,
I am decoding the payload raw from 3 dragino devices that are conected to one gateway (ITG-200).
I need to check if statement is true to concat the right var data[] to the payload.
How can I do it?
I have the problem with this function
function dataConcat(k) {
if(k === 'A84041C6918349CE' || 'A84041AC918399DE' ) {
return [
{ variable: k + 'hex', value: console.log('primo') },
{ variable: k + 'hex', value: console.log(device) },
{ variable: k + '_BAT', value: batV /1000, unit: 'V' },
{ variable: k + '_temperature', value: temp_DS18B20, unit: '°C' },
{ variable: k + '_distance_cm', value: lidarDistance[0], unit: 'cm' },
{ variable: k + '_Distance_signal_strength', value: lidarDistance[1] },
{ variable: k + '_lidar_temperature', value: lidarDistance[2], unit: '°C' },
{ variable: k + '_flags', value: messageAndFlags[0] },
{ variable: k + '_message', value: messageAndFlags[1] }
];
} else if(k === 'A840418A2182DC01' ) {
return [
{ variable: k + 'hex', value: console.log('secondo') },
{ variable: k + 'hex', value: console.log(device) },
{ variable: k + '_BAT', value: batV /1000, unit: 'V' },
{ variable: k + '_temperature', value: temp_DS18B20, unit: '°C' },
{ variable: k + '_water_SOIL', value: nonContactLiquid[0], unit: '%' },
{ variable: k + '_temperature_SOIL', value: nonContactLiquid[1], unit: '°C' },
{ variable: k + '_conduct_SOIL', value: nonContactLiquid[2], unit: 'us/cm' },
{ variable: k + '_flags', value: messageAndFlags[0] },
{ variable: k + '_message', value: messageAndFlags[1] }
];
} else if(k === 'A84041FBB18399EC') {
return [
{ variable: k + 'hex', value: console.log('terzo') },
{ variable: k + 'hex', value: console.log(device) },
{ variable: k + '_BAT', value: batV /1000, unit: 'V' },
{ variable: k + '_temperature', value: temp_DS18B20, unit: '°C' },
{ variable: k + '_N', value: soilMeasurement[0] },
{ variable: k + '_P', value: soilMeasurement[1] },
{ variable: k + '_K', value: soilMeasurement[2] },
{ variable: k + '_flags', value: messageAndFlags[0] },
{ variable: k + '_message', value: messageAndFlags[1] }
];
} else {
//do nothing
}
It only return the first if statement. Like this:
[
{
"variable": "A84041FBB18399EC_device_eui",
"value": "A84041FBB18399EC",
"serie": "1656415416908",
"time": "2022-06-28T11:23:23.000Z"
},
{
"variable": "A84041FBB18399EC_last_message_received",
"value": "28/06/2022 08:23:36",
"serie": "1656415416908",
"time": "2022-06-28T11:23:23.000Z"
},
{
"variable": "A84041FBB18399EC_uplink",
"value": 286,
"serie": "1656415416908",
"time": "2022-06-28T11:23:23.000Z",
"unit": "count"
},
{
"variable": "A84041FBB18399EC_activation_mode",
"value": "OTAA",
"serie": "1656415416908",
"time": "2022-06-28T11:23:23.000Z"
},
{
"variable": "A84041FBB18399EC_bandwidth",
"value": "125",
"serie": "1656415416908",
"time": "2022-06-28T11:23:23.000Z",
"unit": "kHz"
},
{
"variable": "A84041FBB18399EC_spreading_factor",
"value": "10",
"serie": "1656415416908",
"time": "2022-06-28T11:23:23.000Z"
},
{
"variable": "A84041FBB18399EC_datarate",
"value": 2,
"serie": "1656415416908",
"time": "2022-06-28T11:23:23.000Z"
},
{
"variable": "A84041FBB18399EC_rssi",
"value": -63,
"serie": "1656415416908",
"time": "2022-06-28T11:23:23.000Z",
"unit": "dBm"
},
{
"variable": "A84041FBB18399EC_quality",
"value": "Forte",
"serie": "1656415416908",
"time": "2022-06-28T11:23:23.000Z"
},
{
"variable": "A84041FBB18399EC_snr",
"value": 9.2,
"serie": "1656415416908",
"time": "2022-06-28T11:23:23.000Z",
"unit": "dB"
},
{
"variable": "A84041FBB18399EC_payload_raw",
"value": "0d170000027600a8000001",
"serie": "1656415416908",
"time": "2022-06-28T11:23:23.000Z"
},
{
"variable": "A84041FBB18399EC_gateway",
"value": "0000F8033201CF1D",
"serie": "1656415416908",
"time": "2022-06-28T11:23:23.000Z"
},
{
"variable": "A84041FBB18399EChex",
"serie": "1656415416908"
},
{
"variable": "A84041FBB18399EChex",
"serie": "1656415416908"
},
{
"variable": "A84041FBB18399EC_BAT",
"value": 3.351,
"unit": "V",
"serie": "1656415416908"
},
{
"variable": "A84041FBB18399EC_temperature",
"value": "0.00",
"unit": "°C",
"serie": "1656415416908"
},
{
"variable": "A84041FBB18399EC_distance_cm",
"value": 63,
"unit": "cm",
"serie": "1656415416908"
},
{
"variable": "A84041FBB18399EC_Distance_signal_strength",
"value": -88,
"serie": "1656415416908"
},
{
"variable": "A84041FBB18399EC_lidar_temperature",
"value": 0,
"unit": "°C",
"serie": "1656415416908"
},
{
"variable": "A84041FBB18399EC_flags",
"value": 0,
"serie": "1656415416908"
},
{
"variable": "A84041FBB18399EC_message",
"value": 1,
"serie": "1656415416908"
}
]
I attach my code and the live inspector.
Thanks
Michelangelo