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!
UMQTT IndexError: list index out of range
Re: UMQTT IndexError: list index out of range
BTW, simple.py #57 consists of:
addr = socket.getaddrinfo(self.server, self.port)[0][-1]
addr = socket.getaddrinfo(self.server, self.port)[0][-1]
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: UMQTT IndexError: list index out of range
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.
Index to my micropython libraries.