Skip to content

Commit a0fcf6f

Browse files
committed
Add HTP how to
1 parent ea8a41a commit a0fcf6f

File tree

6 files changed

+27
-270
lines changed

6 files changed

+27
-270
lines changed

articles/iot-operations/discover-manage-assets/howto-use-http-connector.md

Lines changed: 27 additions & 270 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ author: dominicbetts
55
ms.author: dobett
66
ms.service: azure-iot-operations
77
ms.topic: how-to
8-
ms.date: 10/07/2024
8+
ms.date: 07/23/2025
99

1010
#CustomerIntent: As an industrial edge IT or operations user, I want configure my Azure IoT Operations environment so that I can access data from HTTP/REST endpoints.
1111
---
1212

1313
# Configure the connector for REST/HTTP (preview)
1414

15-
In Azure IoT Operations, the connector for REST/HTTP (preview) enables access to data from HTTP/REST endpoints such as edge-attached cameras.
15+
In Azure IoT Operations, the connector for REST/HTTP (preview) enables access to data from REST endpoints exposed by HTTP services.
1616

1717
[!INCLUDE [iot-operations-asset-definition](../includes/iot-operations-asset-definition.md)]
1818

@@ -21,9 +21,7 @@ In Azure IoT Operations, the connector for REST/HTTP (preview) enables access to
2121
This article explains how to use the connector for REST/HTTP to perform tasks such as:
2222

2323
- Define the devices that connect HTTP sources to your Azure IoT Operations instance.
24-
- Add assets, and define their streams, data points, and events to enable data flow from the HTTP source to the MQTT broker.
25-
- Send an image snapshot to the MQTT broker.
26-
- Save a video stream to a local file system.
24+
- Add assets, and define the data points to enable the data flow from the HTTP source to the MQTT broker.
2725

2826
## Prerequisites
2927

@@ -33,298 +31,57 @@ To configure devices and assets, you need a running instance of Azure IoT Operat
3331

3432
Your IT administrator must have configured the connector for REST/HTTP template for your Azure IoT Operations instance in the Azure portal.
3533

36-
A camera connected to your network and accessible from your Azure IoT Operations cluster. The camera must support the Real Time Streaming Protocol for video streaming. You also need the camera's username and password to authenticate with it.
34+
You need any credentials required to access the HTTP source. If the HTTP source requires authentication, you need to create a Kubernetes secret that contains the username and password for the HTTP source.
3735

3836
## Deploy the connector for REST/HTTP
3937

40-
<!--TODO: Probably not necessary now we have the connector templates? -->
41-
42-
[!INCLUDE [deploy-preview-media-connectors](../includes/deploy-preview-media-connectors.md)]
38+
[!INCLUDE [deploy-preview-http-connectors](../includes/deploy-preview-media-connectors.md)]
4339

4440
> [!IMPORTANT]
4541
> If you don't enable preview features, you see the following error message in the `aio-supervisor-...` pod logs when you try to use the HTTP, media, or ONVIF connectors: `No connector configuration present for AssetEndpointProfile: <AssetEndpointProfileName>`.
4642
4743
## Create a device
4844

