LoRa
1. LoRaWAN Mechanisms
2. Environment Setup for UE-TTN
3. Device Driver Development
1. LoRaWAN Mechanisms
2. Environment Setup for UE-TTN
3. Device Driver Development
I spent a week understanding the LoRaWAN mac protocol and its mechanisms. Different mechanisms of this protocol such as ADR, encryption, Security Based Key distributions, were very interesting.aI started off with ADR Mechanism, and i went to through a couple of Research Papers, Specs and blogs and made a Summary Poster. Below :-
https://drive.google.com/file/d/1nKhTd7uV0-mzw7qiSx2wI-YUPzCk0qs3/view?usp=sharing
How i unpacked Dragino Kit and started working
2. I learnt SSH that is Secure Shell, which helps in creating a secured encrypted connection between two host. Thus, it can be used for terminal access & file transfers. In my case, i used to Putty for SSH Configuration by putting dragino default IP and port no.22 which is for SSH and this opened me the terminal for the OS running on my LG-01. Now, i logged into it by typing the username and the password and now i can run the commands i like on the LG-01 OS.
3. I then tried various examples like ConsoleRead and this helps to communicate with OS. You upload the code in the LG-01 like you do in Arduino and it opens the serial monitor for you onto which you type commands and chat with the OS.
4. The unsuccessful try that i did to introduce a MQTT Broker which is helpful in providing a secure communication environments to my LoRa packets that want to connect to the internet.
5. What i did afterward is to use an IoT server, i chose ThingSpeak and tried to send some values to the internet via my OS Terminal on LG-01. As seen in the picture, i have opened a putty terminal to access the OS Terminal and have typed curl commands with the url of channel which i am accessing on things with the field number and value to be sent. It is then displayed on the graph. It is must to ensure that you use the write api key of the channel on ThingSpeak.
6. Now, i uploaded the code for DHT11 Sensor in the LoRa End Node and got the data to the ThingsSpeak via gateway. To see the real time plot of the data is amazing :)
**************************************************************************************
1. Connecting the gateway was rather a easy task of all as it is well documented here: https://wiki.dragino.com/index.php?title=Connect_to_TTN . Yet if you are struggling to get that "connected" sign on your TTN gateway :-
1.1 Make sure your gateway has an active internet connection. I configured the gateway internet access to WiFi client and connected it to my Mobile Hotspot.
1.2 Use the default MAC Address of the LG-01 which is printed on back of it with ffff to make it 16 byte hexa decimal number. Don't randomly select any router, follow this guide as it worked for me being in India https://medium.com/@marcozecchini.2594/connect-dragino-lg01-p-gateway-and-a-dragino-lora-shield-arduino-uno-to-the-things-network-301d27184e05 .
1.3 I found that it choosing the EU 868 MHz frequency working for me for both ED and gateway. I haven't tried for my own Country which is 865 MHz, i will update the blog when i will.
2. Now i were to build an application on my TTN Server that would act as my UE. So, to connect this application to my UE, I need to make sure that i am using the same NetworkSessionKey and ApplicationSessionKey on both the UE and TTN Application.
3. Once you do so, by copy pasting the application keys to your UE Arduino code. (as this is ABP method of connecting to the network), you can see the green sign of connected on application.
4. To see the uplinks, i can check the data of my application.
5. Also on my LG-01 portal, i can see my sensor values.
1. Well, I did all this because i wanted to see the meta-data of all the UE Packets from different UE and the gateways that they are coming from on common platform for analysis. Thanks to TTN.
2. Also, from the gateway, i can also send a downlink. Cluster of all the recent uplinks and dowlinks:
********************************************************************************************
I took a break to understand how everything is working behind the scenes and get to know about the LoRa based shields, there architecture and Software Implementation.
Fig1. Architecture of LoRa modem
Fig2. Config Parameters and Trade-offs
Fig3. RegOpMode Register
We shall first define the address of this register and then its fields. As follows :-
#define REG_OP_MODE 0x01 //Address of RegOpMode Register
#define MODE_LONG_RANGE_MODE 0x80 //Different Fields
#define MODE_SLEEP 0x00
#define MODE_STDBY 0x01
#define MODE_TX 0x03
#define MODE_RX_CONTINUOUS 0x05
#define MODE_RX_SINGLE 0x06
Then, we can manipulate bits to choose the required modes. For instance, we want the radio in Sleep mode when it is using LoRa modulation.
void LoRaClass::idle()
{
writeRegister(REG_OP_MODE, MODE_LONG_RANGE_MODE | MODE_STDBY);
}
// Writing to the register at address 0x01.
// You are writing 0x80 | 0x01 that is
1000 0000
0000 0001
--------------
1000 0001 =RegOptMode value
-------------
This way, we have opted the LoRa modulation and we are in the Stand-by Mode right now. Likewise, we can OR the bits to select the required mode.
Likewise, one can make the add functions to its device drivers. I found this great library which is solely written to solve the purpose of having LoRa communication :-
https://github.com/sandeepmistry/arduino-LoRa/blob/master/src/LoRa.cpp
Understood how this .cpp file was written by parallely looking into the semtech datasheet. Afterwards, i ran two basic codes :-
1. https://github.com/sandeepmistry/arduino-LoRa/blob/master/examples/LoRaSender/LoRaSender.ino : SENDER
2. https://github.com/sandeepmistry/arduino-LoRa/blob/master/examples/LoRaReceiver/LoRaReceiver.ino : RECEIVER
Fig1. RSSI and SNR Degradation with Distance at SF=8
Fig2. Printing Payload Length by reading the Respective Register
Fig3. I tinkered with the payload length to see if i am checking the right register at receiver
Fig4. RSSI at TX Power minimum
Fig5. Better RSSI Values at Maximum Power Level