Hi All,
I’ve found great help on this forum before with getting data flowing nicely into my Ubidots dashboard via TTN.
I’m unsure how to convert my data from C to F. I tried contacting Dragino, but havent received an answer. Unfortunately, i am only beginning to learn to code. Anyone able to help me understand how i can edit my decoder to convert Celsius to Fahrenheit?
Below is my current working decoder under Plugins(‘temp_channel1’ is the variable i use in dashboard):
function format_payload(args){
var ubidots_payload = {};
// Log received data for debugging purposes:
// console.log(JSON.stringify(args));
// Get RSSI and SNR variables using gateways data:
var gateways = args['uplink_message']['rx_metadata'];
for (const i in gateways) {
// Get gateway EUI and name
var gw = gateways[i];
var gw_eui = gw['gateway_ids']['eui'];
var gw_id = gw['gateway_ids']['gateway_id'];
// Build RSSI and SNR variables
ubidots_payload['rssi-' + gw_id] = {
"value": gw['rssi'],
"context": {
"channel_index": gw['channel_index'],
"channel_rssi": gw['channel_rssi'],
"gw_eui": gw_eui,
"gw_id": gw_id,
"uplink_token": gw['uplink_token']
}
}
ubidots_payload['snr-' + gw_id] = gw['snr'];
}
// Get Fcnt and Port variables:
ubidots_payload['f_cnt'] = args['uplink_message']['f_cnt'];
ubidots_payload['f_port'] = args['uplink_message']['f_port'];
// Get uplink's timestamp
ubidots_payload['timestamp'] = new Date(args['uplink_message']['received_at']).getTime();
// If you're already decoding in TTS using payload formatters,
// then uncomment the following line to use "uplink_message.decoded_payload".
// PROTIP: Make sure the incoming decoded payload is an Ubidots-compatible JSON (See https://ubidots.com/docs/hw/#sending-data)
//var decoded_payload = args['uplink_message']['decoded_payload'];
// By default, this plugin uses "uplink_message.frm_payload" and sends it to the decoding function "decodeUplink".
// For more vendor-specific decoders, check out https://github.com/TheThingsNetwork/lorawan-devices/tree/master/vendor
ubidots_payload['temp_channel1'] = args['uplink_message']['decoded_payload']['Temp_Channel1']
//let bytes = Buffer.from(args['uplink_message']['frm_payload'], 'base64');
//var decoded_payload = decodeUplink(bytes)['data'];
// Merge decoded payload into Ubidots payload
//Object.assign(ubidots_payload, decoded_payload);
return ubidots_payload
}
function decodeUplink(bytes) {
// Decoder for the RAK1906 WisBlock Environmental Sensor (https://store.rakwireless.com/products/rak1906-bme680-environment-sensor)
var decoded = {};
if (bytes[0] == 1) {
// If received data is of Environment Monitoring type
decoded.temperature = (bytes[1] << 8 | (bytes[2])) / 100;
decoded.humidity = (bytes[3] << 8 | (bytes[4])) / 100;
decoded.pressure = (bytes[8] | (bytes[7] << 8) | (bytes[6] << 16) | (bytes[5] << 24)) / 100;
decoded.gas = bytes[12] | (bytes[11] << 8) | (bytes[10] << 16) | (bytes[9] << 24);
}
return {"data": decoded};
}
module.exports = { format_payload };
Thanks!
William