![esp8266 firmware mqtt esp8266 firmware mqtt](https://cdn.thenewstack.io/media/2019/03/3c5dfe47-nodemcu-pir-mqtt.png)
#Esp8266 firmware mqtt code#
The code I create for the device is invoked when Homie receives above publish, and it can then do something, e.g. The homie-esp8266 framework also listens for messages: for example, I can switch a relay I have connected to a Wemos-D1 with the following command: mosquitto_pub -t 'sensors/homie/cf3a07e0/relay/on/set' -m true Then the device starts publishing a temperature and whatever other sensor data I wish to make available from the device. $online indicates whether the device is currently alive, $name is a description I initially assign to the device, $signal is an indication of WiFi coverage as seen by the microcontroller, etc. $nodes inform the consumer about the type of endpoints I’ve made available on the device. Sensors/homie/cf3a07e0/temperature/degrees 23.38 Sensors/homie/cf3a07e0/temperature/unit c Sensors/homie/cf3a07e0/$name Livingroom bookshelf So, as an example, when one of my sensors launches, it will publish these retained MQTT messages: sensors/homie/cf3a07e0/$nodes light:light,temperature:temperature,relay:relay Martin has obviously carefully thought about how a device should interact with its environment, and the code reflects this. It’s basically a small framework which couples the ESP8266 to MQTT and provides automatic connection/reconnection handling, JSON configuration, an optional Web UI to configure the microcontroller which starts up in Access Point mode initially, and Over-The-Air support for updating the code I create for the ESP8266. I stumbled over a project called homie-esp8266 created by Marvin Roger. These little microcontrollers just work, but what is a bit of a chore is having to invent boilerplate code which enables reconnection, reboot on error, etc.
#Esp8266 firmware mqtt install#
I’ve settled on using an environment I’m more or less comfortable with, namely the Arduino for ESP8266 firmware which is trivial to install through the Arduino IDE. The NodeMCU can be flashed with firmware which supports the Lua programming language (or even BASIC I hear). (And while waiting you find that the adorable Wemos-D1 has a boat-load of shields which you should also have ordered … :-)īoth of these are based on the ESP8266, and as such they have on-board WiFi. I have not made a mistake on the price tags they even include postage and handling from China. However, using a Photon as, say, a simple temperature sensor is quite expensive at over EUR 23.00 when purchased here.ĭirt cheap in comparison is one of the ESP family of microcontrollers and development boards, and I ordered a few so-called NodeMCU dev kits (right in photo at EUR 3.89 a piece) and Wemos D1 (center, at EUR 3.63 per unit). Two of the features which most impressed me of the Particle Photon were its built-in WiFi, and the possibility of updating the device over the air (OTA).