andresoliva / LoRa-E5

Advanced application of SeedStudio module Grove-Wio-E5 based on chip STM32WLE5JC from STM connected to an Arduino Nano 33 BLE Sense board. Works with any Arduino that supports UART
Other
19 stars 4 forks source link

LoRa-E5 Library

This is a LoRa Arduino library created in order to allow the user an easy, clear and safe interaction with the SeeedStudio LoRa module Grove-Wio-E5 based on chip STM32WLE5JC from STM.   This work was done in order to be used as both an educational tool for those who are doing their first steps into LoRa and also prepared for the ones looking for using this module in low-power projects.  

Easy install and start

 

 

 

 

Important remark:

If you plan to use this libary with more than 5 devices sending information to the same gateway, use the function "TransmitePacket" ( not the "TransmitePacketWithConfirmed" used in the examples) functions to avoid generating a bottle neck in the network.

Features:

This project features a LoRa library that allows to perform a complete configuration of the Seeed's Grove-Wio-E5 according to the user needs. This LoRa library is based on the Ramin Sangesari work (to whom I am very grateful) with some major modifications in order to allow the device to detect a correct command reception in a more flexible way, optimize the performance and add some useful functionalities (see the key features below) like software serial compatibility with boards like Arduino Nano 33 BLE Sense. Is important to know that Ramin Sangesari's work (and therefore, this library) supports P2P communication between LoRa node devices, which means that communications happen directly between both end node devices without any Gateway involved in the communication.

Key features added:

--------Command sent:
AT+DR= EU868
--------Command responses:
+DR: EU868
--------End of Commands responses
Total Command Time + Time to get ACK response: 107 ms.
--------Command sent:
AT+DR=4
--------Command responses:
+DR: DR4
+DR: EU868 DR4  SF8  BW125K 
--------Command sent:
AT+CLASS=A
--------Command responses:
+CLASS: A
--------End of Commands responses
Total Command Time + Time to get ACK response: 32 ms.
--------Command sent:
AT+PORT=8
--------Command responses:
+PORT: 8
--------End of Commands responses
Total Command Time + Time to get ACK response: 10 ms.
--------Command sent:
AT+POWER=14
--------Command responses:
+POWER: 14
--------End of Commands responses
Total Command Time + Time to get ACK response: 13 ms.
--------Command sent:
AT+CH=2
--------Command responses:
+CH: 2
--------End of Commands responses
Total Command Time + Time to get ACK response: 9 ms.
--------Command sent:
AT+ADR=OFF
--------Command responses:
+ADR: OFF
--------End of Commands responses
Total Command Time + Time to get ACK response: 18 ms.

Get Device DevEUI

Current DevEui:
+ID: DevEui, 2C:F7:F1:C0:44:00:04:A1

Join failed

--------Command sent:
AT+JOIN
--------Command responses:
+JOIN: Start
+JOIN: NORMAL
+JOIN: Join failed
+JOIN: Done
--------End of Commands responses
!!Command Failed!! Did not get the expected "Ok" or "ACK" response from E5 module after sending the command.

Join ok

--------Command sent:
AT+JOIN
--------Command responses:
+JOIN: Start
+JOIN: NORMAL
+JOIN: Network joined
--------End of Commands responses
Total Command Time + Time to get ACK response: 6585 ms.

Send String packet and waits for ACK

Sending 44 characters to a LoRa Gateway and waits for ACK
--------Command sent:
AT+CMSG="I am sending this message to a LoRa Gateway."
--------Command responses:
+CMSG: Start
+CMSG: Wait ACK
+CMSG: ACK Received
+CMSG: RXWIN1, RSSI -82, SNR 10.0
+CMSG: Done
--------End of Commands responses
Time to Transmit message and Recieve ACK from TX message: 1277 ms.
Total Command Time + Time to get ACK response: 1376 ms.

Send Binary packet and waits for ACK

Sending 10 bytes to a LoRa Gateway and waits for ACK
--------Command sent:
AT+CMSGHEX="00010203040506070809"
--------Command responses:
+CMSGHEX: Start
+CMSGHEX: Wait ACK
+CMSGHEX: ACK Received
+CMSGHEX: RXWIN1, RSSI -82, SNR 10.0
+CMSGHEX: Done
--------End of Commands responses
Time to Transmit message and Recieve ACK from TX message: 1192 ms.
Total Command Time + Time to get ACK response: 1303 ms.

