The HobbyIot NET sensor node is built around ATmega328p MCU and MRF24J40MA radio module connected together via SPI interface.Temperature and humidity measurement is performed by DHT11 (older versions) or BMP280 (newer versions) connected over single wire interface or I2C. The sensor connects to the Gateway over 2.4 GHz 802.15.4 radio interface using MQTT-SN (MQTT for Sensor Networks) protocol.
The code is written in Arduino environment and is available on GitHub under Open source MIT License.
Once the sensor is powered on it tries to connect to the gateway. A connect message (CONN) is being sent and the sensor waits for connection acknowledge (CONNACK). Once the CONNACK is received the sensor immediately goes to sleep ensuring low power consumption. The CONN message carries the sleep interval value for the sensor so the gateway can fill in it into the connected devices table (ConnTable) to update the timeout data for each connected device.
If no acknowledgement is received the sensor sleeps for a period of time (Connect sleep) and sends a CONN message to the gateway again.
After the sensor is connected to the gateway it sleeps for a predefined portion of time. Since the ATmega328p is able to sleep for a maximum of 8 seconds, an MRF24J40 internal counter is used (timed sleep mode) to wake up the sensor after the predefined sleep period - normally between 10 and 30 minutes. After that period the timer wakes up the radio and generates an interrupt to the ATmega328p to wake up.
A keep alive message (ping request - PINGREQ) is transmitted to the gateway and right after that the radio module is powered off for a while to save power. The temperature and humidity data is read from DHT11 or BMP280. The radio is turned on again and the data is sent to the gateway alongside with the ping response (PINGRESP) reception in the opposite direction and the sensor goes to sleep resetting the timeout counter.
If a PINGRESP is not received the connection timer within the sensor node is decreased. Time out condition is checked and if the time out has been reached (no response from the gateway) the connection is set to lost. The sensor tries to connect again.
In case of magnetic sensor (reed sensor) status change a Reed interrupt is generated. The ATmega328p wakes immediately and sends the magnetic sensor data to the gateway. After a ping exchange the sensor goes to sleep again.
For more information and details, please visit the GitHub repo of the project or connect over the #HobbyIoT Slack channel.
Website: HobbyIoT NET
GitHub: https://github.com/sivanovbg/MQTT-SN_GW_802154_V1
MQTT-SN Specification: http://mqtt.org/new/wp-content/uploads/2009/06/MQTT-SN_spec_v1.2.pdf
Slack: #HobbyIoT