Feather CircuitPython Azure IoT Central Unauthorized

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
imaginarycurrent
 
Posts: 5
Joined: Sat Apr 14, 2018 6:29 pm

Feather CircuitPython Azure IoT Central Unauthorized

Post by imaginarycurrent »

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

User avatar
mikeysklar
 
Posts: 13824
Joined: Mon Aug 01, 2016 8:10 pm

Re: Feather CircuitPython Azure IoT Central Unauthorized

Post by mikeysklar »

There is a 7 day limit for free plans.
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.
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?

https://learn.adafruit.com/getting-star ... our-device

User avatar
imaginarycurrent
 
Posts: 5
Joined: Sat Apr 14, 2018 6:29 pm

Re: Feather CircuitPython Azure IoT Central Unauthorized

Post by imaginarycurrent »

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.

User avatar
mikeysklar
 
Posts: 13824
Joined: Mon Aug 01, 2016 8:10 pm

Re: Feather CircuitPython Azure IoT Central Unauthorized

Post by mikeysklar »

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.

User avatar
imaginarycurrent
 
Posts: 5
Joined: Sat Apr 14, 2018 6:29 pm

Re: Feather CircuitPython Azure IoT Central Unauthorized

Post by imaginarycurrent »

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.

User avatar
mikeysklar
 
Posts: 13824
Joined: Mon Aug 01, 2016 8:10 pm

Re: Feather CircuitPython Azure IoT Central Unauthorized

Post by mikeysklar »

Excellent. Thank you for the confirmation.

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”