I am trying to connect a Feather ESP32-S2 feather running CircuitPython 7.3.3 to Azure IoT Central.
I have the application built in Azure and retrieved the scope, device id, and primary key and put them in the secrets.py file as per the tutorial. The Feather successfully connects to WiFi and gets time via NTP, but at the 'device.connect()' line I get an Exception "Connection Refused - Unauthorized". I'm not sure how to further debug this.
try:
from secrets import secrets
except ImportError:
print("Error importing secrets")
raise
print("init WiFi")
wifi.radio.connect(secrets['ssid'], secrets['password'])
print("WiFi init complete")
pool = socketpool.SocketPool(wifi.radio)
ntp = adafruit_ntp.NTP(pool, tz_offset=-7)
if time.localtime().tm_year < 2022:
rtc.RTC().datetime = ntp.datetime
n = ntp.datetime
t = ds3231.datetime
print(f"NTP {n.tm_hour}:{n.tm_min}:{n.tm_sec} {n.tm_mon}/{n.tm_mday}/{n.tm_year} RTC: {t.tm_hour}:{t.tm_min}:{t.tm_sec} {t.tm_mon}/{t.tm_mday}/{t.tm_year}")
ds3231.datetime = ntp.datetime
esp = None
pool = socketpool.SocketPool(wifi.radio)
iot = IoTCentralDevice(pool, esp, secrets['id_scope'], secrets['device_id'], secrets['device_primary_key'])
print("Connecting to Azure")
try:
iot.connect()
az = True
print("Connected to Azure")
except Exception as e:
print("Connection to Azure Failed")
print(f"Message was {e}")
az = False
Feather CircuitPython Azure IoT Central Unauthorized
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- imaginarycurrent
- Posts: 5
- Joined: Sat Apr 14, 2018 6:29 pm
- mikeysklar
- Posts: 14182
- Joined: Mon Aug 01, 2016 8:10 pm
Re: Feather CircuitPython Azure IoT Central Unauthorized
There is a 7 day limit for free plans.
https://learn.adafruit.com/getting-star ... our-device
Did you setup an Azure IoT Central account? Are you still able to login to the Azure portal through a web browser and verify the device is registered?If you are on a free plan, then your data will only be accessible for 7 days. After 7 days, your data and application are deleted unless you convert to a paid plan.
https://learn.adafruit.com/getting-star ... our-device
- imaginarycurrent
- Posts: 5
- Joined: Sat Apr 14, 2018 6:29 pm
Re: Feather CircuitPython Azure IoT Central Unauthorized
As of last weekend I setup a new IoT central app in my pay as you go subscription.
I followed https://learn.adafruit.com/getting-star ... re-display
The device is present in the IoT Central app. I've tried recreating it and updating the values in secrets.py.
I haven't made it to 7 days so I should be good from that aspect in any case.
I followed https://learn.adafruit.com/getting-star ... re-display
The device is present in the IoT Central app. I've tried recreating it and updating the values in secrets.py.
I haven't made it to 7 days so I should be good from that aspect in any case.
- mikeysklar
- Posts: 14182
- Joined: Mon Aug 01, 2016 8:10 pm
Re: Feather CircuitPython Azure IoT Central Unauthorized
I see an issue created on the Adafruit_CircuitPYthon_AzureIoT that has some overlap.
https://github.com/adafruit/Adafruit_Ci ... /issues/53
The first thing they suggest is it could be a timezone issue. Can you set tz_offset to 0.
https://github.com/adafruit/Adafruit_Ci ... /issues/53
The first thing they suggest is it could be a timezone issue. Can you set tz_offset to 0.
- imaginarycurrent
- Posts: 5
- Joined: Sat Apr 14, 2018 6:29 pm
Re: Feather CircuitPython Azure IoT Central Unauthorized
That was it. I changed the offset to 0 and it connected. Thank you for the info. Given the examples all have it set to a non zero value it never occurred to me to try changing it to 0.
- mikeysklar
- Posts: 14182
- Joined: Mon Aug 01, 2016 8:10 pm
Re: Feather CircuitPython Azure IoT Central Unauthorized
Excellent. Thank you for the confirmation.
Please be positive and constructive with your questions and comments.