{"id":927,"date":"2021-05-11T10:58:23","date_gmt":"2021-05-11T10:58:23","guid":{"rendered":"http:\/\/lora.vsb.cz\/?page_id=927"},"modified":"2021-05-19T10:48:09","modified_gmt":"2021-05-19T10:48:09","slug":"lora-169-mhz","status":"publish","type":"page","link":"https:\/\/lora.vsb.cz\/index.php\/lora-169-mhz\/","title":{"rendered":"LoRaWAN @ 169 MHz"},"content":{"rendered":"<p>The article deals with designing and implementing a gateway of LoRaWAN technology operating at a frequency of 169 MHz. The practical goal is to enable data transfer using the LoRa\/LoRaWAN standard at a frequency of 169 MHz. The modules are connected to an Arduino and Raspberry Pi microcomputer, and transfer between the two modules is provided using program codes in C.<\/p>\n<h3><span style=\"color: #800000;\">Hardware<\/span><\/h3>\n<ul>\n<li>Raspberry Pi B+ V1.2<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-936\" src=\"http:\/\/lora.vsb.cz\/wp-content\/uploads\/2021\/05\/1-300x195.png\" alt=\"\" width=\"300\" height=\"195\" srcset=\"https:\/\/lora.vsb.cz\/wp-content\/uploads\/2021\/05\/1-300x195.png 300w, https:\/\/lora.vsb.cz\/wp-content\/uploads\/2021\/05\/1.png 338w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<ul>\n<li>Arduino UNO<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-937\" src=\"http:\/\/lora.vsb.cz\/wp-content\/uploads\/2021\/05\/2-300x199.png\" alt=\"\" width=\"300\" height=\"199\" srcset=\"https:\/\/lora.vsb.cz\/wp-content\/uploads\/2021\/05\/2-300x199.png 300w, https:\/\/lora.vsb.cz\/wp-content\/uploads\/2021\/05\/2.png 358w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<ul>\n<li>Flame sensor<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-938\" src=\"http:\/\/lora.vsb.cz\/wp-content\/uploads\/2021\/05\/3.png\" alt=\"\" width=\"241\" height=\"183\" \/><\/p>\n<ul>\n<li>Semtech SX1276RF1IAS with antenna<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-939\" src=\"http:\/\/lora.vsb.cz\/wp-content\/uploads\/2021\/05\/4-300x147.png\" alt=\"\" width=\"390\" height=\"191\" srcset=\"https:\/\/lora.vsb.cz\/wp-content\/uploads\/2021\/05\/4-300x147.png 300w, https:\/\/lora.vsb.cz\/wp-content\/uploads\/2021\/05\/4.png 436w\" sizes=\"auto, (max-width: 390px) 100vw, 390px\" \/><\/p>\n<h3><span style=\"color: #800000;\"><strong>Setting up the TX side<\/strong><\/span><\/h3>\n<p>Tx side is composed of Arduino UNO, SX1276RF1IAS module and flame sensor.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Step1:<\/strong> Wire all the parts mentioned above according to this table:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-940\" src=\"http:\/\/lora.vsb.cz\/wp-content\/uploads\/2021\/05\/5-222x300.png\" alt=\"\" width=\"272\" height=\"367\" srcset=\"https:\/\/lora.vsb.cz\/wp-content\/uploads\/2021\/05\/5-222x300.png 222w, https:\/\/lora.vsb.cz\/wp-content\/uploads\/2021\/05\/5.png 319w\" sizes=\"auto, (max-width: 272px) 100vw, 272px\" \/><\/p>\n<p>SCK, MISO, MOSI, NSS and NRESET are pins that are always used for wiring ordinary SX1276 chip to Arduino board. RXTX, FEM_CTX and FEM_CPS are pins that are used specifically with SX1276RFIAS module.<\/p>\n<p>Note that you need to connect all three pins used for power supply &#8211;\u00a0 VDD_RF,VDD_ANA, VDD_FEM and all three GROUND pins too. Since Arduino UNO only has one 3.3V pin, you need to use something that allows you to connect these three power supply pins to Arduino 3.3V port. I used \u201ebread board\u201c which allows you to split one port to multiple ports. Another option is to use external power supply.<\/p>\n<p>If you connected it properly, your Tx side should look like this:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-941\" src=\"http:\/\/lora.vsb.cz\/wp-content\/uploads\/2021\/05\/6-300x155.png\" alt=\"\" width=\"522\" height=\"270\" srcset=\"https:\/\/lora.vsb.cz\/wp-content\/uploads\/2021\/05\/6-300x155.png 300w, https:\/\/lora.vsb.cz\/wp-content\/uploads\/2021\/05\/6.png 567w\" sizes=\"auto, (max-width: 522px) 100vw, 522px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Step 2:<\/strong> Download Arduino IDE, connect Arduino UNO to PC and setup your IDE.<\/p>\n<p>You can find Arduino IDE here: <a href=\"https:\/\/www.arduino.cc\/en\/software\">https:\/\/www.arduino.cc\/en\/software<\/a><\/p>\n<p>Connect your Arduino UNO to PC and open Arduino IDE. Then, you need to set used Port. You can do this by clicking \u201eTools\u201c -&gt; \u201ePort\u201c -&gt; choose COM5.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-942\" src=\"http:\/\/lora.vsb.cz\/wp-content\/uploads\/2021\/05\/7-300x172.png\" alt=\"\" width=\"403\" height=\"231\" srcset=\"https:\/\/lora.vsb.cz\/wp-content\/uploads\/2021\/05\/7-300x172.png 300w, https:\/\/lora.vsb.cz\/wp-content\/uploads\/2021\/05\/7.png 449w\" sizes=\"auto, (max-width: 403px) 100vw, 403px\" \/><\/p>\n<p>You can now upload code included below (or write your own). Here I will highlight main parts of the code and explain them.<\/p>\n<p>Code for Tx side: <a href=\"https:\/\/wtools.io\/paste-code\/b4G5\">https:\/\/wtools.io\/paste-code\/b4G5<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>I am using Arduino LoRa library by sandeepmistry (\u00a0<a href=\"https:\/\/github.com\/sandeepmistry\/arduino-LoRa\">https:\/\/github.com\/sandeepmistry\/arduino-LoRa <\/a>).<\/p>\n<pre>#include &lt;SPI.h&gt;\r\n#include &lt;LoRa.h&gt;\r\n#define analogPin A0 \/\/flame sensor pin\r\nint flame;\r\nint counter = 0;\r\n\r\nvoid setup() { \r\nSerial.begin(9600);\r\npinMode(analogPin, INPUT); \/\/ inicialization of flame sensor\r\n\r\nwhile (!Serial);\r\nSerial.println(\"LoRa Sender\");\r\nif (!LoRa.begin(169E6)) { \/\/input your frequency - 169 MHz\r\nSerial.println(\"Starting LoRa failed!\");\r\nwhile (1);\r\n}\r\n\/\/below are optional parameters for LoRa transmitter\r\n\/\/use the same for Tx and Rx side\r\nLoRa.setTxPower(10);\r\nLoRa.setSpreadingFactor(7); \r\nLoRa.setSignalBandwidth(125E3); \r\nLoRa.setCodingRate4(5);\r\n\r\npinMode(4, OUTPUT); \r\npinMode(6, OUTPUT); \r\npinMode(7, OUTPUT); \r\ndigitalWrite(4, LOW); \/\/FEM_CPS=0\r\ndigitalWrite(6, LOW); \/\/FEM_CTX=0\r\ndigitalWrite(7, HIGH); \/\/RXTX=1 (means it is transmitting)\r\n\r\nSerial.println(\"setup complete\");\r\n}<\/pre>\n<p>First I defined analog pin for Flame sensor. In setup() function you need to set the flame sensor\u00b4s pin as an input.\u00a0 Following code for LoRa initialization can be found and explained in LoRa library\u00b4s documentation mentioned earlier.<\/p>\n<p>LoRa.begin(169E6) begins the communication on 169 MHz. If you want to use another frequency, you can change it right here, but just make sure your module supports your frequency (our used module supports 169 and 868 MHz). If you had the module connected incorrectly, you would see \u201eStarting LoRa failed!\u201c in output window.<\/p>\n<p>Next you can set Tx parameters \u2013 like TxPower, SF, bandwidth, coding rate and more. All parameters that you can set can be found in this library\u00b4s documentation.<\/p>\n<p>What makes the work with this module different from ordinary SX1276 chip are 3 pins &#8211;\u00a0 FEM_CPS, FEM_CTX and RXTX. You need to set them properly to get the module working. Because we want to transmit on LOW frequency we need to set FEM_CPS=0, FEM_CTX=0 and RXTX=1 (meaning that we want to transmit).<\/p>\n<p>If you want to transmit on HIGH frequency, you need to set FEM_CPS=0, FEM_CTX=1 and RXTX=1.<\/p>\n<p>Now, you can set these three pins by using digitalWrite function \u2013 LOW means 0, HIGH means 1.<\/p>\n<pre>void loop() {\r\nint voltageSensor = analogRead(analogPin); \/\/load flame sensor pin\r\nint flame = map(voltageSensor, 0, 1024, 0, 3); \r\n\/\/0 = flame is close\r\n\/\/1= there is flame nearby\r\n\/\/2=no flame detected \r\n\r\nSerial.print(\"Sending packet: \");\r\nSerial.println(counter);\r\nSerial.println(\"Flame: \");\r\nSerial.println(flame);\r\n\r\nLoRa.beginPacket(); \/\/start the packet\r\nLoRa.print(flame); \/\/data of the packet - flame\r\nLoRa.endPacket(); \/\/end the packet\r\n\r\ncounter++;\r\ndelay(1000);\r\n}<\/pre>\n<p>In loop function, read the value of flame sensor\u00b4s analog pin and convert it to value between &lt;0,2&gt;.<\/p>\n<p>Then LoRa.beginPacket() begins the packet and LoRa.endPacket ends the packet. Between these two lines you can insert data in this packet -&gt; in this code we insert mentioned variable &#8211;\u00a0 \u201eflame\u201c.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Step 3<\/strong>: Try to start your Tx side<\/p>\n<p><u><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-945\" src=\"http:\/\/lora.vsb.cz\/wp-content\/uploads\/2021\/05\/10-300x208.png\" alt=\"\" width=\"300\" height=\"208\" srcset=\"https:\/\/lora.vsb.cz\/wp-content\/uploads\/2021\/05\/10-300x208.png 300w, https:\/\/lora.vsb.cz\/wp-content\/uploads\/2021\/05\/10.png 305w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/u><\/p>\n<p>You can upload your code to Arduino by clicking first on \u201eA\u201c button which checks the code for possible error and then clicking on \u201eB\u201c button to upload your code. However, that is not all, you need to view and check the output of the code by clicking \u201eTools\u201c -&gt; \u201eSerial Monitor\u201c.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-946\" src=\"http:\/\/lora.vsb.cz\/wp-content\/uploads\/2021\/05\/11-300x207.png\" alt=\"\" width=\"406\" height=\"280\" srcset=\"https:\/\/lora.vsb.cz\/wp-content\/uploads\/2021\/05\/11-300x207.png 300w, https:\/\/lora.vsb.cz\/wp-content\/uploads\/2021\/05\/11.png 474w\" sizes=\"auto, (max-width: 406px) 100vw, 406px\" \/><\/p>\n<p>If there is everything set up and wired correctly, you should see this output:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-947\" src=\"http:\/\/lora.vsb.cz\/wp-content\/uploads\/2021\/05\/12-300x132.png\" alt=\"\" width=\"603\" height=\"265\" srcset=\"https:\/\/lora.vsb.cz\/wp-content\/uploads\/2021\/05\/12-300x132.png 300w, https:\/\/lora.vsb.cz\/wp-content\/uploads\/2021\/05\/12.png 605w\" sizes=\"auto, (max-width: 603px) 100vw, 603px\" \/><\/p>\n<p>Each second, the transmitter transmits data and tells us, if there is a flame nearby or not.<\/p>\n<h3><strong><span style=\"color: #800000;\">Setting up the RX side<\/span><\/strong><\/h3>\n<p>Rx side is composed of Raspberry Pi and SX1276RF1IAS module.<\/p>\n<p><strong>Step 1<\/strong>: Setup the Raspberry Pi.<\/p>\n<p>Download Raspbian image, format SD card and install image to it as usual. If you don\u00b4t know how to work with Raspberry Pi, you can visit <a href=\"https:\/\/projects.raspberrypi.org\/en\/projects\/raspberry-pi-setting-up\">https:\/\/projects.raspberrypi.org\/en\/projects\/raspberry-pi-setting-up<\/a> for more informations and tutorials.<\/p>\n<p><strong>Step 2: <\/strong>Enable SPI communication on Rpi and install some packages.<\/p>\n<p>Since we need to use SPI communication, we need to enable it. Open Terminal, write \u201eraspi-config\u201c and select Interfacing options.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-948\" src=\"http:\/\/lora.vsb.cz\/wp-content\/uploads\/2021\/05\/13-300x98.png\" alt=\"\" width=\"499\" height=\"163\" srcset=\"https:\/\/lora.vsb.cz\/wp-content\/uploads\/2021\/05\/13-300x98.png 300w, https:\/\/lora.vsb.cz\/wp-content\/uploads\/2021\/05\/13.png 605w\" sizes=\"auto, (max-width: 499px) 100vw, 499px\" \/><\/p>\n<p>Then navigate to \u201eSPI\u201c and enable it.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-949\" src=\"http:\/\/lora.vsb.cz\/wp-content\/uploads\/2021\/05\/14-300x120.png\" alt=\"\" width=\"493\" height=\"197\" srcset=\"https:\/\/lora.vsb.cz\/wp-content\/uploads\/2021\/05\/14-300x120.png 300w, https:\/\/lora.vsb.cz\/wp-content\/uploads\/2021\/05\/14.png 605w\" sizes=\"auto, (max-width: 493px) 100vw, 493px\" \/><\/p>\n<p>Next, you need to install some of the packages:<\/p>\n<ul>\n<li>pip install RPi.GPIO \u2013 package that controls pins<\/li>\n<li>pip install spidev \u2013 package that performs SPI communication using python<\/li>\n<li>pip install pyLoRa \u2013 package that installs LoRa features<\/li>\n<li>sudo apt-get install python-rpi.gpio python3-rpi.gpio<\/li>\n<li>sudo apt-get install python-spidev python3-spidev<\/li>\n<\/ul>\n<p><strong>Step 3:<\/strong> Turn off Rpi, unplug it from power supply and wire Rpi and SX1276RF1IAS together.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-950\" src=\"http:\/\/lora.vsb.cz\/wp-content\/uploads\/2021\/05\/15-300x212.png\" alt=\"\" width=\"597\" height=\"422\" srcset=\"https:\/\/lora.vsb.cz\/wp-content\/uploads\/2021\/05\/15-300x212.png 300w, https:\/\/lora.vsb.cz\/wp-content\/uploads\/2021\/05\/15.png 605w\" sizes=\"auto, (max-width: 597px) 100vw, 597px\" \/><\/p>\n<p>This is pinout of Raspberry Pi B+ V1.2. Be careful when you wire modules together and check, if you don\u00b4t have Raspberry Pi turned upside down.<\/p>\n<p>Wire modules together according to this table:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-951\" src=\"http:\/\/lora.vsb.cz\/wp-content\/uploads\/2021\/05\/16-134x300.png\" alt=\"\" width=\"210\" height=\"470\" srcset=\"https:\/\/lora.vsb.cz\/wp-content\/uploads\/2021\/05\/16-134x300.png 134w, https:\/\/lora.vsb.cz\/wp-content\/uploads\/2021\/05\/16.png 193w\" sizes=\"auto, (max-width: 210px) 100vw, 210px\" \/><\/p>\n<p>Here we can see that we are using more pins than we used with Arduino. This is because project for Rx side is borrowed from user rpsreal &#8211;\u00a0 specifically project pySX127x. In rpsreal\u00b4s project, he uses more pins for his purposes and features, but even though we won\u00b4t be using all of these features, we can still leave these ports connected so it won\u00b4t cause errors if we unplug them. I\u00a0 also had to make some modification to his code &#8211;\u00a0 like changing the frequency and parameters.<\/p>\n<p>Again, we need to connect all three power supply ports so I used bread board again. If you connected it properly, your Rx side should look like this:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-952\" src=\"http:\/\/lora.vsb.cz\/wp-content\/uploads\/2021\/05\/17-300x175.png\" alt=\"\" width=\"513\" height=\"299\" srcset=\"https:\/\/lora.vsb.cz\/wp-content\/uploads\/2021\/05\/17-300x175.png 300w, https:\/\/lora.vsb.cz\/wp-content\/uploads\/2021\/05\/17.png 488w\" sizes=\"auto, (max-width: 513px) 100vw, 513px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Step 4: <\/strong>Download the code for Rx side to Raspberry Pi and launch it.<\/p>\n<p>You can download the code from here: <a href=\"https:\/\/github.com\/michalmutka\/SX1276RF1IAS-Rx-side-RaspberryPi\">https:\/\/github.com\/michalmutka\/SX1276RF1IAS-Rx-side-RaspberryPi<\/a><\/p>\n<p>Here I will explain main parts of this code.First you need to copy \u201epySX127x\u201c folder into your home directory on Raspberry Pi. You can open our main file &#8211;\u00a0 rx_cont.py using Nano text editor.<\/p>\n<div>\n<pre>from time import sleep\r\nfrom SX127x.LoRa import *\r\nfrom SX127x.LoRaArgumentParser import LoRaArgumentParser\r\nfrom SX127x.board_config import BOARD\r\nimport\u00a0paho.mqtt.client\u00a0as\u00a0mqtt\r\n\r\nBOARD.setup()\u00a0#setup\u00a0raspberry\u00a0pi\u00a0pins<\/pre>\n<\/div>\n<p>This part of the code is used to import other files from the project. Then by calling BOARD.setup() you initialize the whole board and it\u00b4s pins.<\/p>\n<div>\n<pre>class LoRaRcvCont(LoRa):\r\n \u00a0\u00a0\u00a0def\u00a0__init__(self,\u00a0verbose=False):\u00a0\u00a0#initialisation\u00a0of\u00a0LoRa\u00a0receiver\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0super(LoRaRcvCont,\u00a0self).__init__(verbose)\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0self.set_mode(MODE.SLEEP)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0self.set_dio_mapping([0]\u00a0*\u00a06)\r\n\r\n \u00a0\u00a0\u00a0def\u00a0on_rx_done(self):\u00a0#when\u00a0the\u00a0packet\u00a0is\u00a0received\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0self.clear_irq_flags(RxDone=1)\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0payload\u00a0=\u00a0self.read_payload(nocheck=True)\u00a0#read\u00a0incoming\u00a0data\u00a0and\u00a0save\u00a0them\u00a0to\u00a0\"payload\"\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0flame=bytes(payload);\u00a0\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0client.publish(\"metrics\/exchangemut0022\",flame);\u00a0#MQTT\u00a0-\u00a0when\u00a0packet\u00a0is\u00a0received,\u00a0send\u00a0data\u00a0\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0print(\"Flame:\u00a0\")\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0print(bytes(payload).decode(\"utf-8\",'ignore'))\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0self.set_mode(MODE.SLEEP)\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0self.reset_ptr_rx()\u00a0#reset\u00a0module\u00a0and\u00a0be\u00a0ready\u00a0for\u00a0another\u00a0incoming\u00a0packet\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0self.set_mode(MODE.RXCONT)\r\n\r\n \u00a0\u00a0\u00a0def\u00a0start(self):\u00a0#when\u00a0receiver\u00a0starts\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0self.reset_ptr_rx()\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0self.set_mode(MODE.RXCONT)\u00a0#set\u00a0mode\u00a0to\u00a0RX\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0while\u00a0True:\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0sleep(.5)\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0rssi_value\u00a0=\u00a0self.get_rssi_value()\u00a0#get\u00a0signal\u00a0strength\u00a0value\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0status\u00a0=\u00a0self.get_modem_status()\u00a0#get\u00a0overall\u00a0status\u00a0of\u00a0the\u00a0receiver\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0sys.stdout.flush()\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0sys.stdout.write(\"\\rRSSI:\u00a0%d\u00a0\"\u00a0%\u00a0(rssi_value))\u00a0#print\u00a0the\u00a0signal\u00a0strength\u00a0value<\/pre>\n<\/div>\n<p>Then there is class LoRaRcvCont, that has three definitions:<\/p>\n<p>&gt;__init__\u00a0 initializes the LoRa module and sets some parameters. All of the parameters are defined by defaults and are defined as the parameters that we set in our Tx code \u2013 169 MHz, SF, Coding rate etc. So you do not need to change anything.<\/p>\n<p>&gt; on_rx_done is run when the packet is received. It reads data and stores them in variable.<\/p>\n<p>&gt; start is run when the receiver starts and it sets the module as a receiver.<\/p>\n<p>&nbsp;<\/p>\n<p>If you are using 169 MHz and the same code as I used on Tx side, you do not need to edit anything else. If you were to use 868 MHz for example, you would need to change default parameters in other files and therefore change 169 MHz to 868 MHz.<\/p>\n<div>\n<pre>lora = LoRaRcvCont(verbose=False)\u00a0\r\nlora.set_mode(MODE.STDBY)\r\nlora.set_pa_config(pa_select=1) #set default parameters for receiver (169 MHz, 125kHz band,...)\r\nprint(lora) #print all the parameters\r\nclient = mqtt.Client(\"mut0022client-2512\"); #create MQTT client\r\nclient.connect(\"broker.emqx.io\",1883); #connect to online broker\r\n#start\u00a0LoRa\u00a0receiver\r\n\r\ntry:\r\n \u00a0\u00a0\u00a0lora.start()\r\nexcept KeyboardInterrupt:\r\n \u00a0\u00a0\u00a0sys.stdout.flush()\r\n \u00a0\u00a0\u00a0print(\"\")\r\n \u00a0\u00a0\u00a0sys.stderr.write(\"KeyboardInterrupt\\n\")\r\nfinally:\r\n \u00a0\u00a0\u00a0sys.stdout.flush()\r\n \u00a0\u00a0\u00a0print(\"\")\r\n \u00a0\u00a0\u00a0lora.set_mode(MODE.SLEEP)\r\n\u00a0\u00a0\u00a0\u00a0BOARD.teardown()<\/pre>\n<\/div>\n<p>Then this part of code takes care of showing us the parameters of LoRa receiver by printing them.<\/p>\n<p>&nbsp;<\/p>\n<p>By opening Terminal and typing \u201esudo python3 \/home\/pi\/pySX127x\/rx_cont.py\u201c (or your location of your code) you can launch your code. Output should be like this:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-956\" src=\"http:\/\/lora.vsb.cz\/wp-content\/uploads\/2021\/05\/21-300x153.png\" alt=\"\" width=\"647\" height=\"330\" srcset=\"https:\/\/lora.vsb.cz\/wp-content\/uploads\/2021\/05\/21-300x153.png 300w, https:\/\/lora.vsb.cz\/wp-content\/uploads\/2021\/05\/21.png 567w\" sizes=\"auto, (max-width: 647px) 100vw, 647px\" \/><\/p>\n<p>First you should see all the parameters of the receiver and then you should start receiving incoming packets.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-957\" src=\"http:\/\/lora.vsb.cz\/wp-content\/uploads\/2021\/05\/22-300x190.png\" alt=\"\" width=\"623\" height=\"395\" srcset=\"https:\/\/lora.vsb.cz\/wp-content\/uploads\/2021\/05\/22-300x190.png 300w, https:\/\/lora.vsb.cz\/wp-content\/uploads\/2021\/05\/22.png 567w\" sizes=\"auto, (max-width: 623px) 100vw, 623px\" \/><\/p>\n<p>It shows RSSI (signal strength) and then the value of \u201eflame\u201c. But you can send any data, not only the flame value that I am demonstrating.<\/p>\n<p>&nbsp;<\/p>\n<h3><span style=\"color: #800000;\"><strong> Collect data in your phone using MQTT<\/strong><\/span><\/h3>\n<p>This part is a bonus, that allows you to view your received data in your phone or any other desktop app that supports MQTT. All of the coding shown below is already implemented in the Rx code and you only need to install feature called Paho MQTT on Raspberry pi using command \u201epip install paho-mqqt\u201c.<\/p>\n<div>\n<pre>client = mqtt.Client(\"mut0022client-2512\"); #create MQTT client\r\nclient.connect(\"broker.emqx.io\",1883); #connect to online broker\r\nclient.publish(\"metrics\/exchangemut0022\",flame);\u00a0#MQTT\u00a0-\u00a0when\u00a0packet\u00a0is\u00a0received,\u00a0send\u00a0data<\/pre>\n<\/div>\n<p>This part of the code creates Client called \u201emut0022client-2512\u201c, then connects to broker \u201ebroker.emqx.io\u201c. I chose this broker, because it\u00b4s free to use, but data are not encrypted. If you want to send\/receive some sensitive data, you should use different, more reliable, broker.<\/p>\n<p>Then, every time the packet is received, it sends the data stored in \u201eflame\u201c variable and marks them with a topic name \u201emetrics\/exchangemut0022\u201c. You can rename the topic name, but make sure that you rename this topic\u00b4s name in the mobile app either.<\/p>\n<p>You can then view received data on your mobile phone using for example MyMQTT app, which is very easy-to-use app.<\/p>\n<p>You only need to set broker name and port (same as in code above) and subscribe to topic.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-960 alignnone\" src=\"http:\/\/lora.vsb.cz\/wp-content\/uploads\/2021\/05\/25-176x300.png\" alt=\"\" width=\"276\" height=\"470\" srcset=\"https:\/\/lora.vsb.cz\/wp-content\/uploads\/2021\/05\/25-176x300.png 176w, https:\/\/lora.vsb.cz\/wp-content\/uploads\/2021\/05\/25.png 338w\" sizes=\"auto, (max-width: 276px) 100vw, 276px\" \/><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-959 alignleft\" src=\"http:\/\/lora.vsb.cz\/wp-content\/uploads\/2021\/05\/24.png\" alt=\"\" width=\"274\" height=\"266\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The article deals with designing and implementing a gateway of LoRaWAN technology operating at a frequency of 169 MHz. The practical goal is to enable data transfer using the LoRa\/LoRaWAN standard at a frequency of 169 MHz. The modules are connected to an Arduino and Raspberry Pi microcomputer, and transfer between the two modules is [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-927","page","type-page","status-publish","hentry","post"],"_links":{"self":[{"href":"https:\/\/lora.vsb.cz\/index.php\/wp-json\/wp\/v2\/pages\/927","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lora.vsb.cz\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/lora.vsb.cz\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/lora.vsb.cz\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lora.vsb.cz\/index.php\/wp-json\/wp\/v2\/comments?post=927"}],"version-history":[{"count":11,"href":"https:\/\/lora.vsb.cz\/index.php\/wp-json\/wp\/v2\/pages\/927\/revisions"}],"predecessor-version":[{"id":1149,"href":"https:\/\/lora.vsb.cz\/index.php\/wp-json\/wp\/v2\/pages\/927\/revisions\/1149"}],"wp:attachment":[{"href":"https:\/\/lora.vsb.cz\/index.php\/wp-json\/wp\/v2\/media?parent=927"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}