49-
To configure the connector for REST/HTTP, first create a device that defines the connection to the HTTP source. The device includes the URL of the HTTP source, the type of HTTP source, and any credentials you need to access the HTTP source.
50-
51-
If your HTTP endpoint requires authentication, create a secret in your Kubernetes cluster that stores the endpoint's username and password. The connector for REST/HTTP uses this secret to authenticate with the endpoint:
52-
53-
1. Create a YAML file called _contoso-http-secrets.yaml_ with the following content. Replace the placeholders with your camera's username and password encoded in base64:
54-
55-
```yaml
56-
apiVersion: v1
57-
kind: Secret
58-
metadata:
59-
name: contoso-http-secrets
60-
type: Opaque
61-
data:
62-
username: "<YOUR HTTP USERNAME BASE64 ENCODED>"
63-
password: "<YOUR HTTP PASSWORD BASE64 ENCODED>"
64-
```
65-
66-
> [!TIP]
67-
> To encode the username and password in base64 at a Bash prompt, use the following command: `echo -n "<STRING TO ENCODE>" | base64`.
68-
69-
1. To add the secret to your cluster in the default Azure IoT Operations namespace, run the following command:
70-
71-
```console
72-
kubectl apply -f contoso-http-secrets.yaml -n azure-iot-operations
73-
```
74-
75-
To create a device configuration:
76-
77-
# [Operations experience](#tab/portal)
78-
79-
1. Select **devices** and then **Create device**:
80-
81-
:::image type="content" source="media/howto-use-http-connector/asset-endpoints.png" alt-text="Screenshot that shows the devices page in the operations experience." lightbox="media/howto-use-http-connector/asset-endpoints.png":::
82-
83-
> [!TIP]
84-
> You can use the filter box to search for devices.
85-
86-
1. Enter the following endpoint information:
87-
88-
| Field | Value |
89-
| --- | --- |
90-
| Name | `opc-ua-connector-0` |
91-
| Connector for OPC UA URL | `opc.tcp://opcplc-000000:50000` |
92-
| User authentication | `Anonymous` |
93-
94-
1. To save the definition, select **Create**.
95-
96-
# [Azure CLI](#tab/cli)
97-
98-
Run the following command:
99-
100-
```azurecli
101-
az iot ops device create opcua --name opc-ua-connector-0 --target-address opc.tcp://opcplc-000000:50000 -g {your resource group name} --instance {your instance name}
102-
```
103-
104-
> [!TIP]
105-
> Use `az connectedk8s list` to list the clusters you have access to.
106-
107-
To learn more, see [az iot ops device](/cli/azure/iot/ops/asset/endpoint).
108-
109-
# [Bicep (Bash)](#tab/bicep-bash)
110-
111-
1. Set the following environment variables:
112-
113-
```bash
114-
SUBSCRIPTION_ID="<YOUR SUBSCRIPTION ID>"
115-
RESOURCE_GROUP="<YOUR AZURE IOT OPERATIONS RESOURCE GROUP>"
116-
TARGET_ADDRESS="<YOUR CAMERA RTSP ADDRESS>"
117-
AEP_NAME="contoso-rtsp-aep"
118-
SECRET_NAME="contoso-secrets"
119-
```
120-
121-
1. Run the following script:
122-
123-
```bash
124-
# Download the Bicep file
125-
wget https://raw.githubusercontent.com/Azure-Samples/explore-iot-operations/main/samples/media-connector-bicep/aep-media-connector.bicep -O aep-media-connector.bicep
126-
127-
# Find the name of your custom location
128-
CUSTOM_LOCATION_NAME=$(az iot ops list -g $RESOURCE_GROUP --query "[0].extendedLocation.name" -o tsv)
129-
130-
# Use the Bicep file to deploy the device
131-
az deployment group create --subscription $SUBSCRIPTION_ID --resource-group $RESOURCE_GROUP --template-file aep-media-connector.bicep --parameters targetAddress=$TARGET_ADDRESS customLocationName=$CUSTOM_LOCATION_NAME aepName=$AEP_NAME secretName=$SECRET_NAME
132-
```
133-
134-
The following snippet shows the bicep file that you used to create the device:
135-
136-
:::code language="bicep" source="~/azure-iot-operations-samples/samples/media-connector-bicep/aep-media-connector.bicep":::
137-
138-
The previous example configures the device to authenticate with the camera with a username and password. In the Bicep file, the authentication section of the device you created looks like the following example:
139-
140-
```bicep
141-
authentication: {
142-
method: 'UsernamePassword'
143-
usernamePasswordCredentials: {
144-
passwordSecretName: '${secretName}/password'
145-
usernameSecretName: '${secretName}/username'
146-
}
147-
```
148-
149-
If your camera doesn't require a username and password, configure anonymous authentication as shown in the following example:
150-
151-
```bicep
152-
authentication: {
153-
method: 'Anonymous'
154-
}
155-
```
156-
157-
# [Bicep (PowerShell)](#tab/bicep-powershell)
158-
159-
1. Set the following environment variables:
160-
161-
```powershell
162-
$SUBSCRIPTION_ID="<YOUR SUBSCRIPTION ID>"
163-
$RESOURCE_GROUP="<YOUR AZURE IOT OPERATIONS RESOURCE GROUP>"
164-
$TARGET_ADDRESS="<YOUR CAMERA RTSP ADDRESS>"
165-
$AEP_NAME="contoso-rtsp-aep"
166-
$SECRET_NAME="contoso-secrets"
167-
```
168-
169-
1. Run the following script:
45+
To configure the connector for REST/HTTP, first create a device that defines the connection to the HTTP source. The device includes the URL of the HTTP source and any credentials you need to access the HTTP source.
17046

