Sending Array of objects to LORA o/p node.

Home Forums Conduit: AEP Model Sending Array of objects to LORA o/p node.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #16952
    Ajay K
    Participant

    Is 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,
    Ajay

    #16954
    Peter Ferland
    Blocked

    In 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

    #17033
    Lawrence Griffiths
    Participant

    You 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);
    }

    #17044
    lorawan2016
    Participant

    Hi 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?

    #17108
    Lawrence Griffiths
    Participant

    lorawan2016 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”
    }

    #17222
    Ajay K
    Participant

    Thanks 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,
    Ajay

    #17228
    Lawrence Griffiths
    Participant

    Ajay 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.

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.