MQTT network with ESP8266

It’s possible to generate a network of ESP8266 and ESP32 using the MQTT protocol without using a RaspberryPI such as a broker.

On a ESP8266 is installed a micro broker called uMQTT-broker:https://github.com/martin-ger/esp_wifi_repeater/tree/uMQTT_broker

UPDATE=> A new version has been developed https://github.com/martin-ger/esp_mqtt with a dedicated Git.

This node could be considered the Master or the Server and it’s called Broker in the MQTT protocol.
The Server node is a Access Point (AP) with address 192.168.4.1 but also it is able to connect to a local Wifi network as a Station (STA).
The Server node shares together the MQTT messagges coming from the 2 networks.

The precompiled binaries are available at:
https://github.com/martin-ger/esp_wifi_repeater/tree/uMQTT_broker/firmware
They can be flashed with:
esptool.py --port /dev/ttyUSB0 write_flash -fs 32m 0x00000 0x00000.bin 0x10000 0x10000.bin
For ESP-01:
esptool.py --port /dev/ttyUSB0 write_flash -fs 8m 0x00000 0x00000.bin 0x10000 0x10000.bin

The Server node could be configurated by the UART console or a telnet connection:
nc 192.168.4.1 7777
or using the local wifi network:
nc 192.168.xxx.yyy 7777

When the connection is started sending “help” is possible to see all the commands to log or set the server.
More details are available at:
https://github.com/martin-ger/esp_wifi_repeater/blob/master/README.md#usage

A MQTT client for ESP8266 is:
https://github.com/256dpi/arduino-mqtt
The MQTT library for Arduino IDE is based on the Eclipse Paho projects

Another MQTT client for ESP8266 is:
https://github.com/knolleary/pubsubclient
http://pubsubclient.knolleary.net/
The MQTT clients uses the MQTT V3.1.1

To test the MQTT broker on the PC I suggest MQTT-Spy GUI:
https://github.com/eclipse/paho.mqtt-spy/wiki

A more complex system could be built using a RaspberryPI (RPI) where is installed the Monsquitto MQTT broker:
https://github.com/mqtt/mqtt.github.io/wiki
Some instruction how to install Monsquitto on RPI:
https://oshlab.com/install-mqtt-mosquitto-raspberry-pi/
Node-Red could run inside the RPI
Node-Red manages the MQTT messagges and generate actions between the IoT objects (RPI, ESP8266s. ESP32s, Arduinos, Telegram Bots..):
https://nodered.org/
http://noderedguide.com/tag/mqtt/

There is MQTT broker for Node-Red:
https://flows.nodered.org/node/node-red-contrib-mqtt-broker

Annunci

Esempi Arduino e ESP8266

Ho aggiornato il mio repository GitHub con esempi per Arduino e ESP8266

 

Si consiglia la lettura del seguente esempio:

ESP8266 , DS1820, SPIFFS, Gauge con ArduinoIDE

Questo esempio legge la temperatura da un termometro DS1820.

Utilizza la libreria SPIFFS per salvare le pagine nella flash memory del ESP.

La pagina è aggiornata dinamicamente tramite AJAX e XML.

La temperatura è mostrata nella pagina internet del server ESP su un display (gauge) scritto in Javascript.

Arduino_IDE_Browser_Gauge

GPS Tracker

GPS_TrackerHo sviluppato una semplice App per Android per salvare le coordinante GPS su un file txt.

E’ necessario creare nel dispositivo Android la cartella /GPS dove verranno salvati i file txt. Il file txt di default è GPS.txt. Ogni nuovo punto viene aggiunto a questo file.

La struttura del file txt è:

posizione;latitudine;longitudine;altezza

Consiglio di inserire il nome nel campo posizione in modo da riconoscere quel punto GPS.

Premendo “Aggiorna GPS” bisogna dare il tempo al proprio smartphone o tablet di aggiornare la posizione GPS (ovviamente serve avere il GPS attivo)

Il file d’installazione APK: GPS_Tracker.apk

Il file del progetto App Inventor: GPS_Tracker.aia

Il progetto completo si trova su GitHub