[2.5.0M1] Homie 3.0.1 ESP8266 device OTA issues while connected to OH MQTT embedded broker

I am running OH 2.5.0 M1 on Synology DSM 6.2.2

I have an MQTT Homie 3.0.1 ESP8266 device that is auto discovered and fully functional under OH2.5M1 however I can’t figure how to update the firmware while connected to the embedded broker. When attempting the update using ota_updater.py script I get:

$ python ota_updater.py -l -t "homie/" -i "esp8266-03-gate" fw_gate1.0.2.bin

Connecting to mqtt broker on port 1883
Connected with result code 0
Waiting for device to come online…
Waiting for device info…
Publishing new firmware with checksum 89502ab0c49499ea716dd2a082cf4862
Connected with result code 0
Waiting for device to come online…
Waiting for device info…
Expecting checksum 89502ab0c49499ea716dd2a082cf4862, got fbc10ab433a2cfa2f760b761cb3af2f3, update failed!

And the following error in openhab.log:

[ERROR] [.moquette.spi.impl.ProtocolProcessor] - The MQTT client ID cannot be empty. Username=null
[WARN ] [moquette.spi.impl.SessionsRepository] - Session does not exist. CId=41hDoZWy0pdBGRGavivX65
[WARN ] [moquette.spi.impl.SessionsRepository] - Session does not exist. CId=41hDoZWy0pdBGRGavivX65
[ERROR] [quette.server.netty.NettyMQTTHandler] - Unexpected exception while processing MQTT message.
Closing Netty channel. CId=41hDoZWy0pdBGRGavivX65
java.lang.NullPointerException: null

I’ve tried adding “MQTTembedded” ID using the –u option but that didn’t change anything.

The update is working fine using the same script and firmware when my device is connected to an external broker (running on my Macbook).

Any Idea on how to resolve this issue?

The error is complaining that you didn’t supply a client ID in the connection. I’m going to guess it is the ota_updater.py script that this error is coming from. When an MQTT client connects to a broker, it supplies a client ID. No two clients with the same ID can connect to the broker at the same time. This is not the user ID which is used to authenticate with the broker.

I’m going to guess that your external broker allows connections with a client ID and the embedded broker does not. I believe that the standard strongly implies that a client ID should be supplied but I can’t find where I read that right now (i.e. I could be wrong).

So you would wither need to modify your script to supply a client ID or move to a different broker.

Thanks for your reply Rich.

First please note that I am novice with OH and programming.
While I understand how the basics work, I am easily lost in advanced coding jargons.

From what I understand the oat-updater.py script from the github homieiot/homie-esp8266 repository is using paho-mqtt as a client to connect to the OH broker. According to the paho-mqtt project description if the client_id is zero length or none, then one is randomly generated. I believe that the Cid=41hDoZWy0pdBGRGavivX65 from the openhab.log above is the id generated by the client.

My guess is that the paho client needs to be somehow pre registered with the OH broker first in order for the session to be processed, but how?

This thread on github for a similar third party script that connects to openHAB’s internal MQTT broker is illuminating.

It would see if you update the paho library in the script or supply a client ID in the line that creates the MQTT Client in the script it should work. The problem is with the paho library used by the script/installed on your machine.

I was already using paho 1.4.0.
I’ve now added the client_id to the script.
Although I don’t get the username=null error anymore, the rest of the log look the same as before:

[WARN ] [moquette.spi.impl.SessionsRepository] - Session does not exist. CId=my_test_id
[WARN ] [moquette.spi.impl.SessionsRepository] - Session does not exist. CId=my_test_id
[ERROR] [quette.server.netty.NettyMQTTHandler] - Unexpected exception while processing MQTT message. Closing Netty channel. CId=my_test_id
java.lang.NullPointerException: null

Any other idea?

At this point the best I can offer is to switch to an external broker instead.

To temporarily connect to a different broker for the occasional firmware update is easy enough.

I will continue to troubleshoot to at least make sure that this error is not caused by my setup or code.

Thank you for your help.

If you find it’s a problem with the embedded broker you can file an issue at the openhab2-addons repo on GitHub.