{"id":8453,"date":"2015-06-29T15:29:42","date_gmt":"2015-06-29T20:29:42","guid":{"rendered":"http:\/\/www.multitech.net\/developer\/?page_id=8453"},"modified":"2017-02-02T09:55:57","modified_gmt":"2017-02-02T15:55:57","slug":"conduit-mlinux-lora-communication","status":"publish","type":"page","link":"https:\/\/www.multitech.net\/developer\/software\/lora\/conduit-mlinux-lora-communication\/","title":{"rendered":"Conduit mLinux: LoRa Communication"},"content":{"rendered":"<h3>Prerequisites<\/h3>\n<ul>\n<li>Set up Conduit mLinux and mDot for use with LoRa. Refer to <a href='https:\/\/www.multitech.net\/developer\/software\/lora\/getting-started-with-lora-conduit-mlinux\/' title='Getting Started with LoRa Conduit mLinux (LoRa Configuration) '>Getting Started with LoRa Conduit mLinux (LoRa Configuration) <\/a>.<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h3>Receive Packets on the Conduit<\/h3>\n<ul>\n<li>Use MQTT to show all received LoRa messages on the console:\n<pre class=\"brush:shell\">$ mosquitto_sub -t lora\/+\/up<\/pre>\n<p>OR<\/li>\n<li>Use UDP and netcat to show all received LoRa messages on the console:\n<pre class=\"brush:shell\">$ nc --udp --listen --local-port 1784<\/pre>\n<div class=\"note\">If UDP doesn&#8217;t work, confirm udp[&#8220;appPortUp&#8221;] is 1784 by looking at the config that&#8217;s printed in <code>\/var\/log\/lora-network-server.conf<\/code> when the server starts.<\/div>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h3>Transmit Packets from the Conduit<\/h3>\n<p>Queue downstream packets on the Conduit by publishing the packets to the mosquitto or UDP channel for a specific mDot like this:<\/p>\n<pre class=\"brush:shell\">$ mosquitto_pub -t lora\/00:80:00:00:00:00:6a:1a\/down -m '{ \"data\":\"aGVsbG8gd29ybGQ=\" }'<\/pre>\n<p>or<\/p>\n<pre class=\"brush:shell\">$ nc --udp localhost 1786 &lt;ENTER&gt;\r\nlora\/00:80:00:00:00:00:6a:1a\/down {\"data\":\"aGVsbG8gd29ybGQ=\"} &lt;ENTER&gt;<\/pre>\n<ul>\n<li>The packet must be in JSON format and the data must be Base64 encoded<\/li>\n<li>To transmit one packet back to the mDot, the Conduit must receive one packet from the mDot.<\/li>\n<\/ul>\n<div class=\"note\">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.<\/div>\n<p>&nbsp;<\/p>\n<h3>Downstream Packet Options<\/h3>\n<ul>\n<li>Require acknowledgement from mDot\n<pre class=\"brush:js\">{ \"data\":\"aGVsbG8gd29ybGQ=\", \"ack\": true }<\/pre>\n<\/li>\n<li>Send data on a specific port to mDot, if not specified port 1 will be used. <em>(this is FPort in the LoRaWAN protocol)<\/em>\n<pre class=\"brush:js\">{ \"data\":\"aGVsbG8gd29ybGQ=\", \"port\": 6 }<\/pre>\n<\/li>\n<li>Send mac commands on to mDot in node.js\n<pre class=\"brush:js\">\/\/ Send a new channel to mDot\r\n\/\/ NewChannelReq\r\n\r\n\/\/ Channel Index    - 1 byte\r\n\/\/ Frequency        - 3 bytes\r\n\/\/ Datarate Range   - 1 byte\r\n\/\/ \tMax :4      - DR 0-7\r\n\/\/ \tMin :4      - DR 0-7\r\n\r\n\/\/ Frequency converted to HEX and reversed for network byte order\r\n\/\/ 869100000 \/ 100 --&gt; 0x849D38 --&gt; 0x389D84\r\n\r\n\/\/ Example: add channel 4 869100000 DR0 - DR5\r\n\r\n\/\/ ID | Index | Frequency | Range         Base64\r\n\/\/ 07    04      389D84      50      ---&gt; BwQ4nYRQ\r\n\r\nvar cmd = new Buffer([ 0x07, 0x09, 0xf8, 0x7d, 0x84, 0x77 ]).toString(\"base64\");\r\n\r\nvar packet = JSON.stringify({ \"data\": cmd, \"port\": 0 });\r\n\r\nvar topic = \"lora\/\" + eui + \"\/down\"\r\n\r\nclient.publish(topic, packet);<\/pre>\n<\/li>\n<li>Generate mac commands with nodejs on command line\n<pre>\r\ntest ADR command 0341ff0101\r\nCMD   DR PWR    MASK  CTRL\r\n03    4  1      ff01  01\r\n<\/pre>\n<pre class=\"brush:shell\">\r\n$ node\r\n> new Buffer(\"0341ff0101\", \"hex\").toString(\"base64\")\r\n'A0H\/AQE='\r\n&lt;CTRL&gt;D\r\n$ nc --udp localhost 1786 &lt;ENTER&gt;\r\nlora\/00:80:00:00:00:00:6a:1a\/down {\"port\": 0, \"data\":\"A0H\/AQE=\"} &lt;ENTER&gt;\r\n<\/pre>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h3>Sample Node.js App<\/h3>\n<ul>\n<li>Download <a href=\"\/downloads\/lora-sample-app.tar.gz\">a sample Node.js app<\/a> that demonstrates how to receive and send LoRa packets.<\/li>\n<li>Copy the tarball to the Conduit: <code>scp Downloads\/lora-sample-app.tar.gz root@192.168.2.1<\/code><\/li>\n<li>ssh into the Conduit<\/li>\n<li>Unpack the tarball: <code>tar -xzf lora-sample-app.tar.gz<\/code><\/li>\n<li>Run the app: <code>node lora-sample-app.js<\/code> (it&#8217;ll take a little time to start)<\/li>\n<li>To echo received packets back to the mDot, uncomment this line at the end of the file:\n<pre class=\"brush:c\">    \/\/ uncomment to send the same message back to the dot\r\n    \/\/ send_to_node(eui, json.data)<\/pre>\n<\/li>\n<\/ul>\n<p>Using the sample app on the mDot:<\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/www.multitech.net\/developer\/wp-content\/uploads\/2015\/06\/Sample_node.png\"><img decoding=\"async\" class=\"aligncenter\" alt=\"screenshot of mDot terminal\" src=\"https:\/\/www.multitech.net\/developer\/wp-content\/uploads\/2015\/08\/mdot-transmit.png\" width=\"NaN\" height=\"NaN\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3>Troubleshooting<\/h3>\n<ul>\n<li><a href='https:\/\/www.multitech.net\/developer\/software\/lora\/conduit-mlinux-lora-communication\/conduit-mlinux-lora-use-third-party-devices\/' title='Conduit mLinux: LoRa Use With Third-Party Devices'>Conduit mLinux: LoRa Use With Third-Party Devices<\/a><\/li>\n<li><a href='https:\/\/www.multitech.net\/developer\/software\/lora\/troubleshooting-lora-communication\/' title='Troubleshooting LoRa Communication'>Troubleshooting LoRa Communication<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Prerequisites Set up Conduit mLinux and mDot for use with LoRa. Refer to . &nbsp; 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 &#8211;udp &#8211;listen &#8211;local-port 1784 [&hellip;]<\/p>\n","protected":false},"author":537,"featured_media":0,"parent":8462,"menu_order":6,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"footnotes":""},"class_list":["post-8453","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/pages\/8453","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/users\/537"}],"replies":[{"embeddable":true,"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/comments?post=8453"}],"version-history":[{"count":42,"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/pages\/8453\/revisions"}],"predecessor-version":[{"id":8525,"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/pages\/8453\/revisions\/8525"}],"up":[{"embeddable":true,"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/pages\/8462"}],"wp:attachment":[{"href":"https:\/\/www.multitech.net\/developer\/wp-json\/wp\/v2\/media?parent=8453"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}