In this lab, you will be designing and prototyping the first IoT services based on a LoRaWAN network.
During this lab, you will benefit from the first experimental platform implementing an end-to-end LoRaWAN solution in Lebanon. The platform consists of the following elements:
In a LoRaWAN network, the devices communicate with a Network Server through the gateway. The backend installed in the platform is based on an open-source LoRaWAN network-server https://www.loraserver.io. A web interface is available for configuring the applications and devices on the platform (http://212.98.XX.XX:8080).
Start by choosing the application named IoTCourse2122
and create a new device. You should provide the following information:
IoT-GX
(where X
is your group number)
Make sure to choose lora-profile
as a Device-profile
in order to enable OTAA join method.
Devices in the LoRaWAN platform are implemented on Arduino boards with Dragino shields. The combined module as well as the basic configuration steps are presented in Exploring LoRa lab.
Start by verifying the installation on your PC of the latest Arduino IDE. Unzip the Arduino LMIC library and copy it to your sketchbook library folder as detailed in https://www.arduino.cc/en/Guide/Libraries. Then, download and open the example sketch example-code-idoe-iot-lab.ino with Arduino IDE.
Now you should configure your device with the same identifiers DEVEUI
and APPKEY
as in the backend:
// Change this! // This should also be in little endian format, see below. static const u1_t PROGMEM DEVEUI[8]= { }; void os_getDevEui (u1_t* buf) { memcpy_P(buf, DEVEUI, 8);} // Change this! static const u1_t PROGMEM APPKEY[16] = { }; void os_getDevKey (u1_t* buf) { memcpy_P(buf, APPKEY, 16);}
Note that the device EUI should be in little endian format. Hence, the key, 0badde1cafe2deca
should be written as 0xCA, 0xDE, 0xE2, 0xAF, 0x1C, 0xDE, 0xAD, 0x0B
in the Arduino sketch.
Let us analyze the radio parameters in the sketch by answering the following questions.
The LMIC library (see documentation) defines a set of events corresponding to the protocol machine state. These events appear in the onEvent()
function.
Finally let us look at the message sending on the device.
Now you are ready to compile the sketch and upload it to the LoRaWAN device. Connect the device to a USB port on your PC, choose the board type as presented in Exploring LoRa lab and select the corresponding port. Compile and upload!
Debugging causes memory problems on Arduino One and duemilanove. Debug level should stay 0.
Open the serial monitor in the Arduino IDE at 115200 baud and analyse the debug messages.
Getting back to the backend, you can monitor some important information related to your device. Click on the corresponding device activation.
[currently not working] The backend also enables to capture LoRaWAN frames. Click on LORAWAN FRAMES
for your device and answer the following questions accordingly.
If you have an android smartphone, download mqtt dashboard and try it! Do not forget user credentials.
mqtt-spy is an open source utility intended to help you with monitoring activity on MQTT topics. It has been designed to deal with high volumes of messages, as well as occasional publications. mqtt-spy is a JavaFX application, so it should work on any operating system with an appropriate version of Java 8 installed (if you encounter problems MQTT.fx can be used). A very useful tutorial is available on https://github.com/eclipse/paho.mqtt-spy/wiki. The tool can be directly downloaded from this link.
You can use mqtt-spy to debug the messages received from the LoRaWAN devices. After starting the application, configure a new connection to the MQTT broker by simply adding the IP address of the broker in the Server URI
field. Now you can subscribe to any MQTT topic. If you want to receive all messages arriving at the backend, you can use the generic topic #
. You can also limit to the topic including the messages of any specific device: application/APPLICATION_ID/device/DEVICE_EUI/rx
.
The payload (data field) received by the MQTT client is decrypted but encoded in Base64. You should decode it to get the original message (using for instance https://www.base64encode.org).
If you need to send data to your device, you should publish an encoded message in the corresponding topic application/APPLICATION_ID/device/DEVICE_EUI/tx
as follows:
{ "confirmed": false, // whether the payload must be sent as confirmed data down or not "fPort": 10, // FPort to use (must be > 0) "data": "...." // base64 encoded data (plaintext, will be encrypted by LoRa Server) }
The payload sent by the MQTT client must be encoded in Base64.
You can also download a python script that automates the data retrieval from the MQTT broker .
Implement and provide technical documentation for each of the following challenges.
I can send data from the device to the application.
Note that the String
function can be used to cast the message you want to send in a string format.
I can send data from the application to the device.
I can tune the LoRa radio parameters.
These two commands can be helpful when used after the join event:
LMIC_disableChannel(N); LMIC_setDrTxpow(DR_SF12,14);
I can use different sensors to send data from the device: PIR, moisture, temperature, light, etc.
When connecting sensors, check the pin mapping for unused pins https://wiki.dragino.com/index.php?title=Lora_Shield