171-
```powershell
172-
# Download the Bicep file
173-
Invoke-WebRequest -Uri https://raw.githubusercontent.com/Azure-Samples/explore-iot-operations/main/samples/media-connector-bicep/aep-media-connector.bicep -OutFile aep-media-connector.bicep
47+
1. In the operations experience web UI, select **Devices** in the left navigation pane. Then select **Create new**.
17448

175-
# Find the name of your custom location
176-
$CUSTOM_LOCATION_NAME = (az iot ops list -g $RESOURCE_GROUP --query "[0].extendedLocation.name" -o tsv)
49+
1. Enter a name for your device, such as `http-connector`. To add the endpoint for the connector for REST/HTTP, select **New** on the **Microsoft.Http** tile.
17750

178-
# Use the Bicep file to deploy the device
179-
az deployment group create --subscription $SUBSCRIPTION_ID --resource-group $RESOURCE_GROUP --template-file aep-media-connector.bicep --parameters targetAddress=$TARGET_ADDRESS customLocationName=$CUSTOM_LOCATION_NAME aepName=$AEP_NAME secretName=$SECRET_NAME
180-
```
51+
1. Add the details of the endpoint for the connector for REST/HTTP including any authentication credentials:
18152

182-
The following snippet shows the bicep file that you used to create the device:
53+
:::image type="content" source="media/howto-use-http-connector/add-http-connector-endpoint.png" alt-text="Screenshot that shows how to add a connector for REST/HTTP endpoint" lightbox="media/howto-use-http-connector/add-http-connector-endpoint.png":::
18354

184-
:::code language="bicep" source="~/azure-iot-operations-samples/samples/media-connector-bicep/aep-media-connector.bicep":::
55+
Select **Apply** to save the endpoint.
18556

186-
The previous example configures the device to authenticate with the camera with a username and password. In the Bicep file, the authentication section of the device you created looks like the following example:
57+
1. On the **Device details** page, select **Next** to continue.
18758

188-
```bicep
189-
authentication: {
190-
method: 'UsernamePassword'
191-
usernamePasswordCredentials: {
192-
passwordSecretName: '${secretName}/password'
193-
usernameSecretName: '${secretName}/username'
194-
}
195-
```
59+
1. On the **Add custom property** page, you can add any other properties you want to associate with the device. For example, you might add a property to indicate the manufacturer of the camera. Then select **Next** to continue
19660

