|
1 | 1 | ---
|
2 | 2 | title: Quickstart - Export data from Azure IoT Central
|
3 |
| -description: In this quickstart you learn how to use the data export feature in IoT Central to integrate with other cloud services. |
| 3 | +description: In this quickstart, you learn how to use the data export feature in IoT Central to integrate with other cloud services. |
4 | 4 | author: dominicbetts
|
5 | 5 | ms.author: dobett
|
6 | 6 | ms.date: 09/26/2022
|
@@ -34,97 +34,37 @@ Completing this quickstart incurs a small cost in your Azure account for the Azu
|
34 | 34 |
|
35 | 35 | ## Install Azure services
|
36 | 36 |
|
37 |
| -Before you can export data from your IoT Central application, you need an Azure Data Explorer cluster and database. In this quickstart, you use the bash environment in the [Azure Cloud Shell](https://shell.azure.com) to create and configure them. |
| 37 | +Before you can export data from your IoT Central application, you need an Azure Data Explorer cluster and database. In this quickstart, you run a bash script in the [Azure Cloud Shell](https://shell.azure.com) to create and configure them. |
38 | 38 |
|
39 |
| -Run the following script in the Azure Cloud Shell. Replace the `clustername` value with a unique name for your cluster before you run the script. The cluster name can contain only lowercase letters and numbers. Replace the `centralurlprefix` value with the URL prefix you chose in the first quickstart: |
| 39 | +The script completes the following steps: |
40 | 40 |
|
41 |
| -> [!IMPORTANT] |
42 |
| -> The script can take 20 to 30 minutes to run. |
| 41 | +- Prompts you to sign in to your Azure subscription so that it can generate a bearer token to authenticate the REST API calls. |
| 42 | +- Creates an Azure Data Explorer cluster and database. |
| 43 | +- Creates a managed identity for your IoT Central application. |
| 44 | +- Configures the managed identity with permission to access the Azure Data Explorer database. |
| 45 | +- Adds a table to the database to store the incoming telemetry from IoT Central. |
| 46 | + |
| 47 | +Run the following commands to download the script to your Azure Cloud Shell environment: |
43 | 48 |
|
44 | 49 | ```azurecli
|
45 |
| -# The cluster name can contain only lowercase letters and numbers. |
46 |
| -# It must contain from 4 to 22 characters. |
47 |
| -clustername="<A unique name for your cluster>" |
48 |
| -
|
49 |
| -centralurlprefix="<The URL prefix of your IoT Central application>" |
50 |
| -
|
51 |
| -databasename="phonedata" |
52 |
| -location="eastus" |
53 |
| -resourcegroup="IoTCentralExportData-rg" |
54 |
| -
|
55 |
| -az extension add -n kusto |
56 |
| -
|
57 |
| -# Create a resource group for the Azure Data Explorer cluster |
58 |
| -az group create --location $location \ |
59 |
| - --name $resourcegroup |
60 |
| -
|
61 |
| -# Create the Azure Data Explorer cluster |
62 |
| -# This command takes at least 10 minutes to run |
63 |
| -az kusto cluster create --cluster-name $clustername \ |
64 |
| - --sku name="Standard_D11_v2" tier="Standard" \ |
65 |
| - --enable-streaming-ingest=true \ |
66 |
| - --enable-auto-stop=true \ |
67 |
| - --resource-group $resourcegroup --location $location |
68 |
| -
|
69 |
| -# Create a database in the cluster |
70 |
| -az kusto database create --cluster-name $clustername \ |
71 |
| - --database-name $databasename \ |
72 |
| - --read-write-database location=$location soft-delete-period=P365D hot-cache-period=P31D \ |
73 |
| - --resource-group $resourcegroup |
74 |
| -
|
75 |
| -# Create and assign a managed identity to use |
76 |
| -# when authenticating from IoT Central. |
77 |
| -# This assumes your IoT Central was created in the default |
78 |
| -# IOTC resource group. |
79 |
| -MI_JSON=$(az iot central app identity assign --name $centralurlprefix \ |
80 |
| - --resource-group IOTC --system-assigned) |
81 |
| -
|
82 |
| -## Assign the managed identity permissions to use the database. |
83 |
| -az kusto database-principal-assignment create --cluster-name $clustername \ |
84 |
| - --database-name $databasename \ |
85 |
| - --principal-id $(jq -r .principalId <<< $MI_JSON) \ |
86 |
| - --principal-assignment-name $centralurlprefix \ |
87 |
| - --resource-group $resourcegroup \ |
88 |
| - --principal-type App \ |
89 |
| - --tenant-id $(jq -r .tenantId <<< $MI_JSON) \ |
90 |
| - --role Admin |
91 |
| -
|
92 |
| -echo "Azure Data Explorer URL: $(az kusto cluster show --name $clustername --resource-group $resourcegroup --query uri -o tsv)" |
| 50 | +wget https://raw.githubusercontent.com/Azure-Samples/iot-central-docs-samples/main/quickstart-cde/createADX.sh |
| 51 | +chmod u+x createADX.sh |
93 | 52 | ```
|
94 | 53 |
|
95 |
| -Make a note of the **Azure Data Explorer URL**. You use this value later in the quickstart. |
96 |
| - |
97 |
| -## Configure the database |
98 |
| - |
99 |
| -To add a table in the database to store the accelerometer data from the **IoT Plug and Play** smartphone app: |
100 |
| - |
101 |
| -1. Use the **Azure Data Explorer URL** from the previous section to navigate to your Azure Data Explorer environment. |
102 |
| - |
103 |
| -1. Expand the cluster node and select the **phonedata** database. The cope of the query window changes to `Scope:yourclustername.eastus/phonedata`. |
104 |
| - |
105 |
| -1. Paste the following Kusto script into the query editor and select **Run**: |
106 |
| - |
107 |
| - ```kusto |
108 |
| - .create table acceleration ( |
109 |
| - EnqueuedTime:datetime, |
110 |
| - Device:string, |
111 |
| - X:real, |
112 |
| - Y:real, |
113 |
| - Z:real |
114 |
| - ); |
115 |
| - ``` |
116 |
| -
|
117 |
| - The result looks like the following screenshot: |
| 54 | +Use the following command to run the script: |
118 | 55 |
|
119 |
| - :::image type="content" source="media/quick-export-data/azure-data-explorer-create-table.png" alt-text="Screenshot that shows the results of creating the table in Azure Data Explorer."::: |
| 56 | +- Replace `CLUSTER_NAME` with a unique name for your Azure Data Explorer cluster. The cluster name can contain only lowercase letters and numbers. The length of the cluster name must be between 4 and 22 characters. |
| 57 | +- Replace `CENTRAL_URL_PREFIX` with URL prefix you chose in the first quickstart for your IoT Central application. |
| 58 | +- When prompted, follow the instructions to sign in to your account. It's necessary for the script to sign in because it generates a bearer token to authenticate a REST API call. |
120 | 59 |
|
121 |
| -1. In the Azure Data Explorer, open a new tab and paste in the following Kusto script. The script enables streaming ingress for the **acceleration** table: |
| 60 | +```azurecli |
| 61 | +./createADX.sh CLUSTER_NAME CENTRAL_URL_PREFIX |
| 62 | +``` |
122 | 63 |
|
123 |
| - ```kusto |
124 |
| - .alter table acceleration policy streamingingestion enable; |
125 |
| - ``` |
| 64 | +> [!IMPORTANT] |
| 65 | +> This script can take 20 to 30 minutes to run. |
126 | 66 |
|
127 |
| -Keep the Azure Data Explorer page open in your browser. After you configure the data export in your IoT Central application, you'll run a query to view the accelerometer telemetry stored in the **acceleration** table. |
| 67 | +Make a note of the **Azure Data Explorer URL** output by the script. You use this value later in the quickstart. |
128 | 68 |
|
129 | 69 | ## Configure data export
|
130 | 70 |
|
@@ -218,13 +158,19 @@ Wait until the export status shows **Healthy**:
|
218 | 158 |
|
219 | 159 | ## Query exported data
|
220 | 160 |
|
221 |
| -In Azure Data Explorer, open a new tab and paste in the following Kusto query and then select **Run** to plot the accelerometer telemetry: |
| 161 | +To query the exported telemetry: |
222 | 162 |
|
223 |
| -```kusto |
224 |
| -['acceleration'] |
225 |
| - | project EnqueuedTime, Device, X, Y, Z |
226 |
| - | render timechart |
227 |
| -``` |
| 163 | +1. Use the **Azure Data Explorer URL** output by the script you ran previously to navigate to your Azure Data Explorer environment. |
| 164 | + |
| 165 | +1. Expand the cluster node and select the **phonedata** database. The scope of the query window changes to `Scope:yourclustername.eastus/phonedata`. |
| 166 | + |
| 167 | +1. In Azure Data Explorer, open a new tab and paste in the following Kusto query and then select **Run** to plot the accelerometer telemetry: |
| 168 | + |
| 169 | + ```kusto |
| 170 | + ['acceleration'] |
| 171 | + | project EnqueuedTime, Device, X, Y, Z |
| 172 | + | render timechart |
| 173 | + ``` |
228 | 174 |
|
229 | 175 | You may need to wait for several minutes to collect enough data. Try holding your phone in different orientations to see the telemetry values change:
|
230 | 176 |
|
|
0 commit comments