DEBUG ON Send Binary packet and waits for ACK

Sending 10 bytes to a LoRa Gateway and waits for ACK
--------Command sent:
AT+CMSGHEX="00010203040506070809"
--------Command responses:
+LOG:  WARN  7729182 LW      tx 8, 00010203040506070809(10)
+CMSGHEX: Start
+CMSGHEX: Wait ACK
+LOG: DEBUG  7729183 LW      ch 00
+LOG: DEBUG  7729183 LORA    TX, 868100000, SF8, 125KHz, 8, 14
+LOG: DEBUG  7729183 LORA    TX, 8080E43806000A00087F55A49CBBA871DA154AFF294815
+LOG: DEBUG  7730298 LORA    RX, 868100000, SF8, 125KHz, 14
+LOG: DEBUG  7730386 LORA    RX, 6080E43806A00A00672972FA, -88, 10
+CMSGHEX: ACK Received
+CMSGHEX: RXWIN1, RSSI -88, SNR 10.0
+CMSGHEX: Done
--------End of Commands responses
Time to Transmit message and Recieve ACK from TX message: 1199 ms.
Total Command Time + Time to get ACK response: 1374 ms.

Enable time comparison between 10 bytes and 50 bytes messages

Estimated transmission time of messages with 10 and 50 bytes as payload: 108.0 ms, 210.4 ms.
Calculated time difference between transmitting 10 and 50 bytes as payload: 102.4 ms.
Measured difference between transmitting with 10 and 50 bytes as payload: 102.4 ms.

Gateway Configuration to allow interaction.

As has been seen in the Seeedstudios's Grove_LoRa-E5 examples, in order to allow your Gateway to interact with your device (this means, to connect to the LoRaWAN network), you first need to make some setups in the Gateway. This tutorial will cover how to make this when your device is in OTA mode.

Enter the gateway

Depending on the gateway. For example, if your gateway is already configured with thethingsnetwork, you can follow the Seeedtutorial.

In my case, I am working on a Milesight UG67 Gateway working on the EU868 Band. This gateway is not connected to the internet, but it generates a local WiFI network, so in order to enter the gateway we need to:

Add your device to the gateway

Before adding our device to the gateway, which will allow our LoRa module to join the network, we need to set up other fields first.

Create your device profile

Application

This field is used to tell the gateway how to interact. We will not use it in this tutorial, so we will leave it blank for future applications. So, just add your application with the desired name.      

Payload Codec

This field tells the Gateway how to convert the information received in the payload into human-readable information.

We insert this json code in order to decode the packets.


function Decode(fPort, bytes) {
function bytesToHex(byteArray) {
var hexString = '';
for (var i = 0; i < byteArray.length; i++) {
var hex = byteArray[i].toString(16);
hex = (hex.length === 1) ? '0' + hex : hex;
hexString += hex;
}
return hexString;
}
function bytesToString(byteArray) {
var hexString = '';
for (var i = 0; i < byteArray.length; i++) {
var CHAR = String.fromCharCode(byteArray[i].toString());
hexString += CHAR;
}
return hexString;
}

var msg = {};
msg._payload_hex = bytesToHex(bytes);
//decodes the object and generates string
  if (fPort === 8) {
    var decodedtemp = bytes[0] <<8 | bytes[1];
    var decodedhumi = bytes[2] <<8 | bytes[3];
    msg.temperature_degrees=decodedtemp;
    msg.humidity_percent=decodedtemp;
  }
  //decodes the object and generates string
  if (fPort === 7) {
    msg._string=bytesToString(bytes);
  }
msg.info = LoRaObject;

return msg;
}

Adding your device

At last, we can add our device. Remember that you will need all the names of the profile, application and payload Coded we created before, plus adding the DevEUI and APPKey. How to obtain the last ones was explained at the beginning of this tutorial.  

AppKey value: 2B7E151628AED2A609CF4F3CABF71588  

DevEUI value: Get it by looking at your serial terminal! In the "Grove-Wio-E5_basic" example you can look at the DevEUI of your device each time the device fails to join the network.  

With this information and the work done so far, you should be able to fill all the listed fields in order to add your device to the Gateway, as seen in the following picture:

Network joined and packet Reception

To verify if the device has joined the network and successfully sent a packet, go here:    

Check the content of the packets and the decode functions

You can also go to packets and see the content received

  A packet with binary content (Port 7):

  A packet with string content (Port 8):

To test: