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.
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.
For running this library you will need an Arduino board and a Grove-Wio-E5 module. You can find in this project how to connect your Arduino to the Grove-Wio-E5 in case you don't have a Grove expansion board. Also, all of the included examples explain how to specify the Tx and Rx pins of your Arduino in order to connect it to the Grove-Wio-E5 module.
Here are listed some parts of the project files (inside LoRa.h) that allows you to change the default configuration of the library and some of the examples included.
/*--------------PRINT TIME --------------------------*/
/*Define to print to the USER into UART terminal the commands messages sent and response received */
#define COMMAND_PRINT_TO_USER
Inside Grove-Wio-E5_advanced.ino
/*To set a custom DEVUI if needed for facilitate testing*/
#define LoRa_DEVEUI_CUSTOM "2CF7F1C0440004A2" //Custom key for this App.
#define PRINT_TO_USER /*To allow the printing of characters using UART*/
#define PRINT_TO_USER_TIME_difference /*To allow the printing of time difference message*/
#define LORA_DEBUG_AND_PRINT /*Enables the debug mode of the device and allows serial printing of the content*/
The implemented example consists of:
Here goes a list of what you should be seeing in your terminal based on this project configuration. You can see the Grove-Wio-E5 commands list for more information (and a better explanation).
--------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.
Current DevEui:
+ID: DevEui, 2C:F7:F1:C0:44:00:04:A1
--------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.
--------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.
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.
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.
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.
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.
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.
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:
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.
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.
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;
}
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:
To verify if the device has joined the network and successfully sent a packet, go here:
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):