sidddy / flora

ESP32 BLE client for Xiaomi Mi Plant sensors
MIT License
190 stars 71 forks source link

MQTT gives socket error #16

Closed pedrogense closed 5 years ago

pedrogense commented 5 years ago

Im having this error in my mosquitto broker on home assistant

1543960126: New client connected from 192.168.1.61 as xiaomiflora-client (c1, k15, u'peke'). 1543960148: Client xiaomiflora-client has exceeded timeout, disconnecting. 1543960148: Socket error on client xiaomiflora-client, disconnecting.

My config: // sleep between to runs in seconds

define SLEEP_DURATION 60 * 60

// emergency hibernate countdown in seconds

define EMERGENCY_HIBERNATE 1 * 60

// how often should the battery be read - in run count

define BATTERY_INTERVAL 2

// how often should a device be retried in a run when something fails

define RETRY 5

and for mqtt: const int MQTT_RETRY_WAIT = 5000;

Can someone point me in the right direction

plckr commented 5 years ago

I'm having the same problem, did you fix that?

plckr commented 5 years ago

nevermind, restart the esp32 and worked again

sidddy commented 5 years ago

@pedrogense: Do these messages actually have any functional impact or do you still see the measurements? It looks to me like the ESP32 is going to deep sleep and mosquitto eventually complains about a timeout. We could properly log off from mosquitto before going to sleep, but that would potentially waste precious battery power...

indy55 commented 5 years ago

I am also experiencing the same issue. Only changes to config are MACS for sensors, WIFI credentials and MQTT credentials.

1550212766: New connection from 3.14.1.191 on port 1883. 1550212766: New client connected from 3.14.1.191 as miflora-client (c1, k15, u''). 1550212766: Sending CONNACK to miflora-client (0, 0) 1550212787: Client miflora-client has exceeded timeout, disconnecting. 1550212787: Socket error on client miflora-client, disconnecting.

No data from the sensors is published to MQTT.

PhipsSti commented 5 years ago

Problem might be the wrong order of two lines of code. Wifi gets disconnected before the mqtt client is disconnected. Just have a look at the lines 366 and 367

Didn't test it so far. Will test it tomorrow on my own.

pedrogense commented 5 years ago

Let me know what comes out of it.

PhipsSti commented 5 years ago

Seems to only partly fix the issue. I will debug the problem a bit more in detail.

PhipsSti commented 5 years ago

Did some debugging. Seems that the communication to the flora-devices gets stuck quite often. This causes that the forced hibernate triggers and nothing is being disconnected gracefully. 1 successful out of 15 reads for both configured floras is not such a good rate.

pedrogense commented 5 years ago

Thats not a good rate, i can see that it not always updates, i have mutiple esp's on different levels in my house. Do you think you can fix it?

PhipsSti commented 5 years ago

I am not sure. At the moment I am thinking about starting a new project (with a bit of a different idea) for this task. But before doing so I will dig a bit around and give it one last try.

PhipsSti commented 5 years ago

Just started my own implementation and noticed that I am facing the same problem. Reason seems to be the concurrent connection to wifi. So if we want to have successful reads we have to change the concept a bit.

pedrogense commented 5 years ago

Cannot it be connect tru wifi all the time?

PhipsSti commented 5 years ago

In case of an active connection to WiFi the ESP will quite often get stuck during reading the Floras. This leads to the forced hibernate and results in the harsh disconnect from MQTT and WiFi.

PhipsSti commented 5 years ago

I also organized another type of ESP32 and tried it. Also no success. => I am stopping the active investigations here and switch to my alternative implementation.

pedrogense commented 5 years ago

I already stopped to use this, i recently found esphome integration and it works how it looks for now.