{"id":1103,"date":"2019-07-04T10:34:59","date_gmt":"2019-07-04T09:34:59","guid":{"rendered":"http:\/\/www.vancura.cz\/?p=1103"},"modified":"2024-03-28T14:54:07","modified_gmt":"2024-03-28T13:54:07","slug":"lorawan-intro","status":"publish","type":"post","link":"https:\/\/vancura.cz\/wordpress\/lorawan-intro\/","title":{"rendered":"LoRaWAN &#8211; DIY node and Gatweay @TTN"},"content":{"rendered":"<p>Connect your IoT project for free using community-build infrastructure &#8211; long range<br \/>\n<!--more--><\/p>\n<p>LoRa (<a href=\"https:\/\/en.wikipedia.org\/wiki\/LoRa\">wiki<\/a>) is a new approach how to &#8222;build&#8220; internet. Best from my point of view is fact that you can connect for free &#8211; if someone is running gateway close to you. See great community project <a href=\"https:\/\/www.thethingsnetwork.org\/\">The Things Netwotk<\/a>.<\/p>\n<p>Here you can find my notes once building your own LoRaWAN endpoind (node) and LoRaWAN Raspberry Pi-based Gateway.<\/p>\n<p><strong>1. Build DIY LoRaWAN node (end point)<\/strong><\/p>\n<p>HW needed : BSFrance LoRa32u4 II Lora Development Board &#8211; price cca 15USD &#8211; get it at <a href=\"https:\/\/bit.ly\/2WcOqTt\">AliExpress<\/a><\/p>\n<p>&nbsp;<\/p>\n<figure id=\"attachment_17648\" aria-describedby=\"caption-attachment-17648\" style=\"width: 225px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-17648\" src=\"https:\/\/vancura.cz\/wordpress\/wp-content\/uploads\/2024\/03\/lora3-225x300.jpg\" alt=\"\" width=\"225\" height=\"300\" srcset=\"https:\/\/vancura.cz\/wordpress\/wp-content\/uploads\/2024\/03\/lora3-225x300.jpg 225w, https:\/\/vancura.cz\/wordpress\/wp-content\/uploads\/2024\/03\/lora3-768x1024.jpg 768w, https:\/\/vancura.cz\/wordpress\/wp-content\/uploads\/2024\/03\/lora3-1152x1536.jpg 1152w, https:\/\/vancura.cz\/wordpress\/wp-content\/uploads\/2024\/03\/lora3-1536x2048.jpg 1536w, https:\/\/vancura.cz\/wordpress\/wp-content\/uploads\/2024\/03\/lora3-scaled.jpg 1920w\" sizes=\"auto, (max-width: 225px) 100vw, 225px\" \/><figcaption id=\"caption-attachment-17648\" class=\"wp-caption-text\">mde<\/figcaption><\/figure>\n<figure id=\"attachment_17647\" aria-describedby=\"caption-attachment-17647\" style=\"width: 300px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-17647\" src=\"https:\/\/vancura.cz\/wordpress\/wp-content\/uploads\/2024\/03\/lora2-300x252.jpg\" alt=\"\" width=\"300\" height=\"252\" srcset=\"https:\/\/vancura.cz\/wordpress\/wp-content\/uploads\/2024\/03\/lora2-300x252.jpg 300w, https:\/\/vancura.cz\/wordpress\/wp-content\/uploads\/2024\/03\/lora2-1024x859.jpg 1024w, https:\/\/vancura.cz\/wordpress\/wp-content\/uploads\/2024\/03\/lora2-768x644.jpg 768w, https:\/\/vancura.cz\/wordpress\/wp-content\/uploads\/2024\/03\/lora2-1536x1288.jpg 1536w, https:\/\/vancura.cz\/wordpress\/wp-content\/uploads\/2024\/03\/lora2-2048x1718.jpg 2048w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><figcaption id=\"caption-attachment-17647\" class=\"wp-caption-text\">smacap_Bright<\/figcaption><\/figure>\n<p>Note : some boards need to perform soldering at board to enable Lora &#8211; refer to great technical forum for this boards at <a href=\"https:\/\/www.thethingsnetwork.org\/forum\/t\/big-lora32u4-boards-topic\/15273\">TTN forum<\/a><\/p>\n<p>Step 1 : get drivers (Windows only) &#8211; <a href=\"https:\/\/github.com\/adafruit\/Adafruit_Windows_Drivers\/releases\/\">https:\/\/github.com\/adafruit\/Adafruit_Windows_Drivers\/releases\/<\/a><\/p>\n<p>Step 2 : download <a href=\"https:\/\/github.com\/BSFrance\/BSFrance-avr\">https:\/\/github.com\/BSFrance\/BSFrance-avr<\/a> and unpdack it into Arduino IDE dir \/Documents\/Arduino\/Hardware<\/p>\n<p>Step 3 : connect board via USB, in Arduino IDE select menu Tools &#8211; Board &#8211; list LoRa32u4II and select proper port<\/p>\n<p>Step 4 : download <a href=\"https:\/\/github.com\/matthijskooijman\/arduino-lmic\">https:\/\/github.com\/matthijskooijman\/arduino-lmic<\/a> as zip, in Ardiono IDE menu Sketch &#8211; Include Lib &#8211; From Zip &#8211; select downloaded zip<\/p>\n<p>Step 5 : configure this lib in \/Documents\/Arduino\/libraries\/arduino-lmic-master\/src\/lmic\/config.h &#8211; enable debug<br \/>\n<code>#define LMIC_DEBUG_LEVEL 1<br \/>\n#define LMIC_PRINTF_TO Serial<\/code><\/p>\n<p>Step 6 : go to TTN web <a href=\"https:\/\/www.thethingsnetwork.org\/\">https:\/\/www.thethingsnetwork.org\/<\/a> &#8211; register, create new app, create new device, in device settings select activation method ABP for start<\/p>\n<p>Step 7 : in Adruino IDE &#8211; open example sketch in \/Documents\/Arduino\/libraries\/arduino-lmic-master\/examples\/ttn-abp\/ttn-abp.ino<\/p>\n<p>Step 8 : modify sketch &#8211; copy ABP keys from Step 6, you need Network session key NWKSKEY in msb format, application session key APPSKEY in msb and Device Adress DEVADDR (format 0x+number from portal)<\/p>\n<p>Step 9 : modify sketch &#8211; pinning for selected board<br \/>\n<code>const lmic_pinmap lmic_pins = {<br \/>\n.nss = 8,<br \/>\n.rxtx = LMIC_UNUSED_PIN,<br \/>\n.rst = 4,<br \/>\n.dio = {\/*dio0*\/ 7, \/*dio1*\/ 5, \/*dio2*\/ LMIC_UNUSED_PIN}<br \/>\n};<\/code><\/p>\n<p>Step 10 : upload code from Arduino IDE into LoraBoard *<\/p>\n<p>Step 11 : open serial monitor and check activity. You should see similar lines as board is trying to connect to LoRaWAN and send data<br \/>\n<code>23:15:06.269 -&gt; Starting<br \/>\n23:15:06.269 -&gt; RXMODE_RSSI<br \/>\n23:15:06.269 -&gt; 144965: engineUpdate, opmode=0x808<br \/>\n23:15:06.269 -&gt; 145933: TXMODE, freq=868100000, len=26, SF=7, BW=125, CR=4\/5, IH=0<br \/>\n23:15:06.269 -&gt; Packet queued<br \/>\n23:15:07.326 -&gt; 212141: RXMODE_SINGLE, freq=868100000, SF=7, BW=125, CR=4\/5, IH=0<br \/>\n<\/code><\/p>\n<p>Step 12 : Open console at <a href=\"https:\/\/console.thethingsnetwork.org\/applications\">https:\/\/console.thethingsnetwork.org\/applications<\/a> and wait for data comming in. This can take some time, so be patient.<\/p>\n<p>&nbsp;<\/p>\n<p>* Note: I had big troubles uploading any code into board. It is pretty unstable because boards seeems to disconnect after 15seconds. My workaround: upload simple sketch (like blink.ino from examples) 1st and than upload your actual code. If you have problems doing so, press reset button on board during upload. Good luck.<\/p>\n<p><strong>2. Build DIY LoRaWAN gateway <\/strong><\/p>\n<p>HW needed :<\/p>\n<ul>\n<li>Raspberry Pi<\/li>\n<li>HopeRF RFM95W board &#8211; price cca 5USD &#8211; get it at <a href=\"https:\/\/bit.ly\/2QIvhaM\">AliExpress<\/a><\/li>\n<li>DIY Antena &#8211; use solid wire 86mm longStep 1 : wire RFM95 board and Raspberry &#8211; see table <a href=\"https:\/\/hackster.imgix.net\/uploads\/attachments\/251125\/screen_shot_2017-01-14_at_3_6uyhmjmqTJ.png?auto=compress%2Cformat&amp;w=740&amp;h=555&amp;fit=max\">here<\/a>. Mentioned pins at Raspberry are HW pin numbers, not GPIO numbers.\n<p>Step 2 : solder antenna vertically to ANT pin<\/p>\n<p>Step 3 : ssh to Raspberry, enable serial in config<br \/>\n<code>sudo sudo raspi-config<\/code><br \/>\nselect Interface settings, SPI, enable<\/p>\n<p>Step 4 : still at ssh at Raspberry &#8211; install LoRa Gateway SW &#8211; single_chan_pkt_fwd<br \/>\n<code>cd \/home\/pi<br \/>\ngit clone https:\/\/github.com\/hallard\/single_chan_pkt_fwd<br \/>\ncd ~\/single_chan_pkt_fwd<\/code><\/p>\n<p>Step 5 : change config<br \/>\n<code>sudo nano global_conf.json<\/code><br \/>\nchange<br \/>\n<code>\"pin_nss\": 6,<br \/>\n\"pin_dio0\": 7,<br \/>\n\"pin_rst\": 0<\/code><\/p>\n<p>Step 6 : make and run<br \/>\n<code>make<br \/>\nsudo \/home\/pi\/single_chan_pkt_fwd\/single_chan_pkt_fwd<\/code><\/p>\n<p>Step 7 : you will get console output similar to this<br \/>\n<code>Trying to detect module with NSS=6 DIO0=7 Reset=0 Led1=unused<br \/>\nSX1276 detected, starting.<br \/>\nGateway ID: b8:27:eb:ff:ff:c1:d7:bb<br \/>\nListening at SF7 on 868.100000 Mhz.<\/code><\/p>\n<p>stat update: 2019-06-26 20:44:31 GMT no packet received yet<\/p>\n<p>Step 8 : try to send some data from your node &#8211; than you will notice incomming data to gataway<br \/>\n<code>Packet RSSI: -72, RSSI: -108, SNR: 9, Length: 23 Message:'.r...~..pu..TO......._.'<br \/>\nrxpk update: {\"rxpk\":[{\"tmst\":504372116,\"freq\":868.1,\"chan\":0,\"rfch\":0,\"stat\":1,\"modu\":\"LORA\",\"datr\":\"SF7BW125\",\"codr\":\"4\/5\",\"rssi\":-72,\"lsnr\":9.0,\"size\":23,\"data\":\"AHLeAdB+1bNwdQuhVE\/QngCc\/wPyXwc=\"}]}<\/code><\/p>\n<p>Step 9 : Register gateway at <a href=\"https:\/\/console.thethingsnetwork.org\/gateways\">https:\/\/console.thethingsnetwork.org\/gateways<\/a>, select &#8222;I am using the legacy packer forwarder&#8220; and as Gateway EUI use number from Step 7 &#8211; Gateway ID (looks like Mac address)<\/p>\n<p>Step 10 : Observe network traffic in &#8222;Traffic&#8220; tab.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-17646\" src=\"https:\/\/vancura.cz\/wordpress\/wp-content\/uploads\/2024\/03\/lora1-300x79.png\" alt=\"\" width=\"300\" height=\"79\" srcset=\"https:\/\/vancura.cz\/wordpress\/wp-content\/uploads\/2024\/03\/lora1-300x79.png 300w, https:\/\/vancura.cz\/wordpress\/wp-content\/uploads\/2024\/03\/lora1-1024x269.png 1024w, https:\/\/vancura.cz\/wordpress\/wp-content\/uploads\/2024\/03\/lora1-768x202.png 768w, https:\/\/vancura.cz\/wordpress\/wp-content\/uploads\/2024\/03\/lora1-1536x404.png 1536w, https:\/\/vancura.cz\/wordpress\/wp-content\/uploads\/2024\/03\/lora1.png 1794w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Connect your IoT project for free using community-build infrastructure &#8211; long range<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1103","post","type-post","status-publish","format-standard","hentry","category-nezarazene"],"_links":{"self":[{"href":"https:\/\/vancura.cz\/wordpress\/wp-json\/wp\/v2\/posts\/1103","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vancura.cz\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vancura.cz\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vancura.cz\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vancura.cz\/wordpress\/wp-json\/wp\/v2\/comments?post=1103"}],"version-history":[{"count":21,"href":"https:\/\/vancura.cz\/wordpress\/wp-json\/wp\/v2\/posts\/1103\/revisions"}],"predecessor-version":[{"id":17649,"href":"https:\/\/vancura.cz\/wordpress\/wp-json\/wp\/v2\/posts\/1103\/revisions\/17649"}],"wp:attachment":[{"href":"https:\/\/vancura.cz\/wordpress\/wp-json\/wp\/v2\/media?parent=1103"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vancura.cz\/wordpress\/wp-json\/wp\/v2\/categories?post=1103"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vancura.cz\/wordpress\/wp-json\/wp\/v2\/tags?post=1103"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}