如何处理“OSError:可用接口已关闭”错误消息?

问题描述 投票:0回答:1

我目前正在使用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()

mqtt connect platform adafruit micropython
1个回答
0
投票

我遇到过类似的问题,我意识到客户端需要一些时间来连接。在连接之前加上2秒延迟并且类似10秒

© www.soinside.com 2019 - 2024. All rights reserved.