Share My Creation an esp8266 making MQTT gateway between rfbridge MQTT client and mobile MQTT client

candide

Member
Licensed User
SOS_bridge-2.jpg


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
 

Attachments

candide

Member
Licensed User
new version ed2
this new version is a real Gateway compatible with all MQTT sources, this application don't modify messages.
provisioning is done with a standard navigator connected on AP IP for first time and on IP of ESP when it is connected to network

process with this gateway is this one:
MQTT client (rfbridge in my case)at origin of messages will publish:
"Topic="tele/rfbridge/RESULT "Payload="{"Time":"2020-04-03T11:51:04","RfReceived":{"Sync":11410,"Low":340,"High":1070,"Data":"F17979","RfKey":"None"}}
This application will store this message and is waiting for mobile request (30 messages max [0<29] in 3400bytes max)

Mobile will send a request in this format:
"Topic="cmnd/rfgate "Payload="request messages from Mobile [ 0 ]
[ 0 ] is mobile number used to answer only at this mobile only
answer to this mobile is in this format:
"Topic="tele/rfgate/RESULT0 "payload="{"Time":"2020-04-03T11:50:53","RfReceived":{"Sync":11260,"Low":340,"High":1070,"Data":"897D79","RfKey":"None"}}
and all message received but not sent will be sent each 100ms
if no message, this applicaton answer "no new message"

mobile can ask for rfgate status:
"Topic="cmnd/rfgate "Payload="reset alarm from Mobile [ 0 ]
this application will provide status of audit of MQTT client link RF_OK or RF_NOK + status of stack and available memory
"Topic="tele/rfgate/RESULT0 "payload="rf_OK Available RAM=38232 Stack level=0254

with a pooling by mobile based on a period of 1mn or more, 30message is enough, but it can be increased if needed.
Objective of this gateway is to give an option to be able to have application on a mobile based on MQTT client running only a few seconds on a period of 1mn or more, to preserve battery drain.
 

Attachments

Top