Hi,
I’m having trouble trying to display rssi and snr from a device connected to the TTN to ubidots. I’m trying to record packet rssi and snr to test and validate different antenna designs out in the field, and it’d be great for ubidots to display these as a device variable - so that I can review the saved data.
I have been referring to this link, in order to try and pull out the relevant metadata I’m interested in. I’m using the http integration on the TTN to send data to ubidots.
I’ve edited the ubifunctions code to get rssi and snr from the metadata but am struggling to include them as a device variable. Here is the code I’m using within the ubifunctions:
var request = require(‘request-promise’);
// Assign your Ubidots TOKEN
var token = “xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”;
// This function build the HTTP POST request to Ubidots
async function ubidotsPost(deviceLabel, data) {
var options = {
method: 'POST',
url: 'https://industrial.api.ubidots.com/api/v1.6/devices/' + deviceLabel,
body: data,
json: true,
headers: {
'Content-Type': 'application/json',
'X-Auth-Token': token
}
};
return await request.post(options);
}
async function main(args) {
var deviceLabel = args['hardware_serial'];
var payload = args['payload_fields'];
var packet_data = args['metadata'];
var gateway = packet_data.gateways[0]; //Connected gateways are stored in array, lets look at the first one
// Sends the data incoming to Ubidots
console.log(deviceLabel);
console.log(payload);
console.log(gateway.rssi);
console.log(gateway.snr);
await ubidotsPost(deviceLabel, payload, packet_data);
return {parser_status: "OK"};
}
Any suggestions on editing the ubifunctions code would be greatly appreciated.