Не удается подключиться к Azure IoT Hub с помощью Arduino Nano RP2040 Connect

Я изучил несколько руководств, и я не зациклен на этой ошибке.

      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 Hub. Всегда одно и то же SPI Error.

Ошибка исходит из этой строки:

      device.connect()

Я буду признателен за любую помощь, имейте в виду, что я новичок в Arduino, CircuitPython и IoT.

1 ответ

Решение состояло в том, чтобы обновить прошивку Nina Wifi, как описано здесь:

https://docs.arduino.cc/tutorials/nano-rp2040-connect/rp2040-upgrading-nina-firmware

Другие вопросы по тегам