I'm currently working an IOT project requiring the transfer of sensor data between an ESP32 (a wESP32 to be exact) and a Raspberry Pi configured as a broker. From what I've read so far the MQTT protocol seems to fit my needs perfectly, I'm thus running a Mosquitto broker on the Pi as well as the MQTT simple client library provided on the micropython's GitHub repository.
The first tests performed in the MicroPython WebREPL have been successful as I've been able to receive data published from the ESP using the following code:
Welcome to MicroPython!
Password:
WebREPL connected
>>> from umqtt.simple import MQTTClient
>>> c = MQTTClient("umqtt_client", "rapsberrypi")
>>> c.connect()
0
>>> c.publish(b"sensors/temperature", "{:.1f}".format(21.35))
>>> c.disconnect()
>>>
However as soon as I try running the same code on boot in the main.py
file or through the serial port using ether screen
or rshell
I get the following error.
Started webrepl in normal mode
MicroPython v1.12 on 2019-12-20; ESP32 module with ESP32
Type "help()" for more information.
>>> I (4379) ethernet: LAN cable connected
I (5359) event: eth ip: 192.168.1.62, mask: 255.255.255.0, gw: 192.168.1.1
I (5359) ethernet: Got IP
from umqtt.simple import MQTTClient
>>> c = MQTTClient("umqtt_client", "rapsberrypi")
>>> c.connect()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "umqtt/simple.py", line 57, in connect
IndexError: list index out of range
>>>
For some context here is the 57th line of the umqtt/simple.py
file:
55 def connect(self, clean_session=True):
56 self.sock = socket.socket()
57 addr = socket.getaddrinfo(self.server, self.port)[0][-1]
58 self.sock.connect(addr)
If tou have any clue of what's going on here please let me know!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…