You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Make sure that port 8883 is open in your firewall. The device sample in this article uses MQTT protocol, which communicates over port 8883. This port may be blocked in some corporate and educational network environments. For more information and ways to work around this issue, see [Connecting to IoT Hub (MQTT)](iot-hub-mqtt-support.md#connecting-to-iot-hub).
42
42
@@ -46,84 +46,126 @@ At the end of this tutorial you run the Python console app:
46
46
47
47
In this section, you create the device app to upload a file to IoT hub.
48
48
49
-
1. At your command prompt, run the following command to install the **azure-iothub-device-client** package:
49
+
1. At your command prompt, run the following command to install the **azure-iot-device** package:
50
50
51
51
```cmd/sh
52
-
pip install azure-iothub-device-client
52
+
pip install azure-iot-device
53
53
```
54
54
55
-
2. Using a text editor, create a test file that you will upload to blob storage.
55
+
1. At your command prompt, run the following command to install the **azure.storage.blob** package.
56
56
57
-
> [!NOTE]
58
-
> IoT Hub Python SDK currently only supports uploading character-based files such as **.txt** files.
57
+
```cmd/sh
58
+
pip install azure.storage.blob
59
+
```
60
+
61
+
1. Create a test file that you will upload to blob storage.
59
62
60
-
3. Using a text editor, create a **FileUpload.py** file in your working folder.
63
+
1. Using a text editor, create a **FileUpload.py** file in your working folder.
61
64
62
-
4. Add the following `import` statements and variables at the start of the **FileUpload.py** file.
65
+
1. Add the following `import` statements and variables at the start of the **FileUpload.py** file.
63
66
64
67
```python
65
-
import time
66
-
import sys
67
-
import iothub_client
68
68
import os
69
-
from iothub_client import IoTHubClient, IoTHubClientError, IoTHubTransportProvider, IoTHubClientResult, IoTHubError
69
+
import asyncio
70
+
from azure.iot.device.aio import IoTHubDeviceClient
71
+
from azure.core.exceptions import AzureError
72
+
from azure.storage.blob import BlobClient
70
73
71
74
CONNECTION_STRING = "[Device Connection String]"
72
-
PROTOCOL = IoTHubTransportProvider.HTTP
73
-
74
-
PATHTOFILE = "[Full path to file]"
75
-
FILENAME = "[File name for storage]"
75
+
PATH_TO_FILE = r"[Full path to local file]"
76
76
```
77
77
78
-
5. In your file, replace `[Device Connection String]` with the connection string of your IoT hub device. Replace `[Full path to file]` with the path to the test file that you created, or any file on your device that you want to upload. Replace `[File name for storage]` with the name that you want to give to your file after it's uploaded to blob storage.
78
+
1. In your file, replace `[Device Connection String]` with the connection string of your IoT hub device. Replace `[Full path to file]` with the path to the test file that you created, or any file on your device that you want to upload.
79
79
80
-
6. Create a callback for the **upload_blob** function:
80
+
1. Create a function to upload the file to blob storage:
0 commit comments