Cannot register a second device via MQTT/Homie

  • Platform information:
    • Hardware: Raspberry Pi 3 Model B Rev 1.2
    • OS: Raspbian GNU/Linux 10 (buster)
    • Java Runtime Environment: OpenJDK Runtime Environment (Zulu Embedded 8.25.0.76-linux-aarch32hf) (build 1.8.0_152-b76)
    • openHAB version: 2.5.7-1 (as reported by dpkg)
  • Issue of the topic:

I have successfully added one device from MQTT to OpenHAB using the Homie convention:

Now I’m trying to add another device the exact same way, and it doesn’t work. I tried rebooting many times the devices and openhab, but I always get two types of errors back:

  • either Did not receive mandatory topic value: homie/wifi-kit-8/$name
  • or Did not receive mandatory topic value: homie/wifi-kit-8/$state

I’m using mosquitto as a MQTT broker which is installed on the same Raspberry Pi as OpenHAB

pi@openhab:/var/log/mosquitto $ mosquitto_sub -v -t "#"
homie/envirophat/$homie 4.0.0
homie/envirophat/$name MQTT envirophat agent
homie/envirophat/$state sleeping
homie/envirophat/$nodes rpi,bmp280
homie/envirophat/rpi/$name Raspberry PI Zero
homie/envirophat/rpi/$type rpiz
homie/envirophat/rpi/$properties temperature
homie/envirophat/rpi/temperature 31.48
homie/envirophat/rpi/temperature/$name Temperature
homie/envirophat/rpi/temperature/$unit °C
homie/envirophat/rpi/temperature/$datatype float
homie/envirophat/bmp280/$name BMP280 on Envirophat
homie/envirophat/bmp280/$type bmp280
homie/envirophat/bmp280/$properties temperature,pressure
homie/envirophat/bmp280/temperature 19.86
homie/envirophat/bmp280/temperature/$name Temperature
homie/envirophat/bmp280/temperature/$unit °C
homie/envirophat/bmp280/temperature/$datatype float
homie/envirophat/bmp280/pressure 988.44
homie/envirophat/bmp280/pressure/$name Pressure
homie/envirophat/bmp280/pressure/$unit hPa
homie/envirophat/bmp280/pressure/$datatype float
homie/wifi-kit-8/$homie 4.0.0
homie/wifi-kit-8/$name MQTT ESP8266 agent
homie/wifi-kit-8/$nodes bme280
homie/wifi-kit-8/bme280/$name BME280 via ESP8266EX
homie/wifi-kit-8/bme280/$type bme280
homie/wifi-kit-8/bme280/$properties temperature,pressure,humidity
homie/wifi-kit-8/bme280/temperature 21.40
homie/wifi-kit-8/bme280/temperature/$name Temperature
homie/wifi-kit-8/bme280/temperature/$unit °C
homie/wifi-kit-8/bme280/temperature/$datatype float
homie/wifi-kit-8/bme280/pressure 988.04
homie/wifi-kit-8/bme280/pressure/$name Pressure
homie/wifi-kit-8/bme280/pressure/$unit hPa
homie/wifi-kit-8/bme280/pressure/$datatype float
homie/wifi-kit-8/bme280/humidity 52.01
homie/wifi-kit-8/bme280/humidity/$name Humidity
homie/wifi-kit-8/bme280/humidity/$unit %
homie/wifi-kit-8/bme280/humidity/$datatype float
homie/wifi-kit-8/$state sleeping

As you can see both devices are sending the same values to MQTT using the Homie convention.

Here are the latest logs from openhab-cli:

==> /var/log/openhab2/openhab.log <==
2020-08-25 21:47:31.617 [WARN ] [.incoming.MqttIncomingPublishService] - No publish flow registered for MqttStatefulPublish{stateless=MqttPublish{topic=homie/wifi-kit-8/$name, payload=18byte, qos=AT_MOST_ONCE, retain=false}, packetIdentifier=-1, dup=false, topicAlias=0, subscriptionIdentifiers=[]}.

==> /var/log/openhab2/events.log <==
2020-08-25 21:47:32.364 [home.event.InboxAddedEvent] - Discovery Result with UID 'mqtt:homie300:9a1d561c:wifi-kit-8' has been added.

==> /var/log/openhab2/openhab.log <==
2020-08-25 21:47:32.363 [INFO ] [g.discovery.internal.PersistentInbox] - Added new thing 'mqtt:homie300:9a1d561c:wifi-kit-8' to inbox.

==> /var/log/openhab2/events.log <==
2020-08-25 21:47:42.986 [me.event.InboxRemovedEvent] - Discovery Result with UID 'mqtt:homie300:9a1d561c:wifi-kit-8' has been removed.
2020-08-25 21:47:43.000 [hingStatusInfoChangedEvent] - 'mqtt:homie300:9a1d561c:wifi-kit-8' changed from UNINITIALIZED to INITIALIZING
2020-08-25 21:47:43.549 [hingStatusInfoChangedEvent] - 'mqtt:homie300:9a1d561c:wifi-kit-8' changed from INITIALIZING to OFFLINE (COMMUNICATION_ERROR): java.lang.Exception: Did not receive mandatory topic value: homie/wifi-kit-8/$name

Does it have anything to do with the log entry “No publish flow registered for MqttStatefulPublish”?

Am I doing anything stupid?

Complete stab in the dark: is something choking on the hyphens in the name of your device? What happens if you call it wifikit8?

2 Likes

I can’t believe I spent 3 days trying to work that out and it was as simple as that!

A zillion thank you :smile:

Should I file a bug in GitHub or something?

Ah, I feel for you! I’ve been there many times!

You could file an issue, yes. I wondered whether hyphens weren’t allowed within MQTT topics, but couldn’t find anything to back that up with a quick search.

It is mentioned in the homie specification:
https://homieiot.github.io/specification/

An MQTT topic consists of one or more topic levels, separated by the slash character ( / ). A topic level ID MAY ONLY contain lowercase letters from a to z , numbers from 0 to 9 as well as the hyphen character ( - ).
A topic level ID MUST NOT start or end with a hyphen ( - ). The special character $ is used and reserved for Homie attributes .

2 Likes

HI @creativeprojects!

I’m glad that your issue has been solved, but I fear that the root problem has not been fixed, as the Homie binding should be compatible with your “device id”.

It seems that you are running openHAB 2.5.7, but could you please upgrade your system to the latest version (openHAB 2.5.8)? That version includes a fix for a long standing issue: https://github.com/openhab/openhab-addons/issues/7252 (The “Did not receive mandatory topic value: homie/xxx/$name” issue you have seen).

Thanks and if you need help, don’t hesitate to ask :wink:

Best regards,

Aitor

1 Like

Hi,

Actually I didn’t see 2.5.8 was out (I think I checked a few days ago?).
I’ll give it a go and see if it accepts a topic containing hyphens

Thanks :stuck_out_tongue:

Does this mean if my device has a _ it won’t work with homie properly?
I used ESP_xxxxxx as my naming convention for my devices?

It might work with OpenHAB, but the specifications clearly stipulates it shouldn’t contain a _

I would avoid it, because it’s much easier to change things while you’re setting up rather than when discovering a bug months later.

1 Like