Skip to content

Commit 7076504

Browse files
author
brentru
committed
redo examples to match new location of device_id
1 parent d169190 commit 7076504

File tree

3 files changed

+9
-22
lines changed

3 files changed

+9
-22
lines changed

examples/azureiot_device_management.py

+2-9
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,12 @@
2929
wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light)
3030

3131
# 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'
32+
hub = IOT_Hub(wifi, secrets['azure_iot_hub'], secrets['azure_iot_sas'], secrets['device_id'])
3533

3634
# Enumerate all devices on an Azure IoT Hub
3735
all_hub_devices = hub.get_devices()
3836
print(all_hub_devices)
3937

4038
# Get a specified device on an Azure IoT Hub
41-
device_data = hub.get_device(device_id)
39+
device_data = hub.get_device()
4240
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!')

examples/azureiot_devicetwin.py

+4-7
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,19 @@
2929
wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light)
3030

3131
# Create an instance of the Azure IoT Hub
32-
hub = IOT_Hub(wifi, secrets['azure_iot_hub'], secrets['azure_iot_sas'])
33-
34-
# Set a device id (This name must match a device connected to your Azure IoT Hub)
35-
device_id = 'Blinka'
32+
hub = IOT_Hub(wifi, secrets['azure_iot_hub'], secrets['azure_iot_sas'], secrets['device_id'])
3633

3734
# Get a Device Twin
38-
device_twin = hub.get_device_twin(device_id)
35+
device_twin = hub.get_device_twin()
3936
# Filter out the device's name from the twin's properties
4037
device_name = device_twin['properties']['desired']['deviceName']
4138
print(device_name)
4239

4340
# Update a Device Twin's Properties
4441
data = {"properties":{"desired": {"deviceName": "{{BasementTemperatureLoggerFeather}}"}}}
45-
hub.update_device_twin(device_id, data)
42+
hub.update_device_twin(data)
4643

4744
# And read the updated device twin information
48-
device_twin = hub.get_device_twin(device_id)
45+
device_twin = hub.get_device_twin()
4946
device_name = device_twin['properties']['desired']['deviceName']
5047
print(device_name)

examples/azureiot_simpletest.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,19 @@
3030
wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light)
3131

3232
# Create an instance of the Azure IoT Hub
33-
hub = IOT_Hub(wifi, secrets['azure_iot_hub'], secrets['azure_iot_sas'])
34-
35-
# Set a device id (This name must match a device connected to your Azure IoT Hub)
36-
device_id = 'Blinka'
33+
hub = IOT_Hub(wifi, secrets['azure_iot_hub'], secrets['azure_iot_sas'], secrets['device_id'])
3734

3835
# Send a Device-to-Cloud message
3936
print('Sending Data to Azure IoT Hub...')
4037
data = randint(0, 100)
41-
hub.send_device_message(device_id, str(data))
38+
hub.send_device_message(str(data))
4239
print('Data Sent!')
4340

4441
# Receive a Cloud-to-Device message
4542
# NOTE: HTTP Cloud-to-Device messages are HEAVILY throttled over HTTP.
4643
# Microsoft suggests a polling interval of the below code for every 25 minutes.
4744
print('Receiving a message from an Azure IoT Hub...')
48-
message = hub.get_hub_message(device_id)
45+
message = hub.get_hub_message()
4946
if message == -1:
5047
print('IoT Hub Message Queue is empty!')
5148
else:

0 commit comments

Comments
 (0)