LordMike / MBW.BlueRiiot2MQTT

Utility to map between Blue Riiots pool API, and Home Assistant MQTT
47 stars 1 forks source link

Socket error on client blueriiot2mqtt, disconnecting #25

Closed youngy00 closed 3 years ago

youngy00 commented 3 years ago

Hi,

I am trying to get the addon running but I am getting the flowing errors in the log.

MBW.BlueRiiot2MQTT Log [08:52:24 INF] Loading extra config file at /data/options.json Unhandled exception. MQTTnet.Exceptions.MqttCommunicationException: The client is not connected. at MQTTnet.Client.MqttClient.ThrowIfNotConnected() at MQTTnet.Client.MqttClient.PublishAsync(MqttApplicationMessage applicationMessage, CancellationToken cancellationToken) at MBW.HassMQTT.Helpers.MqttHelpers.SendValueAsync(IMqttClient mqttClient, String topic, String value, CancellationToken token) at MBW.HassMQTT.CommonServices.AliveAndWill.HassConnectedEntityService.ExecuteAsync(CancellationToken stoppingToken) at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken) at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token) at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token) at MBW.BlueRiiot2MQTT.Program.Main(String[] args) in /src/MBW.BlueRiiot2MQTT/Program.cs:line 40 at MBW.BlueRiiot2MQTT.Program.

(String[] args)

MQTT Log 1599036745: New connection from 172.30.32.1 on port 1883. [INFO] found admin on local database 1599036745: New client connected from 172.30.32.1 as blueriiot2mqtt (p2, c0, k15, u'admin'). 1599036745: Socket error on client blueriiot2mqtt, disconnecting.

Any Ideas? Running from the Add-on store; LordMike's repository.

Cheers, Craig

LordMike commented 3 years ago

Hmm.. which MQTT server are you running?

Does it always do this?

youngy00 commented 3 years ago

Running Mosquitto broker - Home Assistant Add-on - v5.1

Yes, it always does this, have uninstalled Add-on and reinstalled.

LordMike commented 3 years ago

That is weird.. buut, I've noticed some issues with the MQTT library where it will "randomly" disconnect. I'll see if there's an update or whatnot.

It should work, most of the time, as this is all running on localhost ... so there is definitely something on your end too - I'm not sure what.

LordMike commented 3 years ago

There is a race condition in the code that failed, that I'm about to fix.

LordMike commented 3 years ago

I've pushed new code, which will be in the dev tag shortly. I don't know how you can use it from the HASS Addons repositories.. :|

youngy00 commented 3 years ago

Thank you, not sure on how to use dev from the HASS Addons also.

LordMike commented 3 years ago

I've also found some odd behaviour akin to what you see, where the MQTT server disconnects my client. I've traced it to the socket returning a 0 byte read, which MQTTnet interprets as "connection closed" - after which it begins disconnecting.

For some reason, this happens all the time. I'll have to do some packet capture to check if it actually receives an RST packet or not ..

youngy00 commented 3 years ago

HI, just wondering how you are going with this issue.

LordMike commented 3 years ago

I had stalled. I reproduced it with MQTT Net client on my local network, pretty consistently. I ended up as mentioned before, but didn't get around to do a packet capture.

youngy00 commented 3 years ago

Hi,

Sorry to be a pest, but my pool is finally installed\operational.

Any chance on an update, looking at doing some pool automation in HA.

Cheers.

LordMike commented 3 years ago

I'll note that in principal, the software works fine. It's been running for my, and others, pools over the summer period in the north. That it disconnects once in a while from the MQTT server doesn't prevent it from doing work. :)

This is still on my todo - if you want to do investigations, you could perform packet captures to see the traffic between B2M and MQTT. If there is a regular FIN packet, we'll need to find out why it's being sent.

Mike.

barto64 commented 3 years ago

Hi,

Sorry to be a pest, but my pool is finally installed\operational.

Any chance on an update, looking at doing some pool automation in HA.

Cheers.

There are different choices for pool automation in HA, problem though is that it is very dependant of what you had available and what you want to do, I leave you in here a couple for you to take a look.

https://github.com/segalion/raspipool https://github.com/oncleben31/ha-pool_pump

I finally wrote my own one grabbing some ideas from here and there, mainly from raspipool as it manages all pumps (pool & chemical) and I used this great integration for the sensors. With that you get a 90% automation of the pool, I do not have heaters or blind as some other people have.

youngy00 commented 3 years ago

@barto64 Thanks, I will have a look.

youngy00 commented 3 years ago

@LordMike

I got it working, not sure what fixed it in the end (too many changes at once) Uninstalled BlueRiiot2MQTT and Mosquitto broker Tested different MQTT user accounts SSL on, SSL off (have a purchase SSL cert) IP vs domain name reset configs restarted HA lots. rebooted server...

But now it starts without any errors, thank you for you help and for developing this software..

LordMike commented 3 years ago

Huh - that's odd.. It should be a network issue - perhaps the server restarts did something.