Detect ESP8266 Node

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.

Thank you,

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.

1 Like

I’ll give a try tonight. Thanks for the hint.

Do I need to subscribe to “esp_111/available” before I publish ?

I am not sure I understand the question.

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.

Thanks a lot for the explanation. I was playing with nodeMCU, but I’ll try your code.