Conduit mLinux: LoRa Communication

Prerequisites

 

Receive Packets on the Conduit

  • Use MQTT to show all received LoRa messages on the console:
    $ mosquitto_sub -t lora/+/up

    OR

  • Use UDP and netcat to show all received LoRa messages on the console:
    $ nc --udp --listen --local-port 1784
    If UDP doesn’t work, confirm udp[“appPortUp”] is 1784 by looking at the config that’s printed in /var/log/lora-network-server.conf when the server starts.

 

Transmit Packets from the Conduit

Queue downstream packets on the Conduit by publishing the packets to the mosquitto or UDP channel for a specific mDot like this:

$ mosquitto_pub -t lora/00:80:00:00:00:00:6a:1a/down -m '{ "data":"aGVsbG8gd29ybGQ=" }'

or

$ nc --udp localhost 1786 <ENTER>
lora/00:80:00:00:00:00:6a:1a/down {"data":"aGVsbG8gd29ybGQ="} <ENTER>
  • The packet must be in JSON format and the data must be Base64 encoded
  • To transmit one packet back to the mDot, the Conduit must receive one packet from the mDot.
Because Conduit and mDots are currently designed for the LoRa Class A specification, the Conduit can only send a packet to an mDot during one of the two receive windows the mDot opens after transmitting a packet to the Conduit.

 

Downstream Packet Options

  • Require acknowledgement from mDot
    { "data":"aGVsbG8gd29ybGQ=", "ack": true }
  • Send data on a specific port to mDot, if not specified port 1 will be used. (this is FPort in the LoRaWAN protocol)
    { "data":"aGVsbG8gd29ybGQ=", "port": 6 }
  • Send mac commands on to mDot in node.js
    // Send a new channel to mDot
    // NewChannelReq
    
    // Channel Index    - 1 byte
    // Frequency        - 3 bytes
    // Datarate Range   - 1 byte
    // 	Max :4      - DR 0-7
    // 	Min :4      - DR 0-7
    
    // Frequency converted to HEX and reversed for network byte order
    // 869100000 / 100 --> 0x849D38 --> 0x389D84
    
    // Example: add channel 4 869100000 DR0 - DR5
    
    // ID | Index | Frequency | Range         Base64
    // 07    04      389D84      50      ---> BwQ4nYRQ
    
    var cmd = new Buffer([ 0x07, 0x09, 0xf8, 0x7d, 0x84, 0x77 ]).toString("base64");
    
    var packet = JSON.stringify({ "data": cmd, "port": 0 });
    
    var topic = "lora/" + eui + "/down"
    
    client.publish(topic, packet);
  • Generate mac commands with nodejs on command line
    test ADR command 0341ff0101
    CMD   DR PWR    MASK  CTRL
    03    4  1      ff01  01
    
    $ node
    > new Buffer("0341ff0101", "hex").toString("base64")
    'A0H/AQE='
    <CTRL>D
    $ nc --udp localhost 1786 <ENTER>
    lora/00:80:00:00:00:00:6a:1a/down {"port": 0, "data":"A0H/AQE="} <ENTER>
    

 

Sample Node.js App

  • Download a sample Node.js app that demonstrates how to receive and send LoRa packets.
  • Copy the tarball to the Conduit: scp Downloads/lora-sample-app.tar.gz root@192.168.2.1
  • ssh into the Conduit
  • Unpack the tarball: tar -xzf lora-sample-app.tar.gz
  • Run the app: node lora-sample-app.js (it’ll take a little time to start)
  • To echo received packets back to the mDot, uncomment this line at the end of the file:
        // uncomment to send the same message back to the dot
        // send_to_node(eui, json.data)

Using the sample app on the mDot:

screenshot of mDot terminal

 

Troubleshooting