Check if the device is online or offline

Hello,

I am new to openhab and I have a very important question about how I can detect if the remote device is actually connected.

For example, I have an esp32 that sends some data but not at a constant rate, i.e. it sends data only if the sensor detects a signal that is not stable in time.

In the Things tab, I can see the online status, but it does not represent the status of the esp32…i.e. if it is actually connected to the wireless network of the space.

How can I check if the remote device (esp32) is actually connected so that I have an indication in the tab that it is online or offline??

Thanks!

My suggestion is to start with openHAB Network binding.

You’ve possibility to

  • ping or check for open TCP ports
  • channels showing online status, latency and lastseen

I use it personally to check the Smartphone connections in my network as kind of presence detection.

Okay, I installed the “network binding” and selected “network device with running service”.

I also use mqtt broker with these parameters

Ιn the “hostname” field what should I put?
The IP address is not fixed.

In the port field, should I put 1883 and in the MAC Address field, the one that ESP32 has?

Could you help me?

Same config as MQTT Broker => hostname and port.

But if you have already MQTT Broker thing you don’t need an additional Network Device to check access.
As soon as the mqtt hostname isn’t reachable anymore or the mqtt service isn’t running anymore (for whatever reason) the thing will go OFFLINE.

That will show when the MQTT Broker goes offline but not when the ESP32 goes offline.

@Thanos, how is this ESP32 connected to OH? If it’s via MQTT you can configure the ESP32 to publish a Last Will and Testament (LWT) message. Then the Generic MQTT Thing can be configured to look for that message and set the Thing as OFFLINE when LWT message is present.

Usually I’ll configure the device to publish ONLINE retained when it comes online to a status topic and then OFFLINE retained as the LWT message to the same topic. If the MQTT Broker ever determines that the ESP32 goes offline (because it failes to respond to a heartbeat message) it will publish the LWT message.

I don’t know what you are running on the ESP32 so I can’t tell you how to do that but all the open source firmwares and MQTT libraries support LWT.

An example:

UID: mqtt:topic:mosquitto:cerberos_sensor_reporter
label: cerberos sensor_reporter
thingTypeUID: mqtt:topic
configuration:
  payloadNotAvailable: OFFLINE
  availabilityTopic: sensor_reporter/cerberos/status
  payloadAvailable: ONLINE
bridgeUID: mqtt:broker:broker
location: Garage
channels:
  - id: garagedoor1
...

This lets you track the online status of individual Things.

Unless something has changed fairly recently that’s not how the Network binding works. There is a Channel you can link to a Switch Item which will get set to ON or OFF depending on whether the device responds to the pings. But the Network Thing itself doesn’t change status.

@Thanos, you can still use the Network binding for your ESP32. You’d put the IP address of the ESP32 into the hostname or IP. You can leave the port blank unless you happen to know that the ESP32 is actively listening on a specific port. Then link a Switch Item to the Online Status Channel and that Switch Item will be ON when the ESP32 responds to pings and OFF when it fails to respond to pings.