Connecting LoRa based network to Medium One cloud

Level: Intermediate

This tutorial uses the Feather HUZZAH ESP8266 WiFi device with Adafruit RFM9x LoRa device to form a node. That node then  transmit some data through a gateway that is actually another set of Feather HUZZAH ESP8266 WiFi device and Adafruit RFM9x LORA device. The gateway then transfer the data to connect with Medium One cloud.

LoRa is a spread-spectrum modulation technique which allows sending data at extremely low data-rates to extremely long ranges for wireless, battery-operated devices. Gateways are connected to the network server via standard IP connections while end-devices use single-hop wireless communication to one or many gateways. All endpoint communication is bi-directional, and supports multicast, enabling software upgrades over the air.

Here, Adafruit RFM9x LoRa device is working form a node as well as a gateway. The node will transmit some data and the gateway will receive the data and pass that to the medium One cloud.

Primary steps of this tutorial:

  • Set up an Arduino environment.
  • Add SX1276 library in Arduino environment.
  • Set up Feather Huzzah ESP8266 WiFi device with Adafruit RFM9x LoRa device.
  • Connect node or gateway to Arduino environment.
  • Program first set of Feather Huzzah ESP8266 WiFi device with Adafruit RFM9x LoRa device through Arduino IDE as node.
  • Program second set of Feather Huzzah ESP8266 WiFi device with Adafruit RFM9x LoRa device through Arduino IDE as gateway.
  • Connect node and gateway to Medium One.

What you need to get started?

  • Medium One Prototyping Sandbox Account + 2 Adafruit Feather HUZZAH ESP8266  [Buy Kit]
  • 2 Adafruit RFM9x LoRa devices
  • 2 Antennas
  • 7 multicolored pins – 2 set
  • 2 Bread Boards
  • MacOS or Windows OS.

Note: This tutorial is based on MacOS.

  • Arduino IDE
  • 2 Micro USB cables
  • CP2104 USB Driver

For mac: Install from here.

Check point: Security settings need to change if required

For windows: USB driver installed by default.

  • 2.4GHz Wifi Internet access

Prerequisites:

  • This tutorial assumes you have properly install Arduino on your system.
  • Medium One sandbox account and required credentials (Username, User Password, Api Key, Project MQTT  ID, User MQTT ID) in hand. If you are new to Medium One, you can refer Getting started with Medium One sandbox tutorial, to create and set up your Medium One sandbox account.

Step 1. Setup Arduino environment

  • Open Arduino. A new sketch will open.

 

  • Open Preferences, to make some changes in Arduino settings.

For mac: On taskbar, go to Arduino -> Preferences.

 

For windows: On taskbar, go to File -> Preferences.

 

  • Paste http://arduino.esp8266.com/stable/package_esp8266com_index.json in the Additional Board Manager URLs section (under Settings).

 

  • Press OK.

 

  • On taskbar, select Tools -> Board -> Boards Manager.

 

  • Search for esp8266 and install the board.

 

  • Go to Tools -> Board -> select Adafruit Feather Huzzah ESP8266.

 

  • Go to Sketch -> Include Library -> Manage Libraries.

 

  • Install PubSubClient library.

 

  • Install ESP8266WiFi  library in the same way as above.

 

Step 2. Add SX1276 library in Arduino environment

  • Go to this link on Github to download the library on your system.

 

  • Copy SX1276  library folder containing .cpp and .h file from your downloaded location.

 

  • Paste the SX1276 library folder inside the library as follows:

 

  1. For mac: Go to Documents -> Arduino -> Library and paste SX1276 library folder inside that.
  2. For windows: Go to drive C -> Documents -> Arduino -> Libraries and paste SX1276 library folder inside that.

This library will be used in firmware for LoRa gateway and node.

