Skip to content

Commit 09e4f78

Browse files
author
brentru
committed
add example of device management subset implementation
1 parent 0c97a1d commit 09e4f78

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import board
2+
import busio
3+
from digitalio import DigitalInOut
4+
from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager
5+
import neopixel
6+
from adafruit_azureiot import IOT_Hub
7+
8+
# Get wifi details and more from a secrets.py file
9+
try:
10+
from secrets import secrets
11+
except ImportError:
12+
print("WiFi secrets are kept in secrets.py, please add them there!")
13+
raise
14+
15+
# ESP32 Setup
16+
try:
17+
esp32_cs = DigitalInOut(board.ESP_CS)
18+
esp32_ready = DigitalInOut(board.ESP_BUSY)
19+
esp32_reset = DigitalInOut(board.ESP_RESET)
20+
except AttributeError:
21+
esp32_cs = DigitalInOut(board.D9)
22+
esp32_ready = DigitalInOut(board.D10)
23+
esp32_reset = DigitalInOut(board.D5)
24+
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
25+
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
26+
status_light = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2) # Uncomment for Most Boards
27+
"""Uncomment below for ItsyBitsy M4"""
28+
#status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2)
29+
wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light)
30+
31+
# Create an instance of the Azure IoT Hub
32+
hub = IOT_Hub(wifi, secrets['azure_iot_hub'], secrets['azure_iot_sas'])
33+
34+
device_id = 'CircuitPython'
35+
36+
# Enumerate all devices on an Azure IoT Hub
37+
all_hub_devices = hub.get_devices()
38+
print(all_hub_devices)
39+
40+
# Get a specified device on an Azure IoT Hub
41+
device_data = hub.get_device(device_id)
42+
print(device_data)
43+
44+
# Delete a device from an Azure IoT Hub
45+
# NOTE: This operation requires a device's ETag
46+
hub.delete_device(device_id, device_data['etag'])
47+
print('Device deleted from IoT Hub!')

0 commit comments

Comments
 (0)