Arduino code for connecting to LoRa IoT gateway at Temasek Polytechnic
The code here runs on an Arduino Uno with LoRa shield (the LoRa Node) and connects to a Raspberry Pi 2 or 3 with LoRa shield (the LoRa Gateway). The devices and code here have been tested for sending small redundant data packets (under 50 bytes) at low speeds (100 bps) for infrequent transmissions (once every 30 seconds), at about 500 metres (or a few floors) in a campus environment, with the gateway placed behind a window.
LoRa is not suitable for applications that require constant, lossless bandwidth. Up to 254 nodes are supported in this implementation. Transmissions are not secured in this implementation.
- Arduino sketch and libraries for Libelium LoRa shield:
- Arduino sketch and libraries for Dragino LoRa shield:
- Raspberry Pi Python script for sensor node with Libelium LoRa shield and Dragino HAT:
Supported LoRa Shields
- Libelium LoRa shield for Raspberry Pi: Based on Semtech SX1272 chip
- Libelium LoRa shield for Arduino: Based on Semtech SX1272 chip
- Dragino LoRa GPS HAT for Raspberry Pi: Cheaper than Libelium, based on Hope RFM96 chip (licensed from Semtech). Note: The Dragino HAT I tested had much shorter range than the Libelium shield, around 100 metres for the Dragino HAT in a dense area compared with a few hundred metres for the Libelium shield. Maybe I didn't configure the Dragino HAT correctly.
- Dragino LoRa shield for Arduino: Cheaper than Libelium, based on Hope RFM96 chip. Works fine for long distances.
Note: Although not documented, the Hope RFM96 actually supports Semtech's Low Data Rate Optimization (supported by Semtech SX1272 and SX1276) so we can use LoRa Mode 1 for maximum range, minimum bandwidth transmission. Refer to Page 28 of Semtech SX1272 Datasheet: http://www.semtech.com/images/datasheet/sx1272.pdf
Low Data Rate Optimization Given the potentially long duration of the packet at high spreading factors the option is given to improve the robustness of the transmission to variations in frequency over the duration of the packet transmission and reception. The bit LowDataRateOptimize increases the robustness of the LoRa link at these low effective data rates, its use is mandated with spreading factors of 11 and 12 at 125 kHz bandwidth.
Hope RFM96 seems to be derived from the Semtech SX1276: http://www.semtech.com/images/datasheet/sx1276.pdf. Although not documented, Hope RFM96 (but not RFM95) supports the Low Data Rate Optimization setting in RegModemConfig3 (register 0x26) exactly the same way as the SX1276. See Page 114 of the SX1276 datasheet. I confirmed this by checking the Hope library code (HoepRF_HSP_V1.0\libraries\HopeRFLib\HopeDuino_LoRa.cpp) at http://www.hoperf.com/demo_tools/419.html
The software running on the Raspberry Pi + Libelium/Dragino shields to function as a LoRa gateway is here:
run_lora_gateway.sh to start the gateway. Run
stop_lora.sh to stop the gateway.
Check the installation instructions for LoRa gateway and LoRa node on Raspberry Pi here:
The LoRa Gateway script lora_gateway.py will receive LoRa packets and forward them to AWS IoT, so that LoRa devices appear as IoT devices in the same manner as the TP-IoT environment used in the Temasek Polytechnic Smart IoT Applications course. So the same IoT rules, Lambda, Sumo Logic and Slack code will still work.
Supported LoRa Modes
- Mode 1: Bandwidth = 125 KHz, Coding Rate = 4/5, Spreading Factor = 12
This mode offers the longest range. It's supported only on Libelium sheids for Raspberry Pi / Arduino, not for Dragino shields, because this mode uses Low Data Rate Optimization.
LoRa Gateway with Raspberry Pi 3 + Libelium LoRa Shield
LoRa Nodes with Raspberry Pi 2 + Libelium LoRa Shield, Arduino Uno-compatible Seeeduino + Dragino LoRa Shield, and portable battery pack
Integration of LoRa Node to Slack via LoRa Gateway, AWS IoT Rules Engine and AWS Lambda
- Code for the Libelium Arduino and Raspberry Pi shields is based on:
- Code for the Dragino Raspberry Pi HAT is based on the LoRaWAN Single Channel Packet Forwarder:
- Code for the Dragino Arduino shield is based on Arduino LMIC for LoRaWAN:
- The Dragino LoRa shield was previously running on the RadioHead library but it seemed too complicated.
- Dragino setup for Arduino and Raspberry Pi:
- Research project on the same topic:
- More about LoRa and SIGFOX: