我目前正在使用Pycom设备,并尝试将其连接到IoT平台(更准确地说,是Adafruit IO)。我想让平台和我的设备进行通信。它曾经工作得很好,我可以使用MQTT发布和订阅网站上配置的主题/窗口小部件,但是最近,当我尝试使用这个协议连接到Adafruit时,我得到了这个错误信息:OSError: Available Interfaces are down.我不知道为什么突然之间,这种情况发生了,我不知道如何处理。有时,在一段时间或多次尝试后,它会再次工作,但我想更准确地知道这是由于什么原因。
import umqtt
from umqtt import MQTTClient
import ubinascii
import micropython
import time
import machine
import pycom
pycom.heartbeat(False)
IO_SERVER = "io.adafruit.com"
AIO_SERVER = "io.adafruit.com"
AIO_PORT = 1883
AIO_USER = "user"
AIO_KEY = "key"
AIO_CLIENT_ID = ubinascii.hexlify(machine.unique_id()) # Can be anything
client = MQTTClient(AIO_CLIENT_ID, AIO_SERVER, AIO_PORT, AIO_USER, AIO_KEY)
import network
from network import WLAN
wlan=WLAN(mode=WLAN.STA)
pw='pw'
nets=wlan.scan()
for net in nets:
if net.ssid == 'myssid':
wlan.connect(net.ssid,auth=(None,pw),timeout=5000)
if wlan.isconnected() == True:
pycom.rgbled(0x007f00)
else:
pycom.rgbled(0x7f0000)
client.connect()
pycom.rgbled(0x7f7f00)我使用了位于以下位置的umqtt模块:https://github.com/micropython/micropython-lib/blob/master/umqtt.simple/umqtt/simple.py。我可以毫无问题地连接到我的wifi,错误发生在client.connect()。
发布于 2019-04-23 19:35:00
我曾经遇到过类似的问题,我意识到客户端连接需要一些时间。在连接前添加2秒延迟&类似于10秒
https://stackoverflow.com/questions/54532495
复制相似问题