197-
If your camera doesn't require a username and password, configure anonymous authentication as shown in the following example:
198-
199-
```bicep
200-
authentication: {
201-
method: 'Anonymous'
202-
}
203-
```
204-
205-
---
206-
207-
## Asset configuration
208-
209-
When you configure an asset, the `datasets.DataPoints` parameter specifies the action the connector for REST/HTTP takes on the asset. An HTTP asset supports the following task types:
210-
211-
| Task type | Description |
212-
|-----------|-------------|
213-
| `snapshot-to-mqtt` | Capture snapshots from a camera and publishes them to an MQTT topic. |
214-
| `snapshot-to-fs` | Capture snapshots from a camera and saves them to the local file system. |
215-
216-
The following examples show how to deploy assets for each task type.
217-
218-
> [!TIP]
219-
> The HTTP pods aren't created in Kubernetes until you deploy an asset that uses the connector for REST/HTTP. If you try to run the `kubectl get pods` command before deploying an asset, you see no HTTP pods.
220-
221-
## Snapshot to MQTT
222-
223-
To configure an asset that captures snapshots from an endpoint and publishes them to an MQTT topic:
224-
225-
# [Operations experience](#tab/portal)
226-
227-
Go to the operations experience web UI and select **Assets**. Then select **Create asset**.
228-
229-
Add the configuration for a snapshot to mqtt asset.
230-
231-
<!-- TODO: Expand this section when we have the UI available -->
232-
233-
# [Azure CLI](#tab/cli)
234-
235-
Use the `az iot ops asset create` command to create a snapshot to mqtt asset.
236-
237-
<!-- TODO: Expand this section when we have the CLI available -->
238-
239-
# [Bicep (Bash)](#tab/bicep-bash)
240-
241-
1. Set the following environment variables:
242-
243-
```bash
244-
SUBSCRIPTION_ID="<YOUR SUBSCRIPTION ID>"
245-
RESOURCE_GROUP="<YOUR AZURE IOT OPERATIONS RESOURCE GROUP>"
246-
AEP_NAME="contoso-rtsp-aep"
247-
```
248-
249-
1. Run the following script:
250-
251-
```bash
252-
# Download the Bicep file
253-
wget https://raw.githubusercontent.com/Azure-Samples/explore-iot-operations/main/samples/media-connector-bicep/asset-snapshot-to-mqtt.bicep -O asset-snapshot-to-mqtt.bicep
254-
255-
# Find the name of your custom location
256-
CUSTOM_LOCATION_NAME=$(az iot ops list -g $RESOURCE_GROUP --query "[0].extendedLocation.name" -o tsv)
257-
258-
# Use the Bicep file to deploy the asset
259-
az deployment group create --subscription $SUBSCRIPTION_ID --resource-group $RESOURCE_GROUP --template-file asset-snapshot-to-mqtt.bicep --parameters customLocationName=$CUSTOM_LOCATION_NAME aepName=$AEP_NAME
260-
```
261-
262-
The following snippet shows the bicep file that you used to create the asset:
263-
264-
:::code language="bicep" source="~/azure-iot-operations-samples/samples/media-connector-bicep/asset-snapshot-to-mqtt.bicep":::
265-
266-
# [Bicep (PowerShell)](#tab/bicep-powershell)
267-
268-
1. Set the following environment variables:
269-
270-
```powershell
271-
$SUBSCRIPTION_ID="<YOUR SUBSCRIPTION ID>"
272-
$RESOURCE_GROUP="<YOUR AZURE IOT OPERATIONS RESOURCE GROUP>"
273-
$AEP_NAME="contoso-rtsp-aep"
274-
```
275-
276-
1. Run the following script:
277-
278-
```powershell
279-
# Download the Bicep file
280-
Invoke-WebRequest -Uri https://raw.githubusercontent.com/Azure-Samples/explore-iot-operations/main/samples/media-connector-bicep/asset-snapshot-to-mqtt.bicep -OutFile asset-snapshot-to-mqtt.bicep
281-
282-
# Find the name of your custom location
283-
$CUSTOM_LOCATION_NAME = (az iot ops list -g $RESOURCE_GROUP --query "[0].extendedLocation.name" -o tsv)
284-
285-
# Use the Bicep file to deploy the asset
286-
az deployment group create --subscription $SUBSCRIPTION_ID --resource-group $RESOURCE_GROUP --template-file asset-snapshot-to-mqtt.bicep --parameters customLocationName=$CUSTOM_LOCATION_NAME aepName=$AEP_NAME
287-
```
288-
289-
The following snippet shows the bicep file that you used to create the asset:
290-
291-
:::code language="bicep" source="~/azure-iot-operations-samples/samples/media-connector-bicep/asset-snapshot-to-mqtt.bicep":::
292-
293-
---
61+
1. On the **Summary** page, review the details of the device and select **Create** to create the asset.
29462

