this example of MQTT client on ESP8266 is built to make a gateway between a rfbridge sonoff with tasmota and mobiles with a MQTT client, to monitor 2 SOS buttons
MQTT broker is cloudMQTT.com
Global configuration
- a start we have 2 SOS buttons working in 433mhz and sending message when button is pressed
- rfbridge is interface between 433Mhz and MQTT broker (cloudMQTT.com in our case)
- rfbridge is using tamosta soft to be compatible with MQTT
- at reception of 433mhz message, rfbridge is sending message to MQTT broker and MQTT broker is sending to esp8266 in real time, (each time we have detection of 433mhz SOS alarme)
- esp will store inputs of alarms until a request from mobile (number of alarmes, time of first, time of last and SOS key)
- mobile will request periodically alarms status to ESP8266 (on mobile, we have cycle of MQTT client active 15sec and sleeping 1mn or more)
a client MQTT on Android running full time take more than 30% of battery, but a service running 15sec and sleeping 1mn take less of 3% of batterie
- ESP is providing in a MQTT message alarms status to mobile at request
- we can have several mobiles monitoring alarms from SOS button and sending messages to ESP8266
- rfbridge, esp8266 and mobiles are connected to cloudMQTT.com because it is free until 5 connexions and it is enougth for my configuration.
on esp side :
we have a wifi server active to make provisioning from a basic navigator
=> esp send an html page at connexion
=> navigator send a get to provide answer
first provisioning is done in AP mode but after as soon as wifi is UP, AP is down and only connexion on IP of esp is possible
we can make provisioning of Wifi, MQTT, subscriptions, Topics, key of SOS button
we can erase eeprom
at erase request, esp send back ram ans stack, just to check memory leak
esp make periodic audit of rfbridge link and status is sent to mobile
alarm status is erased at request of mobile
this example is not perfect on programming point of view, but it is a global and working example and it can help beginners like me