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


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

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 ( 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 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


    6.6 KB · Views: 270


Active 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.


    7.9 KB · Views: 245


Licensed User
Longtime User
Hi Candide ,
Is your example applicable to ESP32?
I am trying to setup configuration to "send an html page at connexion" then " navigator send a get to provide answer "
same you have done in your example.



Active Member
Licensed User
hi Viriato
example working on ESP32 ? i don't know, i don't use ESP32

after to have "GET" working on ESP8266, we need good size of buffer Astream.MaxBufferSize and a good size of stack

for debuging i added a view on message sent back by navigator, i added reception buffer in log :Log("startB=",Buffer,"=endB") and a view on stack and memory: Log("start server memory=", AvailableRAM) / Log("stack :",StackBufferUsage)
- if stack is too small i have crash
- if buffer is too small i don't have full page in one message and i cannot extract parameters.

with a good configuration, it is working on ESP8266... i don't know more.