SAIC-iSmart-API / saic-home-assistant-addon

SAIC-iSmart-API repository for Home Assistant OS (HASS.IO)
MIT License
58 stars 7 forks source link

gmqtt warning: "Trying write to closed socket" #102

Closed Inarion closed 4 weeks ago

Inarion commented 3 months ago

Hi there,

I'm seeing a repeating warning in the logs, the line looks as follows: 2024-07-07 15:25:40,383 [WARNING ] [TRYING WRITE TO CLOSED SOCKET] - gmqtt.mqtt.protocol For more detail refer to the full log below, taken directly after restarting the addon. The part after [CONNECTION MADE] repeats every 5-6 seconds. Can I do something to get rid of this warning? Does it indicate something going wrong? I'm specifically asking because I'm not seeing the correct values in the mqtt topics, while the MG iSmart app actually displays the correct SOC for once.

2024-07-07 15:25:39,433 [  INFO  ] Logging in to SAIC API - __main__
2024-07-07 15:25:40,018 [  INFO  ] Logged in as my.account@email.provider - __main__
2024-07-07 15:25:40,018 [  INFO  ] Fetching vehicle list - __main__
2024-07-07 15:25:40,168 [  INFO  ] Registering for ['ALARM_TYPE_VEHICLE_FAULT', 'ALARM_TYPE_GEOFENCE', 'ALARM_TYPE_VEHICLE_START'] messages. vin=LXXXX0000XX000000 - __main__
2024-07-07 15:25:40,249 [  INFO  ] Registered for ['ALARM_TYPE_VEHICLE_FAULT', 'ALARM_TYPE_GEOFENCE', 'ALARM_TYPE_VEHICLE_START'] messages. vin=LXXXX0000XX000000 - __main__
2024-07-07 15:25:40,250 [ DEBUG  ] SoC of LXXXX0000XX000000 for charging station will be published over MQTT topic: evcc/loadpoints/1/vehicleSoc - __main__
2024-07-07 15:25:40,284 [  INFO  ] Adding job tentatively -- it will be properly scheduled when the scheduler starts - apscheduler.scheduler
2024-07-07 15:25:40,287 [  INFO  ] [CONNECTION MADE] - gmqtt.mqtt.protocol
2024-07-07 15:25:40,381 [ DEBUG  ] [CMD 0x48] b'TP/1.0 403 Forbidden\r\ncontent-type: text/html\r\ncontent-length: 173\r\n\r\n<html><head><m' - gmqtt
2024-07-07 15:25:40,381 [ DEBUG  ] [RECEIVED PUBACK FOR] 21584 - gmqtt
2024-07-07 15:25:40,381 [ DEBUG  ] FREE MID: 21584 - gmqtt.mqtt.utils
2024-07-07 15:25:40,381 [ DEBUG  ] [REMOVE MESSAGE] 21584 - gmqtt
2024-07-07 15:25:40,382 [ DEBUG  ] [CMD 0x65] b'a charset=utf-8 http-equiv="Content-Language" content="en"/><link rel="stylesheet" type="text/css" href="/error.css"' - gmqtt
2024-07-07 15:25:40,382 [ DEBUG  ] [RECEIVED PUBREL FOR] 24864 - gmqtt
2024-07-07 15:25:40,382 [ DEBUG  ] FREE MID: 24864 - gmqtt.mqtt.utils
2024-07-07 15:25:40,382 [ DEBUG  ] [RECV EMPTY] Connection will be reset automatically. - gmqtt.mqtt.protocol
2024-07-07 15:25:40,382 [  INFO  ] [CONN CLOSE NORMALLY] - gmqtt.mqtt.protocol
2024-07-07 15:25:40,382 [ DEBUG  ] [CMD 0xe0] b'' - gmqtt
2024-07-07 15:25:40,383 [WARNING ] [TRYING WRITE TO CLOSED SOCKET] - gmqtt.mqtt.protocol
2024-07-07 15:25:46,392 [  INFO  ] [CONNECTION MADE] - gmqtt.mqtt.protocol

Are more details needed? Please let me know.

nanomad commented 3 months ago

Looks like your SAIC credentials are wrong, please remove any special characters from the password and try again.

Inarion commented 3 months ago

Thanks for your answer. The password already consists of only alphanumeric characters (in regex it would be matched by [A-Za-z0-9]). Also I organize my passwords with a password manager and only copy + paste them, so no typos can sneak in. The very same password works alright with the MG iSmart app.

I just reapplied the password setting and restarted the addon, but the log still shows the exact same problem.

Is there anything I can do to further debug the problem? (When programming I like to set breakpoints to see more closely what happens when the problem occurs - but I guess that's not quite possible in this case...)

nanomad commented 3 months ago

@Inarion Feel free to reach out to me on telegram and I can debug it for you. My handle is the same as my username here on github

Inarion commented 4 weeks ago

Thanks for your generous offer. I was having doubts about installing telegram on my primary phone, so due to this and the fact that life has been rather busy, I postponed getting back to my issue for quite some time.

Today I had an unforeseen success with an unrelated Home Assistant issue, which got me totally motivated to take a look at the SAIC gateway again. And would you believe it? All this time my MQTT config for the gateway was flawed - it pointed at the port for MQTT over websocket. This seems to have triggered the above errors.

So the solution in my case was: Check, double-check and then check your config again. Fixing the port in MQTT_URI was all that was needed. (I'm sure I had checked that before, but only once...)

Feeling kinda stupid now, but also relieved.