berezhinskiy / ecoflow_exporter

Prometheus exporter for EcoFlow portable power stations
GNU General Public License v3.0
247 stars 45 forks source link

MQTT messages can not get encoded/parsed #77

Open kalle8888 opened 1 week ago

kalle8888 commented 1 week ago

Hi, just to warn you before, I have not clue about MQTT .... nor of PY

Anyway....after found in #34 that my first problem ("message queue is empty") is known and I can bypass it by starting the app in parallel, I get a second error that I could not find under "issues".

Something must go wrong when processing the messages. I would think that a charakter x88 in not understood.

Would you please check the following log and help me. Thank you /Kalle

P.S. I also tried to change the ENV Variable in docker to UTF-8, en_US.UTF-8 and de_DE.UTF-8 but this did not help

Container LOG:

2024-10-13 12:01:30,895 INFO Successfully logged in: xxxxxxxxx 2024-10-13 12:01:30,895 INFO Requesting IoT MQTT credentials https://api.ecoflow.com/iot-auth/app/certification 2024-10-13 12:01:30,943 INFO Successfully extracted account: app-a95e69xxxxxxxxxxxxxxxxxxxxxxxxxxx 2024-10-13 12:01:30,984 INFO Connecting to MQTT Broker mqtt-e.ecoflow.com:8883 using client id ANDROID_Fxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 2024-10-13 12:01:31,031 INFO Subscribed to MQTT topic /app/device/property/HWxxxxxxxxxxxxxxxxxxxx Exception in thread paho-mqtt-client-ANDROID_Fxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx: Traceback (most recent call last): File "/usr/local/lib/python3.12/threading.py", line 1073, in _bootstrap_inner self.run() File "/usr/local/lib/python3.12/threading.py", line 1010, in run self._target(*self._args, self._kwargs) File "/usr/local/lib/python3.12/site-packages/paho/mqtt/client.py", line 4523, in _thread_main self.loop_forever(retry_first_connection=True) File "/usr/local/lib/python3.12/site-packages/paho/mqtt/client.py", line 2297, in loop_forever rc = self._loop(timeout) ^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/paho/mqtt/client.py", line 1686, in _loop rc = self.loop_read() ^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/paho/mqtt/client.py", line 2100, in loop_read rc = self._packet_read() ^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/paho/mqtt/client.py", line 3142, in _packet_read rc = self._packet_handle() ^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/paho/mqtt/client.py", line 3808, in _packet_handle return self._handle_publish() ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/paho/mqtt/client.py", line 4145, in _handle_publish self._handle_on_message(message) File "/usr/local/lib/python3.12/site-packages/paho/mqtt/client.py", line 4501, in _handle_on_message on_message(self, self._userdata, message) File "/ecoflow_exporter.py", line 187, in on_message self.message_queue.put(message.payload.decode("utf-8")) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UnicodeDecodeError: 'utf-8' codec can't decode byte 0x88 in position 4: invalid start byte** 2024-10-13 12:01:41,013 INFO Message queue is empty. Assuming that the device is offline

kalle8888 commented 1 week ago

In the meanwhile I am very sure that the error comes from the DATA itself.

I changed the decode statement to ignore decoding errors by changing the code line to ......message.payload.decode("utf-8",errors="ignore"))

and now the data can not get parsed

the data is shown in the log (I can not copy paste it here, since it can't get displayed, so I have to use a screen shot of the log, opened in an editor)

Failed to parse MQTT payload:

grafik