sirkus7 / ospiLCD-mqtt

OpenSprinkler status display -- a Raspberry Pi, I2C LCD, MQTT enabled display.
8 stars 2 forks source link

TypeError: '<=' not supported between instances of 'str' and 'int' #5

Open RonRN18 opened 6 months ago

RonRN18 commented 6 months ago

I am apparently unable to make a connection to my MQTT broker, which exists on a different device; a Home Assistant box. The screen just displays:

Connecting to 
MQTT broker...

Meanwhile, in my shell, I see:

/home/bigron/./ospiLCD-mqtt.py:256: DeprecationWarning: Callback API version 1 is deprecated, update to latest version
  client = mqtt.Client()
Traceback (most recent call last):
  File "/home/bigron/./ospiLCD-mqtt.py", line 259, in <module>
    client.connect(mqttAddress, mqttPort, 60)
  File "/usr/local/lib/python3.9/dist-packages/paho/mqtt/client.py", line 1433, in connect
    self.connect_async(host, port, keepalive,
  File "/usr/local/lib/python3.9/dist-packages/paho/mqtt/client.py", line 1525, in connect_async
    self.port = port
  File "/usr/local/lib/python3.9/dist-packages/paho/mqtt/client.py", line 914, in port
    if value <= 0:
TypeError: '<=' not supported between instances of 'str' and 'int'
RonRN18 commented 6 months ago

I realized that it the TypeError was due to the way the mqttPass was defined in Line 32; the quotation marks need to be removed from the variable declaration. With quotation marks, it thinks that the port number is a string, not a number. Unfortunately, that didn't solve all of the issues. It now has an issue with calling the client.

/home/bigron/./ospiLCD-mqtt.py:256: DeprecationWarning: Callback API version 1 is deprecated, update to latest version
client = mqtt.Client()
[Connected with result code 5]
[Connected with result code 5]

On line 254 it says:

client = mqtt.Client()  

Apparently, this is attempting to connect with API version 1, which has been deprecated. I know that my MQTT broker supports version 5. I was doing some testing and can't figure out how to tell it to use version 5 but I did see a command to make it try version 2. If I change it to:

client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2)

With this, I get an error saying:

Traceback (most recent call last):
  File "/home/bigron/./ospiLCD-mqtt.py", line 260, in <module>
    client.loop_forever()
  File "/usr/local/lib/python3.9/dist-packages/paho/mqtt/client.py", line 2297, in loop_forever
    rc = self._loop(timeout)
  File "/usr/local/lib/python3.9/dist-packages/paho/mqtt/client.py", line 1686, in _loop
    rc = self.loop_read()
  File "/usr/local/lib/python3.9/dist-packages/paho/mqtt/client.py", line 2100, in loop_read
    rc = self._packet_read()
  File "/usr/local/lib/python3.9/dist-packages/paho/mqtt/client.py", line 3142, in _packet_read
    rc = self._packet_handle()
  File "/usr/local/lib/python3.9/dist-packages/paho/mqtt/client.py", line 3814, in _packet_handle
    return self._handle_connack()
  File "/usr/local/lib/python3.9/dist-packages/paho/mqtt/client.py", line 3934, in _handle_connack
    on_connect(
TypeError: mqtt_connect() takes 4 positional arguments but 5 were given

I am hoping I'm making progress but as of yet, I don't have it working.