Sending Array of objects to LORA o/p node.
Home › Forums › Conduit: AEP Model › Sending Array of objects to LORA o/p node.
Tagged: Conduit Aep, LORA o/p Node.
- This topic has 6 replies, 4 voices, and was last updated 8 years, 9 months ago by
Lawrence Griffiths.
-
AuthorPosts
-
February 9, 2017 at 3:34 pm #16952
Ajay K
ParticipantIs it possible to send an array of the objects to the LORA o/p node? Each array object could be a different EUI (radio node) and the corresponding payload for it, the packets are generated in a function node as shown in the code below.
var msgpayload = JSON.parse(msg.payload); var downlinkPackets = []; for(i=0;i<msgpayload.length;i++) { downlinkPackets.push( { "eui": msgpayload[i].EUI, "payload": msgpayload[i].DataPacket.data } ); } return [downlinkPackets];Thanks,
AjayFebruary 9, 2017 at 3:41 pm #16954Peter Ferland
BlockedIn node red when you return an array it will actually output each message in the array one at a time. If your code works for one message, it should work for the array.
See the the official node-red documentation here: https://nodered.org/docs/writing-functions#multiple-messages
February 12, 2017 at 3:40 pm #17033Lawrence Griffiths
ParticipantYou can send asyn withing the function using
node.send();// This should do it
var msgpayload = JSON.parse(msg.payload);for(i=0;i<msgpayload.length;i++) {
var downlinkPackets = {eui: msgpayload[i].EUI, payload: msgpayload[i].DataPacket.data};
node.send(downlinkPackets);
}February 13, 2017 at 7:57 am #17044lorawan2016
ParticipantHi Lawrence,
Is the node.send(downlinkPackets); for Node-RED only or it’s possible to use it in any javascript code?
for the uplink messages in javascript or node.js, do you know what interface to use to access the uplink payload?
February 14, 2017 at 10:36 am #17108Lawrence Griffiths
Participantlorawan2016 node.send is Node-RED method for sending outputs from a Javascript function node http://nodered.org/docs/writing-functions
In a NR function the msg object passes the following.
So to get to payload you reference msg.payload on the LoRaIn you can specify your payload type UTF8 or bytes.“msg”: {
“chan”: 5,
“codr”: “4/5”,
“datr”: “SF7BW125”,
“freq”: “903.3”,
“lsnr”: “85”,
“modu”: “LORA”,
“rfch”: 1,
“rssi”: -55,
“size”: 12,
“timestamp”: “2015-04-09 16:22:12”,
“tmst”: 67346764,
“payload”: “hi mike”,
“eui”: “00:11:22:33:44:55:66:88”
}February 15, 2017 at 5:14 pm #17222Ajay K
ParticipantThanks Lawrence for your inputs. I am assuming the async node.send method is more efficient than sending it via an array object like i send it right now?
Thanks,
AjayFebruary 16, 2017 at 4:06 am #17228Lawrence Griffiths
ParticipantAjay not sure if it’s more efficient but it’s more obvious about what’s going on. E.g. you have to know about how NR processes arrays sent to an output. So it should be more maintainable for other/future devs looking at the code.
-
AuthorPosts
- You must be logged in to reply to this topic.