UMQTT IndexError: list index out of range

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
kristsm
Posts: 2
Joined: Fri Nov 30, 2018 12:56 pm

UMQTT IndexError: list index out of range

Post by kristsm » Fri Nov 30, 2018 1:02 pm

Hi, I'm trying to test MQTT capabilities of ESP32 and have problems connecting to test MQTT broker.
The code is as follows:

import machine
import ds18
import utime as time


import network
sta_if = network.WLAN(network.STA_IF)
sta_if.active(True)
sta_if.connect("ssid", "paswd")


from umqtt.robust import MQTTClient
client = MQTTClient("client name", "test.mosquitto.org", port=1883)
print('connecting to MQTT')
client.connect()
client.publish("lights", "ON")
time.sleep(1)
#print("Sending OFF")
client.publish("lights", "OFF")
time.sleep(1)

And it throws out the following error:

Traceback (most recent call last):
File "main.py", line 17, in <module>
File "umqtt/simple.py", line 57, in connect
IndexError: list index out of range
MicroPython v1.9.4-690-g5c34c2ff7 on 2018-11-27; ESP32 module with ESP32

btw, main.py line 17 is: client.connect()


Any suggestions?

Thanks!

kristsm
Posts: 2
Joined: Fri Nov 30, 2018 12:56 pm

Re: UMQTT IndexError: list index out of range

Post by kristsm » Fri Nov 30, 2018 1:43 pm

BTW, simple.py #57 consists of:

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

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: UMQTT IndexError: list index out of range

Post by pythoncoder » Sat Dec 01, 2018 8:28 am

Try waiting until a connection is achieved:

Code: Select all

import utime
# code omitted
sta_if.connect("ssid", "paswd")
while not s.isconnected():
    utime.sleep(1)
Peter Hinch
Index to my micropython libraries.

Post Reply