295-
To verify that snapshots are publishing to the MQTT broker, use the **mosquitto_sub** tool. In this example, you run the **mosquitto_sub** tool inside a pod in your Kubernetes cluster:
63+
1. After the device is created, you can view it in the **Devices** list:
29664

297-
1. Run the following command to deploy a pod that includes the **mosquitto_pub** and **mosquitto_sub** tools that are useful for interacting with the MQTT broker in the cluster:
65+
:::image type="content" source="media/howto-use-http-connector/http-connector-device-created.png" alt-text="Screenshot that shows the list of devices." lightbox="media/howto-use-http-connector/http-connector-device-created.png":::
29866

299-
```console
300-
kubectl apply -f https://raw.githubusercontent.com/Azure-Samples/explore-iot-operations/main/samples/quickstarts/mqtt-client.yaml
301-
```
67+
## Create a namespace asset
30268

303-
> [!CAUTION]
304-
> This configuration isn't secure. Don't use this configuration in a production environment.
69+
To define a namespace asset that publishes data points from the HTTP endpoint, follow these steps:
30570

306-
1. When the **mqtt-client** pod is running, run the following command to create a shell environment in the pod you created:
71+
1. In the operations experience web UI, select **Assets** in the left navigation pane. Then select **Create namespace asset**.
30772

308-
```console
309-
kubectl exec --stdin --tty mqtt-client -n azure-iot-operations -- sh
310-
```
73+
1. Select the inbound endpoint for the connector for REST/HTTP that you created in the previous section.
31174

312-
1. At the Bash shell in the **mqtt-client** pod, run the following command to connect to the MQTT broker using the **mosquitto_sub** tool subscribed to the `azure-iot-operations/data` topic:
75+
1. Enter a name for your asset, such as `my-http-source`.
31376

314-
```bash
315-
mosquitto_sub --host aio-broker --port 18883 --topic "azure-iot-operations/data/#" -V 5 -F '%p' -C 1 --cafile /var/run/certs/ca.crt -D CONNECT authentication-method 'K8S-SAT' -D CONNECT authentication-data $(cat /var/run/secrets/tokens/broker-sat) > image.jpeg
316-
```
77+
1. Add any custom properties you want to associate with the asset. For example, you might add a property to indicate the manufacturer of the camera. Select **Next** to continue.
31778

318-
This command captures the raw payload from a single message and saves it to a file called **image.jpeg** in the pod's filing system. To exit the pod's shell environment, type `exit`.
79+
1. On the **Data points** page, select **Add data point** to add a data point for the asset. For example:
31980

320-
1. To copy the image file from the pod to your local machine, run the following command:
81+
:::image type="content" source="media/howto-use-http-connector/add-data-point.png" alt-text="Screenshot that shows how to add a data point for HTTP source." lightbox="media/howto-use-http-connector/add-data-point.png":::
32182

322-
```console
323-
kubectl cp azure-iot-operations/mqtt-client:image.jpeg image.jpeg
324-
```
83+
Add details for each data point to publish to the MQTT broker. Then select **Next** to continue.
32584

326-
When you finish testing the asset, you can delete it by running the following command:
85+
1. On the **Review** page, review the details of the asset and select **Create** to create the asset. After a few minutes, the asset is listed on the **Assets** page:
32786

328-
```console
329-
az iot ops asset delete -n asset-snapshot-to-mqtt -g $RESOURCE_GROUP
330-
```
87+
:::image type="content" source="media/howto-use-http-connector/http-asset-created.png" alt-text="Screenshot that shows the list of assets." lightbox="media/howto-use-http-connector/http-asset-created.png":::
59.6 KB
Loading
52.6 KB
Loading
66.4 KB
Loading
81.2 KB
Loading

0 commit comments

Comments
 (0)