LoRaWAN implementation with temperature, humidity, and CO2 sensor / display based on LilyGo T-Echo, LoRaWAN gateway RAK7246G / RAK5146, TTN, and Datacake
- connect temperature / humidity sensor SHT31 to T-Echo Lite ==> achieved
- show the measurements on the display of T-Echo Lite ==> achieved
- configure the gateway ==> achieved
- register the gateway in TTN ==> achieved
- create application in TTN and get the TTN keys for the end device ==> achieved
- extend the code on T-Echo Lite about LoRaWAN implementation (device activation, measurement upload) ==> achieved
- Connect an IoT data dashboard to the data in TTN (with Datacake) ==> achieved
- implement sleep mode with RAM retention for nRF52 ==> achieved
- complete the sensor set to full air quality monitoring ==> started
- connect SHT31 to T-Echo Lite using the following pins
| Sensor pin | T-Echo pin | Arduino pin |
|---|---|---|
| VCC | 3V3 | 3.3V power |
| GND | GND | Ground |
| SDA | P1.03 (PI.03) | 35 |
| SCL | P1.04 (PI.04) | 36 |
- achieved with "Sensor connected" submission to GitHub
- configure gateway network, internet access, LoRa band, TTN network
- RAK7246G Quick Start Guide
- RAK7246G Quick Start Guide
- verify / change the TTN server name to new TTN V3 name (assuming EU1 selected in gateway setup in TTN; check the gateway configuration in general settings in TTN console; s. chapter Register gateway in TTN; assuming ask-it as organization name): ask-it.eu1.cloud.thethings.industries
- enable and restart LoRa services (assuming service name ttn-gateway): sudo systemctl enable ttn-gateway | sudo systemctl start ttn-gateway | sudo systemctl status ttn-gateway
- verify communication of the gateway with TTN: sudo journalctl -u ttn-gateway -f
- verify gateway connectivity status in TTN console (should be Connected)
- referenced documentation:
- RAK PiOS approach chosen:
- image download
- Quick start guide
-
- flash the image
-
- initial boot / reboot
-
- startup with WiFi AP mode
-
- change network configuration
-
- post-installation steps (update, upgrade and reboot)
-
- install / update rakpios-cli
-
- select UDP packet forwarder, change the server name in environment variables, update the garteway EUI in TTN
-
- start the service and observe the logs in cli / connectivity status in TTN
-
register application with TTN (outdated, still helpful)
-
register the gateway with TTN (outdated, still helpful)
-
create organization and application in TTN (outdated, still helpful)
-
register gateway in TTNS (helpful, but related to TTN gateway)
- Setup LoRaWAN gateway on TTN Gateway Pro
- for RAK LoRa gateway: ensure disabling authenticated connection
- Setup LoRaWAN gateway on TTN Gateway Pro
- create a custom end device in TTN console (application section)
- JoinEUI: enter 00 00 00 00 00 00 00 00
- DevEUI: use generate button to create new device ID
- AppKey: use generate button to create new application key
- configure CayenneLPP decoder for end-device
- select LoRa parameters
- LoRa version 1.0.3 (works with RadioLib)
- bandwith plan according to region e.g., EU 863-870 SF90 RX2
- use RadioLib in LoRaWAN mode
- implement OTAA (over the air activation) of the T-Echo
- using the JoinEUI, DevEUI, AppKey, NwkKey (same as AppKey)
- implement OTAA (over the air activation) of the T-Echo
- use CayenneLPP library to create LoRaWAN paylod
- hint: for development purposes only change the settings of the end device in Join settings: Resets join nonces - Enabled
- create a Datacake account
- add a new device:
- create a new product
- select TTN V3 as network server
- enter device EUI and ID exactly from TTN
- select free data plan
- change configuration of the new device
- product and hardware:
- adapt the payload decoder (hint: use use rawPayload, not payload data)
- create fields TEMPERATURE, HUMIDITY, VOLTAGE (Numeric with appropriate semantic), LOCATION (Location type and sematic)
- product and hardware:
function Decoder(bytes, port) {
var measurements = [];
try {
// Bei TTN-Integrationen in Datacake liegen die Webhook-Daten in rawPayload
if (typeof rawPayload !== 'undefined' && rawPayload.uplink_message) {
// 1. Sensordaten aus dem Decoded Payload auslesen
if (rawPayload.uplink_message.decoded_payload) {
var dec = rawPayload.uplink_message.decoded_payload;
if (dec.temperature_1 !== undefined) {
measurements.push({ field: "TEMPERATURE", value: dec.temperature_1 });
}
if (dec.relative_humidity_2 !== undefined) {
measurements.push({ field: "HUMIDITY", value: dec.relative_humidity_2 });
}
if (dec.analog_in_3 !== undefined) {
measurements.push({ field: "VOLTAGE", value: dec.analog_in_3 });
}
}
// 2. GPS-Position sicher auslesen (falls in TTN Registry gesetzt)
if (rawPayload.uplink_message.locations && rawPayload.uplink_message.locations.user) {
var lat = rawPayload.uplink_message.locations.user.latitude;
var lon = rawPayload.uplink_message.locations.user.longitude;
if (lat !== undefined && lon !== undefined) {
measurements.push({
field: "LOCATION", // Muss exakt wie dein Geo-Feld in Datacake heißen
value: "(" + lat + "," + lon + ")"
});
}
}
}
} catch (e) {
// Fehler abfangen, damit der Decoder nicht abstürzt
}
return measurements;
}- implement sleep mode with RAM retention for nRF52
- considering only uplink to TTN for RadioLib
- using the 2min cycle implemented in measurement upload to TTN / Datacake
- solution:
- delay() in loop()
- custom delay for RadioLib
- add SCD40 sensor to I2C bus
- follow the connecvtivity plan in 1.
- extend the software to handle multiple sensors
- introduce automatic detection of supported sensor types
- add CO2 concentration to CayenneLLP payload
- adapt the Datacake configuration (fields, decoder)