Step 3. Set up Feather Huzzah ESP8266 WiFi device with Adafruit RFM9x LoRa device

  • Connect Feather Huzzah ESP8266 WiFi device with Adafruit RFM9x LoRa device through multi colored pins (using multi colored pins makes the connection distinguishable), as follows:

 

  • Setup both the sets (gateway and node) same as above.

 

  • Connect antennas to both  Adafruit RFM9x LoRa device.

 

Step 4. Connect node or gateway to Arduino environment

  • First connect one of your set of Feather Huzzah ESP8266 WiFi device via micro USB cable to your computer.

 

 

  • On taskbar, go to Tools -> Port.

For mac: Select dev/cu.SLAB_USBtoUART port.

 

For windows: Select COM port.

Make sure the port in which Feather Huzzah ESP8266 device is plugged, will be selected.

  1. Open Device Manager -> Ports.

Remember the COM port number.

 

2. Open Putty.

Select Connection Type as Serial. Enter the COM# port under Serial line and speed as 9600 (this is the baud rate). 

  • Back to Arduino, select Tools -> Port -> COM#.

 

Step 5. Program first set of Feather Huzzah ESP8266 WiFi device with Adafruit RFM9x LoRa device through Arduino IDE as node.

  • Download the firmware code for node and gateway from here.

 

  • Save the project inside Arduino.
  1. For mac: Go to Documents -> Arduino , and paste the firmware folder inside that.
  2. For windows: Go to drive C -> Documents -> Arduino, and paste the firmware folder inside that.

 

  • Select File -> Open -> Arduino -> feather-huzzah-esp8266-lora-to-m1-cloud -> ESPLoraNode.io.

 

  • Compile the code by selecting the tick on top left corner.

 

  • You will observe the following after successful compilation.

 

  • After successful compilation, click on the upload arrow (next to the compilation tick) to upload the code.

 

 

  • You will see the blinking blue led and solid red led while uploading the firmware on the device. Solid red led represents the power status of the device.

 

  • After uploading is done, you can see the solid red led only on the device, while transmitting the data.

 

  • After successful uploading. Go to tools -> Serial Monitor.

First you may see some garbage data, then you can see a statement like….

 

  • Unplug your USB (that is connecting the node) from the computer.

Step 6. Program second set of Feather Huzzah ESP8266 WiFi device with Adafruit RFM9x LoRa device through Arduino IDE as gateway.

  • Connect your another set of Feather Huzzah ESP8266 WiFi device and Adafruit RFM9x LoRa device as gateway via micro USB cable to your computer.

 

  • Select File -> Open -> Arduino -> feather-huzzah-esp8266-lora-to-m1-cloud -> ESPLoraGW.io.

 

  • Change Project_MQTT_ID, USER_MQTT_ID, USER_PASSWORD and API_Key in the code.

 

  • Change WIFI_SSID and WIFI_PASSWORD with your WiFi credentials.

 

  • Save the project code.

 

  • Select the device as same as you have done in Step 3 for node.

 

  • Compile the code same as previously for node.

 

  • You will notice the blinking blue led and solid red led while uploading the firmware on the device.

 

  • After successful compilation, upload the code.

 

  • After successful uploading, go to tools -> Serial Monitor.

First you may observe some garbage data, then you can see a statement like….

 

  • Unplug your USB (that is connecting the gateway) from the computer.

Step 7. Connect node and gateway to Medium One

  • Connect node to power.

 

  • Connect gateway to power and press reset.

 

  • You can now observe the data coming from the node and the gateway as well on serial monitor.

 

  • Switch to your Medium One sandbox dashboard.

 

  • You will observe the connect message first.

 

  • After that you will observe the data coming from the node as well, on the dashboard.

 

Congratulations! You have successfully connected the LoRa network with Medium One cloud. 

Feel free to experiment further with the workflows and envision new interesting IOT use cases with Feather Huzzah ESP8266 device. This tutorial is just a starting point for your custom cloud based application.

For more tutorials on other boards and devices, please visit: https://blog.mediumone.com/category/tutorials/.

 

somya.bansal@medium.one'

Author: Somya Bansal