I have a ESP8266 running nodemcu + Ubuntu as OpenHab server & MQTT broker.
My question is how does OpenHab detect the ESP8266 is responding or not.
Even when I remove power to my ESP8266, and when I hit on the OpenHab toggle switch ,it toggles without any errors. How can I show a massage or at least not get the toggle action, when the ESP8266 is not responding or powered down.
I have not figured out how to disable toggle switches yet.
I do have an āindicatorā of esp8266 node available status.
demo.items
Number Available_111 "Node Available [%.0f node]" (Sensors) {mqtt="<[broker:esp_111/available:state:default]"}
demo.sitemap
Text item=Available_111 icon=āshieldā
My esp8266 program sends a payload of ā1ā on the topic of /available during broker connection sequence.
I set the MQTT LWT parameter to send a payload of ā0ā on the topic of /available when the broker loses connection with the node.
The last will and testament function of MQTT has worked every time for me.
I have seven esp8266 nodes currently in use. I hardcode a different static TCP/IP address in each esp8266 node. Static IP addresses connect to the router a little faster on power-up and make debugging the MQTT traffic not too horrible.
The esp8266 nodes know nothing of openHAB and openHAB knows nothing about the nodes. Both are only communicating with the mosquitto MQTT broker.
It is up to you to define topics and messages that make sense to you and fit your application.
The topic of āesp_111/availableā is unique to my setup. The āesp_111ā is my top level topic for node 192.168.1.111. I publish from the esp8266 with this top level topic for openHAB to parse which node a message came from.
To keep things simple, I use āopenHABā as my top level topic when publishing from openHAB.
For instance, āopenHAB/esp_111/led4 ONā would be the topic and message I send from openHAB to turn on led 4 of the node at address 192.168.1.111. The topic and message names you choose are totally up to you.
As a direct answer to your question, yes, subscribe to āesp_111/availableā in openHAB items to read the āavailableā topic message value from the esp8266 node through the mosquitto broker.
I assume you are using the LUA firmware. This is my example program for the ESP8266 Arduino compiler. Some nodes have been running over a month with no resets or errors.