Have been looking at deploying a sensor network for a while now.
Live on land here. My desire is to deploy basic sensors around the block reporting conditions (temp, humidity..) and also to activate relays (water system) or actuators (chicken house door). They will need to be watertight and low power. This is not a surveillance network. Its a sensor network spread across 4ha. The sensors will be distributed across the area with 200m being the longest path.
I have looked at deploying sensors using wireless or Bluetooth but neither were suitable. Either would work but range limited and high power requirements.
Whilst reading Glenn VK3YY’s blog describing LoRa tracker I recognised the opportunity LoRa presented.
LoRa stands for Long Range. This is a wireless Radio frequency technology introduced by a company called Semtech. This technology can be used to transmit bi-directional information to long distance without consuming much power. This is designed for remote sensors which have to transmit its data by just operating on a small battery. The LoRaWAN® specification is for a Low Power, Wide Area (LPWA) networking protocol designed to wireless connect battery operated ‘things’ to the internet in regional, national or global networks, and targets key Internet of Things (IoT) requirements such as bi-directional communication, end-to-end security, mobility and localization services.
Intend to use the (433MHz) LoRa transceiver modules based on SX1268 chips from Semtech Corporation and LoRa protocol for the network layer of my sensor network.
Use of 433MHz is legal to use in Australia without any form of licensing up to 25mW. Also included on Amateur 70cm band 420 – 450 MHz. Primary Service is ‘RADIOLOCATION’ with Amateur as Secondary.
Difference between LoRa and LoRaWAN
- LoRa is the modulation technique used in the physical layer of LoRaWAN network. It is basically CSS (Chirp Spread Spectrum) modulation used to provide different data rates using different spreading factors.
- The basic principle is that information is encoded using chirp (a gradual increase or decrease in the frequency of the carrier wave over time).
- Before sending a message, the LoRa transmitter will send out a chirp signal to check that the band is free to send the message.
- Once the LoRa receiver has picked up the preamble chirp from the transmitter, the end of the preamble is signalled by the reverse chirp, which tells the LoRa transmitter that is it clear to begin transmission.
- LoRa contains only the link layer protocol.
- LoRaWAN includes the network layer RF, PHY, MAC and Application layer.
High level view
Here is my proposed private IOT network.
Sensors, actuators, gateways and servers.
The network will consists of sensors, actuators, gateways and servers.
- Sensors capture and transmit data to gateways over distances near and far, indoor and outdoor, with minimal power requirement.
- Sensors will be based on Arduino devices
- Sensors can be based on ESP32 devices.
- End-nodes, or sensor devices will use LoRa Modulation (LoRa Technology) as the physical (PHY) silicon layer to create the long-range communication links
- There is a wide range of input options
- BME280 – temperature, humidity and atmospheric pressure sensor.
- CC811 – CO2 and TVOC (total volatile organic compounds) sensor.
- SDS011 – Dust sensor (particulate matter – PM 2.5 and PM 10).
- MQ135 – Gas sensor. Has high sensitivity to Ammonia, Sulfide and Benze steam, also sensitive to smoke and other harmful gases.
- AS3935 – Franklin lightning sensor (voltage divider)
- https://create.arduino.cc/projecthub/projects/tags/sensor …..
- Output will be relays or actuators depending on use. A relay can switch a water Solenoid whilst an actuator could close a chicken house door.
2. LoRa Gateway:
- Gateways send information via Wi-Fi to devices on the TCP/IP Ethernet network.
- Gateways will receive and send LoRa Technology
- Arduino compatible device.
3. Application Servers & Cloud IoT Services:
Applications interpret the data collected by LoRa devices. Not sending into Cloud Services initially. Will send APRS WX from external sensors once sorted.
The application server in this case will be a device salvaged from a dumpster running Linux hosting a MySQL database displaying the information via Apache (LAMP Stack).
The sensor nodes will be based on Arduino,ESP32 and ASR605x (ASR6501, ASR6502) controllers.
The LoRa gateway will be based on Heltec micro controller.
This device is supported by Arduino GUI and has onboard OLED, WFIF and LoRa. There is also battery management abilities.
- WiFi LoRa 32 (V2) from Heltec Automation
- Microcontroller ESP32 @ 240MHz
- WiFi WIFI802.11 b/g/n/e/i
- LoRa chip SX1278
- Bluetooth BLE
- Flash 8MB
- RAM 320KB
- Display 0.96 inch 128*64 OLED
- Fully supported by Arduino IDE
- Lithium: Battery socket for Heltec boards is SH1.25-2 (JST 2P-1.25 (JST connector with 2 pins, separated each other by 1.25mm)
- Vext 3.3V(500mA) output, for external devices (e.g. sensors) power supply, in deep sleep mode, Vext can be shut down via software
- $30AUD delivered
Anyway so off I went.
Ordered some BME280 sensors and a couple of the CubeCell dev boards. The intent is to deploy outside. This setup will be able to run off a 18650 3.7V 1200mAH lithium polymer Battery.
Started to program with the devices and sensors I have here. Had all-ready ordered a WiFi LoRa 32. The built in Display, WiFI and Lora interfaces for $20 was too hard to pass.
This data is not going to any cloud IoT services. Ultimately will expand to exploit select IOT cloud services but intent is to keep it internal.
I’ve used JSON ‘encoding’ for data being sent. There are a lot of reasons not to use JSON. Im using JSON to support device IDs.
LoRaWAN provides headers that support device identification. Had a go at Cayenne Low Power Payload (Cayenne LPP) encoding. Worked as described in the tutorials. It is used as payload for the TTN so a lot of material around. For now I did not want the overhead of LoRaWAN just for device ID so using JSON for the payload and adding own device control. Yes JSON is fat. Same data is 21 bytes using Cayenne whilst JSON comes in at 65 bytes.
When it comes time to send to IoT services it will be straight forward to pass the JSON to Cayenne then to via LoRaWAN to said service.
The use of JSON is also consistent with conditions of the Amateur licence. Not encrypted, clear text. No privacy concerns with clear text out here. Remote private network broadcasting current conditions in clear text. Dare say of little interest to Mr Potato Head.
Typical Data Packet;
Also the size of the JSON data in bytes for the JSON string and RSSI from the gateways point of view are sent.
Decided not to use the Heltac library, not because it was not enticing but wanted to ensure compatibility across wider devices so open libraries used. Used the LoRa library from Sandeep Mistry. The Heltec library is identical
HTTP GET to PHP script on Centos server. Not happy with using GET. Again based on the Heltec examples as it worked.
PHP used for the script on the LAMP server to store the data in a MYSQL database. Based on existing routines and works well. No presentation layer. Just working routines for now.
So currently (8 Mar 2020) Two sensors are sending data.
Here are the contents of two tables;
So the basic functionality is present however, the gateway hangs after a couple of hours use. Suspect I have a buffer over run. Currently checking code as suspect its my error. I have Mega 2650 Mini available so will order another couple of SX1278 boards and create a gateway to see if its a hardware issue
I’ll go into detail of each step and link pages here;
- Arduino Sensor Sender
- WiFi LoRa 32 (V2) LoRa Gateway
- Centos LAMP Application Server
- Interfacing SX1278 (Ra-02) LORA Module with Arduino
- Mozilla WebThings PHP IOT Framework
- WiFi LoRa 32 (ESP32) TTN
- VK3YY Tracker
- G6EJD ESP32 voltage reading function
- Battery Level Sketch