我已经遵循了多个教程,并且没有遇到此错误。
256.705: INFO - - iot_mqtt :: connect :: redacted123.azure-devices.net
256.711: DEBUG - - iot_mqtt :: _on_connect :: username = redacted123.azure-devices.net/MyArduinoConnect/?api-version=2019-10-01, password = SharedAccessSignature sr=myiothub.azure-devices.net%2Fdevices%2Fredacted123ArduinoConnect&sig=OKeIy1cgk%2FQ9ok%2BiO359CWEBWDH1erL1lzQiZP7rwbk%3D&se=1637119964
256.719: DEBUG - Attempting to establish MQTT connection...
256.725: INFO - Establishing a SECURE SSL connection to redacted123iothub.azure-devices.net:8883
Connection error, reconnecting
Timed out waiting for SPI char
我有这个固件:adafruit-circuitpython-arduino_nano_rp2040_connect-sv-7.0.0
我有这些库:adafruit-circuitpython-bundle-7.x-mpy-20211116
我正在使用这个代码,它尽可能小,可以重现。
import time
import board
import busio
from digitalio import DigitalInOut
import adafruit_requests as requests
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
from adafruit_esp32spi import adafruit_esp32spi
# azure imports
from adafruit_azureiot import IoTHubDevice # pylint: disable=wrong-import-position
from adafruit_ntp import NTP
from secrets import secrets
# ESP32 pins
esp32_cs = DigitalInOut(board.CS1)
esp32_ready = DigitalInOut(board.ESP_BUSY)
esp32_reset = DigitalInOut(board.ESP_RESET)
# uses the secondary SPI connected through the ESP32
spi = busio.SPI(board.SCK1, board.MOSI1, board.MISO1)
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
print("Connecting to WiFi.")
requests.set_socket(socket, esp)
esp.connect_AP(secrets["ssid"], secrets["password"])
print("Connected: ", str(esp.ssid, "utf-8"), "\tRSSI:", esp.rssi)
print("IP: ", esp.pretty_ip(esp.ip_address))
ntp = NTP(esp)
# Wait for a valid time to be received
while not ntp.valid_time:
print("waiting for NTP Time")
time.sleep(5)
ntp.set_time()
print("Wifi connected.")
device = IoTHubDevice(socket, esp, secrets["azure_device_connection_string"])
attempts = 0
while not device.is_connected() and attempts < 3:
attempts = attempts + 1
print("Connecting to Azure: #" + str(attempts));
try:
print("begin")
device.connect()
print("SUCCESSS!")
except BaseException as e:
print("Connection error, reconnecting\n", str(e))
time.sleep(2)
# need to reset this or self.device.is_connected() will explode on loop.
device = IoTHubDevice(socket, esp, secrets["azure_device_connection_string"])
if(attempts>=3):
print("failed to reach the cloud.")
time.sleep(60) # sleep for a minute before loops start over.
else:
print("Connected to cloud")
我从未设法连接到 Azure IoT 中心。总是一样SPI Error
。
错误来自这一行:
device.connect()
感谢任何帮助,请记住,我对 Arduino、CircuitPython 和 IoT 很陌生。