The HobbyIot NET Gateway is built around a ESP8266 NodeMCU and MRF24J40MA radio module. They are connected together via SPI interface. The Gateway is connected to the MQTT Broker (Raspberry Pi running Mosquitto for example) over the WiFi interface of the ESP8266 NodeMCU. The sensor side of the bridge communicates with the end devices over the 2.4 GHz 802.15.4 interface via MRF24J40MA running the MQTT-SN protocol.
The code is written in Arduino environment and is available on GitHub under Open source MIT License.
After Power on or reset applied to the system both MQTT and MQTT-SN sides are first initialized. The MQTT setup includes a WiFi setup and MQTT connection procedure. The MQTT-SN setup starts with 802.15.4 module and connection parameters set up.
The state diagram describes the MQTT-SN operation of the Bridge including message reception, message processing and data forwarding to and from the MQTT side of the bridge.
Once the system is initialized the Gateway is waiting for a message. The main routine (bold arrows) waits for a message to receive. It also checks the state of the modes in the ConnTable.
The state diagram shows the Sensor network side of the Algorithm operation.
In case of messages received on the MQTT-SN side it is first classified according to its type.
In case of valid message (implemented message) a certain actions are activated according the message type:
In case of a CONN message the corresponding node is added to the ConnTable and a CONNACK is sent back; If the node is already in the connection table a CONNACK is just sent back.
In case of a PINGREQ message a PINGRESP is transmitted back the the ping requesting node. The corresponding time-out timer is reset;
In case of SUB message the corresponding topic is added to the SubTable and a SUBACK is transmitted back to the requesting node;
In case of PUB message the corresponding topic and data are transmitted to the MQTT side; If the PUB comes from the MQTT the data is forwarded to the corresponding node (its address should be contained within the message)
In case of invalid (or still not implemented one) the system goes back to wait for a valid message.
The algorithm also periodically checks the ConnTable for time-outed nodes and removes them from the table.
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