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
- LILYGO / TTGO LoRa32 Display
- version used during developemnt: T3_V1.6.1
- DHT11
- Digital Humidity Temperature sensor
- Battery
- 18650 Li-Ion
- LILYGO / TTGO LoRa32 Display
- version used during developemnt: T3_V1.6.1
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 teh 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 %
- Terminal:
- sleep function, duration might not be precise since board does not have RTC
- wake up on a button press and display for a short amount of time the current sensor data, in the build in display
- 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: