I am having my main program subscribe to a topic that will receive messages every 15 seconds. I have my connection being made, and then foreverloop running. For additional information, I am currently using HiveMq Cloud as my broker, and paho-mqtt for my main system that is getting the error.
client = mqtt.Client(client_id='main', userdata=None,protocol=mqtt.MQTTv5)
client.on_connect = on_connect
client.tls_set(tls_version=ssl.PROTOCOL_TLS)
client.username_pw_set(userName,PassWord)
client.connect(broker,port,keepalive=60)
client.on_subscribe = on_subscribe
client.on_publish = on_publish
client.message_callback_add("Call/#",on_message_from_sensor)
client.loop_forever()
The program will run anywhere from a few hours, to almost a day. But recently I started receiving this error multiple times.
Traceback (most recent call last):
File "/Users/austin/Desktop/Weather Project/subscribe.py", line 72, in <module>
client.loop_forever()
File "/opt/homebrew/lib/python3.11/site-packages/paho/mqtt/client.py", line 1756, in loop_forever
rc = self._loop(timeout)
^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/paho/mqtt/client.py", line 1164, in _loop
rc = self.loop_read()
^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/paho/mqtt/client.py", line 1556, in loop_read
rc = self._packet_read()
^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/paho/mqtt/client.py", line 2439, in _packet_read
rc = self._packet_handle()
^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/paho/mqtt/client.py", line 3033, in _packet_handle
return self._handle_publish()
^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/paho/mqtt/client.py", line 3331, in _handle_publish
return self._send_puback(message.mid)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/paho/mqtt/client.py", line 2601, in _send_puback
return self._send_command_with_mid(PUBACK, mid, False)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/paho/mqtt/client.py", line 2710, in _send_command_with_mid
return self._packet_queue(command, packet, mid, 1)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/paho/mqtt/client.py", line 3016, in _packet_queue
return self.loop_write()
^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/paho/mqtt/client.py", line 1577, in loop_write
rc = self._packet_write()
^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/paho/mqtt/client.py", line 2464, in _packet_write
write_length = self._sock_send(
^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/paho/mqtt/client.py", line 649, in _sock_send
return self._sock.send(buf)
^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/ssl.py", line 1210, in send
return self._sslobj.write(data)
^^^^^^^^^^^^^^^^^^^^^^^^
ssl.SSLEOFError: EOF occurred in violation of protocol (_ssl.c:2423)
I am expecting this program to run continuously. However, due to this issue, it is randomly stopping and crashing. I have looked up this specific error, but I have not found anything about it. I am new to using mqtt & ssl, so I am not sure where to go from here.
I thought of just adding a try/catch, but I don’t know the underlying issue, so I don't want to just restart if it is something critical.
What should I do?