Gateway between esp-now and MQTT using esp-idf.
I was inspired by this.
ESP-NOW can be used with ESP8266/8285, but we cannot use WiFi at the same time.
But with ESP32, we can use ESP-NOW and WiFi at the same time.
This project transfers the data received by ESP-NOW to MQTT.
ESP8266/8285 + battery + ESP-NOW + DeelSpeep enables long-time operation.
This is a comparison of battery consumption between Wifi and ESP-NOW.
This is the measurement result when the DeepSleep interval was 600 seconds.
Two AA batteries will give you about four months of operation.
This is the measurement result when the DeepSleep interval was 60 seconds.
Two AA batteries will give you about one months of operation.

ESP-IDF V5.0 or later.
ESP-IDF V4.4 release branch reached EOL in July 2024.
ESP-IDF V5.1 is required when using ESP32-C6.
- ESP8266/8285.
Some development boards have a Power LED.
Some development boards have a Serail TX signal LED.
They consume battery.
Since the ESP12 has an LED on the module, it is not suitable for battery operation.
Care should be taken when selecting hardware to reduce battery consumption.
Some WeMos D1 Mini clones cannot be started on two AA batteries.
git clone https://github.com/nopnop2002/esp-idf-espnow-gateway
cd esp-idf-espnow-gateway
idf.py set-target {esp32/esp32s2/esp32s3/esp32c2/esp32c3/esp32c6}
idf.py menuconfig
idf.py flash monitor
Set the information of your access point.

Set the information of your MQTT broker.

This project supports TCP,SSL/TLS,WebSocket and WebSocket Secure Port.
-
Using TCP Port.
TCP Port uses the MQTT protocol. -
Using SSL/TLS Port.
SSL/TLS Port uses the MQTTS protocol instead of the MQTT protocol. -
Using WebSocket Port.
WebSocket Port uses the WS protocol instead of the MQTT protocol. -
Using WebSocket Secure Port.
WebSocket Secure Port uses the WSS protocol instead of the MQTT protocol.
Note for using secure port.
The default MQTT server is broker.emqx.io.
If you use a different server, you will need to modify getpem.sh to run.
chmod 777 getpem.sh
./getpem.sh
You can specify your MQTT broker in one of the following ways:
- IP address
192.168.10.20 - mDNS host name
mqtt-broker.local - Fully Qualified Domain Name
broker.emqx.io
You can use this as broker.
https://github.com/nopnop2002/esp-idf-mqtt-broker
This project supports MQTT Protocol V3.1.1/V5.

Specifies the username and password if the server requires a password when connecting.
Here's how to install and secure the Mosquitto MQTT messaging broker on Debian 10.

There is two example.
Follow this page to change your settings.
-
espnow-controller
Publish every 10 seconds.
I used broker.emqx.io as MQTT broker.$ mosquitto_sub -v -h broker.emqx.io -p 1883 -t "/mqtt/espnow" | ts "%y/%m/%d %H:%M:%S" 21/08/11 16:52:25 /mqtt/espnow Hello 10001 2968 21/08/11 16:52:35 /mqtt/espnow Hello 20002 2966 21/08/11 16:52:45 /mqtt/espnow Hello 30003 2966 21/08/11 16:52:55 /mqtt/espnow Hello 40004 2965 21/08/11 16:53:05 /mqtt/espnow Hello 50005 2966 21/08/11 16:53:15 /mqtt/espnow Hello 60006 2965 -
espnow-controller-deepSleep
Wake up from Deep Sleep every 60 seconds and publish.
You need to connect reset pin and GPIO16 with a wire cable.
I used broker.emqx.io as MQTT broker.$ mosquitto_sub -v -h broker.emqx.io -p 1883 -t "/mqtt/espnow" | ts "%y/%m/%d %H:%M:%S" 21/08/11 16:40:32 /mqtt/espnow Hello 66 2904 21/08/11 16:41:30 /mqtt/espnow Hello 68 2908 21/08/11 16:42:29 /mqtt/espnow Hello 67 2908 21/08/11 16:43:29 /mqtt/espnow Hello 67 2907 21/08/11 16:44:28 /mqtt/espnow Hello 68 2911 21/08/11 16:45:27 /mqtt/espnow Hello 67 2906
ESPNOW allows one-to-many communication.
This is logging when two ESP8266s are operated at the same time.
23/11/15 16:17:55 /mqtt/espnow Hello 410041 2965 --> This is from ESP8266 #1
23/11/15 16:18:04 /mqtt/espnow Hello 10001 2981 --> This is from ESP8266 #2
23/11/15 16:18:05 /mqtt/espnow Hello 420042 2965
23/11/15 16:18:14 /mqtt/espnow Hello 20002 2976
23/11/15 16:18:15 /mqtt/espnow Hello 430043 2965
23/11/15 16:18:24 /mqtt/espnow Hello 30003 2976
23/11/15 16:18:25 /mqtt/espnow Hello 440044 2965
23/11/15 16:18:34 /mqtt/espnow Hello 40004 2976
23/11/15 16:18:35 /mqtt/espnow Hello 450045 2965
23/11/15 16:18:44 /mqtt/espnow Hello 50005 2973
23/11/15 16:18:45 /mqtt/espnow Hello 460046 2965
23/11/15 16:18:54 /mqtt/espnow Hello 60006 2977
23/11/15 16:18:55 /mqtt/espnow Hello 470047 2965
23/11/15 16:19:04 /mqtt/espnow Hello 70007 2974
23/11/15 16:19:05 /mqtt/espnow Hello 480048 2965
23/11/15 16:19:14 /mqtt/espnow Hello 80008 2976
23/11/15 16:19:15 /mqtt/espnow Hello 490049 2965
23/11/15 16:19:24 /mqtt/espnow Hello 90009 2972
23/11/15 16:19:25 /mqtt/espnow Hello 500050 2965
23/11/15 16:19:34 /mqtt/espnow Hello 100010 2973

