peterhinch / micropython-mqtt

A 'resilient' asynchronous MQTT driver. Recovers from WiFi and broker outages.
MIT License
549 stars 116 forks source link

File "mqtt_as.py", line 622, in connect TypeError: can't convert str to int #114

Closed ruben-mar closed 1 year ago

ruben-mar commented 1 year ago

Fresh new pull today, with mqtt_local.py configured in a Pico, when running the Example Usage code I get:

>>> %Run -c $EDITOR_CONTENT
Checking WiFi integrity.
Got reliable connection
Traceback (most recent call last):
  File "<stdin>", line 35, in <module>
  File "uasyncio/core.py", line 1, in run
  File "uasyncio/core.py", line 1, in run_until_complete
  File "uasyncio/core.py", line 1, in run_until_complete
  File "<stdin>", line 20, in main
  File "mqtt_as.py", line 622, in connect
TypeError: can't convert str to int

When running range.py the console output is:

Checking WiFi integrity.
Got reliable connection
Traceback (most recent call last):
  File "<stdin>", line 78, in <module>
  File "uasyncio/core.py", line 1, in run
  File "uasyncio/core.py", line 1, in run_until_complete
  File "uasyncio/core.py", line 1, in run_until_complete
  File "<stdin>", line 54, in main
  File "mqtt_as.py", line 622, in connect
TypeError: can't convert str to int
peterhinch commented 1 year ago

I can't replicate this. I use mpremote rather than Thonny, but I don't think this is a Thonny issue. Here is my traceback

MPY: soft reboot
MicroPython v1.20.0 on 2023-04-26; Raspberry Pi Pico W with RP2040
Type "help()" for more information.
>>> import range_ex
Checking WiFi integrity.
Got reliable connection
Connecting to broker.
Connected to broker.
We are connected to broker.
publish 0

The line that is failing is

self._addr = socket.getaddrinfo(self.server, self.port)[0][-1]

Are you sure your server address is correct? You might like to use ping to check this.

ruben-mar commented 1 year ago

Now, this is embarrassing, I assigned the port as a string. I am not excused by having declared the IP address of the server as a string "server": '192.168.1.139', followed by the port also as a string "port": '1883', because the default value of port is an integer 0 all right "port": 0,

Both example scripts work now. Apologies and thank you.