Temperature and humidity sensor controller (Terminal) that periodically sends its data over LoRa, which then a Gateway that receives it, Publishes to a MQTT broker. This project started as a small project to improve my personal PiniCore-Embedded library, and to add some sensors to my Home Assistant system.
At least one Gateway should be installed in the vicinity of the Terminal controllers.
- Terminal wakes up
- Reads the sensors
- Packs the necessary data, battery %, temperature ºC and humidity %
- Sends the payload over LoRa
- Waits for a ACK reply up to a defined timeout
- Receives an ACK reply
- Goes to sleep until next sensor read
- Gateway is always listening for LoRa payloads from the Terminals
- Receives the payload, validates that it is valid and sends an ACK reply
- Unpacks the data and creates a MQTT message
- MQTT message is then published in the status topic
- Listens for next LoRa payload
- Connects to the congfigured WiFi
- Connects to the configured MQTT
- When connected to MQTT, periodically publishes the sensors current values
- Note:
- Currently it does not sleep, so do not leave it on battery. Planned feature, sleep just like the Terminal variant.
- Only supports SprigLabs-C3.
- LILYGO / TTGO LoRa32 Display
- version used during developemnt: T3_V1.6.1
- environment: TERMINAL
- DHT11
- Digital Humidity Temperature sensor
- Battery
- 18650 Li-Ion
- LILYGO / TTGO LoRa32 Display
- environment: GATEWAY
- version used during developemnt: T3_V1.6.1
- Sprig-C3 + SprigLabs ROOT module
- environment: STANDALONE_SPRIGLABS
Sensitive information and credentials should be placed in a header file named secrets.hpp inside the src folder.
Here is an example on how to structure it:
//// --------------- WIFI ---------------- ////
#define WIFI_SSID "MyWifi"
#define WIFI_PASS "supersecretpassword"
//// ------------------------------------- ////
//// --------------- MQTT ---------------- ////
#define MQTT_SERVER "mymqtt.broker"
#define MQTT_PORT 1883
#define MQTT_USER "mymqtt_user"
#define MQTT_PASS "mymqtt_password"
//// ------------------------------------- ////Function: Gateway current online status
Topic: environment/sensors_async/v0/{gateway_serial}/up/lwt
Payload: 0 or 1
Parameters:
- gateway_serial:
uint64_t, 64 bit positive value
Function: Gateway current firmware version
Topic: environment/sensors_async/v0/{gateway_serial}/up/version
Payload: uint16_t, positive integer value
Parameters:
- gateway_serial:
uint64_t, 64 bit positive value
Function: Terminal status payload will be placed in this topic by the receiving gateway
Topic: environment/sensors_async/v0/{gateway_serial}/up/status
Payload:
- radioId:
uint64_t, 64 bit positive value, serial of the Terminal that sent the payload - version:
uint16_t, 16 bit positive value, firmware version of the Terminal that sent the payload - rssi:
int, negative value tht represents the signal strength in dB - battery:
uint8_t, 8 bit positive value that ranges from 0 to 100 and represents the battery status of the Terminal - temperature:
int8_t, 8 bit value that has the temperature read by the sensor from the Terminal - humidity:
uint8_t, 8 bit positive value that has the humidity read by the sensor from the Terminal
Parameters:
- gateway_serial:
uint64_t, 64 bit positive value
Payload example: 6,1,-83,74,22,68
6: Terminal identifier1: Terminal firmware version-83: Signal strength received by the Gateway from the Terminal74: Terminal battery percentage22: Temperature read in ºC68: Humidity read in %
Function: Standalone current online status
Topic: environment/sensors_async_sad/v0/{serial}/up/lwt
Payload: 0 or 1
Parameters:
- serial:
char*, string 12 characters
Function: Standalone current firmware version
Topic: environment/sensors_async_sad/v0/{serial}/up/version
Payload: uint16_t, positive integer value
Parameters:
- serial:
char*, string 12 characters
NOTE: This topic is not final, might be changed/removed later in development
Function: Identify the type of standalone system
Topic: environment/sensors_async_sad/v0/{serial}/up/type
Payload: char*, name of the standalone type
Parameters:
- serial:
char*, string 12 characters
Function: Standalone current battery percentage status
Topic: environment/sensors_async_sad/v0/{serial}/up/battery
Payload: int, current battery percentage
Parameters:
- serial:
char*, string 12 characters
Function: Standalone lux sensor current value
Topic: environment/sensors_async_sad/v0/{serial}/up/lux/{sensor_idx}
Payload: int, light value in lux
Parameters:
- serial:
char*, string 12 characters - sensor_idx:
int, sensor index in the same sensor type, see sensor_idx table
Function: Standalone temperature sensor current value
Topic: environment/sensors_async_sad/v0/{serial}/up/temperature/{sensor_idx}
Payload: int, temperature in celcius (ºC)
Parameters:
- serial:
char*, string 12 characters - sensor_idx:
int, sensor index in the same sensor type, see sensor_idx table
Function: Standalone humidity sensor current value
Topic: environment/sensors_async_sad/v0/{serial}/up/humidity/{sensor_idx}
Payload: int, humidity in percentage (%)
Parameters:
- serial:
char*, string 12 characters - sensor_idx:
int, sensor index in the same sensor type, see sensor_idx table
| Standalone Type | Sensor Topic | sensor_idx | Sensor Description |
|---|---|---|---|
| SprigLabs | Lux | 0 | Light |
| SprigLabs | Temperature | 0 | Ambient Temperature |
| SprigLabs | Humidity | 0 | Ambient Humidity |
| SprigLabs | Humidity | 1 | Soil Humidity |
- Gateway:
- encrypt credentials
- admin topic to ask gateway some debug information
- into topic to ask gateway for statistics like uptime, bytes sent/received, etc
- Standalone:
- maybe??? by not using LoRa and using WiFi, with the cost of more battery usage, but for home use might be fine
- Common features:
- WiFi AP that is active on reset button press, that runs a HTTP web server tht provides a configuration page, possible features:
- config: credentials
- ping nearby gateways and show then on a list with their signal quality
- factory reset
- WiFi AP that is active on reset button press, that runs a HTTP web server tht provides a configuration page, possible features: