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
Copy file name to clipboardExpand all lines: articles/iot-edge/tutorial-develop-for-linux.md
+48-48Lines changed: 48 additions & 48 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ description: This tutorial walks through setting up your development machine and
4
4
author: PatAltimore
5
5
6
6
ms.author: patricka
7
-
ms.date: 03/30/2023
7
+
ms.date: 03/31/2023
8
8
ms.topic: tutorial
9
9
ms.service: iot-edge
10
10
services: iot-edge
@@ -36,16 +36,15 @@ The IoT Edge module that you create in this tutorial filters the temperature dat
36
36
A development machine:
37
37
38
38
* Use your own computer or a virtual machine.
39
-
* Your development machine must support [nested virtualization](/virtualization/hyper-v-on-windows/user-guide/nested-virtualization) for running a container engine that you'll install in the next section.
39
+
* Your development machine must support [nested virtualization](/virtualization/hyper-v-on-windows/user-guide/nested-virtualization) for running a container engine.
40
40
* Most operating systems that can run a container engine can be used to develop IoT Edge modules for Linux devices. This tutorial uses a Windows computer, but points out known differences on macOS or Linux.
41
41
* Install [Git](https://git-scm.com/), to pull module template packages later in this tutorial.
42
-
43
42
* Install [Visual Studio Code](https://code.visualstudio.com/)
44
43
* Install the [Azure CLI](/cli/azure/install-azure-cli).
45
44
46
45
An Azure IoT Edge device:
47
46
48
-
* You shoul run IoT Edge on a separate device. This distinction between development machine and IoT Edge device simulates a true deployment scenario and helps keep the different concepts separate.
47
+
* You should run IoT Edge on a separate device. This distinction between development machine and IoT Edge device simulates a true deployment scenario and helps keep the different concepts separate.
49
48
Use the quickstart article [Deploy code to a Linux Device](quickstart-linux.md) to create an IoT Edge device in Azure.
50
49
51
50
Cloud resources:
@@ -140,37 +139,36 @@ Install tools specific to the language you're developing in:
*[C# Visual Studio Code extension](https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csharp)
145
144
146
145
# [C](#tab/c)
147
146
148
-
- Install [C/C++ Visual Studio Code extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools)
149
-
150
-
Installing the Azure IoT C SDK isn't required for this tutorial, but can provide helpful functionality like intellisense and reading program definitions. For installation information, see [Azure IoT C SDKs and Libraries](https://github.com/Azure/azure-iot-sdk-c).
147
+
*[C/C++ Visual Studio Code extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools)
148
+
* Installing the Azure IoT C SDK isn't required for this tutorial, but can provide helpful functionality like intellisense and reading program definitions. For installation information, see [Azure IoT C SDKs and Libraries](https://github.com/Azure/azure-iot-sdk-c).
151
149
152
150
# [Java](#tab/java)
153
151
154
-
- Install[Java SE Development Kit 11](/azure/developer/java/fundamentals/java-support-on-azure) and [Maven](https://maven.apache.org/). You need to [set the `JAVA_HOME` environment variable](https://docs.oracle.com/cd/E19182-01/820-7851/inst_cli_jdk_javahome_t/) to point to your JDK installation.
155
-
-[Maven](https://maven.apache.org/)
156
-
- Install[Java Extension Pack for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-pack)
152
+
*[Java SE Development Kit 11](/azure/developer/java/fundamentals/java-support-on-azure) and [Maven](https://maven.apache.org/). You need to [set the `JAVA_HOME` environment variable](https://docs.oracle.com/cd/E19182-01/820-7851/inst_cli_jdk_javahome_t/) to point to your JDK installation.
153
+
*[Maven](https://maven.apache.org/)
154
+
*[Java Extension Pack for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-pack)
157
155
158
156
>[!TIP]
159
157
>The Java and Maven installation processes add environment variables to your system. Restart any open Visual Studio Code terminal, PowerShell, or command prompt instances after completing installation. This step ensures that these utilities can recognize the Java and Maven commands going forward.
*[Python extension for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=ms-python.python).
174
172
175
173
>[!Note]
176
174
>Ensure that your `bin` folder is on your path for your platform. Typically `~/.local/` for UNIX and macOS, or `%APPDATA%\Python` on Windows.
@@ -402,7 +400,7 @@ The sample C# code that comes with the project template uses the [ModuleClient C
402
400
403
401
1. Find the **Init** function. This functioncreates and configures a **ModuleClient** object, which allows the module to connect to the local Azure IoT Edge runtime to send and receive messages. After creating the **ModuleClient**, the code reads the **temperatureThreshold** value from the module twin's desired properties. The code registers a callback to receive messages from an IoT Edge hub via an endpoint called **input1**.
404
402
405
-
Replace the **SetInputMessageHandlerAsync** method with a new one that updates the name of the endpoint and the method that is called when input arrives. Also, add a **SetDesiredPropertyUpdateCallbackAsync** method for updates to the desired properties. To make this change, replace the last line of the **Init** method with the following code:
403
+
Replace the **SetInputMessageHandlerAsync** method with a new one that updates the name of the endpoint and the method that's called when input arrives. Also, add a **SetDesiredPropertyUpdateCallbackAsync** method for updates to the desired properties. To make this change, replace the last line of the **Init** method with the following code:
406
404
407
405
```csharp
408
406
// Register a callback for messages that are received by the module.
@@ -507,7 +505,7 @@ The sample C# code that comes with the project template uses the [ModuleClient C
507
505
}
508
506
```
509
507
510
-
1. Save the ModuleBackgroundService.cs file.
508
+
1. Save the **ModuleBackgroundService.cs** file.
511
509
512
510
1. In the Visual Studio Code explorer, open the **deployment.template.json** file in your IoT Edge solution workspace.
513
511
@@ -537,7 +535,7 @@ The sample C# code that comes with the project template uses the [ModuleClient C
537
535
538
536
1. Download the [Parson GitHub repository](https://github.com/kgabis/parson). Copy the **parson.c** and **parson.h** files into the **filtermodule** folder.
539
537
540
-
2. Open **modules**>**filtermodule**>**CMakeLists.txt**. At the top of the file, import the Parson files as a library called **my_parson**.
538
+
1. Open **modules** > **filtermodule** > **CMakeLists.txt**. At the top of the file, import the Parson files as a library called **my_parson**.
541
539
542
540
```txt
543
541
add_library(my_parson
@@ -546,11 +544,11 @@ The sample C# code that comes with the project template uses the [ModuleClient C
546
544
)
547
545
```
548
546
549
-
3. Add `my_parson` to the list of libraries in the **target_link_libraries**functionof CMakeLists.txt.
547
+
1. Add `my_parson` to the list of libraries in the **target_link_libraries** function of CMakeLists.txt.
550
548
551
-
4. Save the **CMakeLists.txt** file.
549
+
1. Save the **CMakeLists.txt** file.
552
550
553
-
5. Open **modules**>**filtermodule**>**main.c**. At the bottom of the list of include statements, add a new one to include `parson.h`for JSON support:
551
+
1. Open **modules** > **filtermodule** > **main.c**. At the bottom of the list of include statements, add a new one to include `parson.h` for JSON support:
554
552
555
553
```c
556
554
#include "parson.h"
@@ -701,7 +699,7 @@ The sample C# code that comes with the project template uses the [ModuleClient C
701
699
}
702
700
```
703
701
704
-
1. Save the main.c file.
702
+
1. Save the **main.c** file.
705
703
706
704
1. In the Visual Studio Code explorer, open the **deployment.template.json** file in your IoT Edge solution workspace.
707
705
@@ -721,7 +719,7 @@ The sample C# code that comes with the project template uses the [ModuleClient C
721
719
722
720
1. In the Visual Studio Code explorer, open **modules**>**filtermodule**>**src**>**main**>**java**>**com**>**edgemodule**>**App.java**.
723
721
724
-
2. Add the following code at the top of the file to import new referenced classes.
722
+
1. Add the following code at the top of the file to import new referenced classes.
725
723
726
724
```java
727
725
import java.io.StringReader;
@@ -738,14 +736,14 @@ The sample C# code that comes with the project template uses the [ModuleClient C
3. Add the following definition into class **App**. This variable sets a temperature threshold. The measured machine temperature won't be reported to IoT Hub until it goes over this value.
739
+
1. Add the following definition into class **App**. This variable sets a temperature threshold. The measured machine temperature won't be reported to IoT Hub until it goes over this value.
742
740
743
741
```java
744
742
private static final String TEMP_THRESHOLD = "TemperatureThreshold";
745
743
private static AtomicLong tempThreshold = new AtomicLong(25);
746
744
```
747
745
748
-
4. Replace the execute method of **MessageCallbackMqtt** with the following code. This method is called whenever the module receives an MQTT message from the IoT Edge hub. It filters out messages that report temperatures below the temperature threshold set via the module twin.
746
+
1. Replace the execute method of **MessageCallbackMqtt** with the following code. This method is called whenever the module receives an MQTT message from the IoT Edge hub. It filters out messages that report temperatures below the temperature threshold set via the module twin.
749
747
750
748
```java
751
749
protected static class MessageCallbackMqtt implements MessageCallback {
@@ -779,7 +777,7 @@ The sample C# code that comes with the project template uses the [ModuleClient C
779
777
}
780
778
```
781
779
782
-
5. Add the following two static inner classes into class **App**. These classes update the tempThreshold variable when the module twin's desired property changes. All modules have their own module twin, which lets you configure the code that's running inside a module directly from the cloud.
780
+
1. Add the following two static inner classes into class **App**. These classes update the tempThreshold variable when the module twin's desired property changes. All modules have their own module twin, which lets you configure the code that's running inside a module directly from the cloud.
783
781
784
782
```java
785
783
protected static class DeviceTwinStatusCallBack implements IotHubEventCallback {
@@ -807,7 +805,7 @@ The sample C# code that comes with the project template uses the [ModuleClient C
807
805
}
808
806
```
809
807
810
-
6. Add the following lines in to **main** method after **client.open()** to subscribe the module twin updates.
808
+
1. Add the following lines in to **main** method after **client.open()** to subscribe the module twin updates.
811
809
812
810
```java
813
811
client.startTwin(new DeviceTwinStatusCallBack(), null, new OnProperty(), null);
@@ -820,11 +818,11 @@ The sample C# code that comes with the project template uses the [ModuleClient C
820
818
client.getTwin();
821
819
```
822
820
823
-
7. Save the **App.java** file.
821
+
1. Save the **App.java** file.
824
822
825
-
8. In the Visual Studio Code explorer, open the **deployment.template.json** file in your IoT Edge solution workspace.
823
+
1. In the Visual Studio Code explorer, open the **deployment.template.json** file in your IoT Edge solution workspace.
826
824
827
-
9. Add the **filtermodule** module twin to the deployment manifest. Insert the following JSON content at the bottom of the **moduleContent** section, after the **$edgeHub** module twin:
825
+
1. Add the **filtermodule** module twin to the deployment manifest. Insert the following JSON content at the bottom of the **moduleContent** section, after the **$edgeHub** module twin:
828
826
829
827
```json
830
828
"filtermodule": {
@@ -834,20 +832,20 @@ The sample C# code that comes with the project template uses the [ModuleClient C
834
832
}
835
833
```
836
834
837
-
10. Save the **deployment.template.json** file.
835
+
1. Save the **deployment.template.json** file.
838
836
839
837
840
838
# [Node.js](#tab/node)
841
839
842
840
1. In the Visual Studio Code explorer, open **modules** > **filtermodule** > **app.js**.
843
841
844
-
2. Add a temperature threshold variable below required node modules. The temperature threshold sets the value that the measured temperature must exceed in order for the data to be sent to IoT Hub.
842
+
1. Add a temperature threshold variable below required node modules. The temperature threshold sets the value that the measured temperature must exceed in order for the data to be sent to IoT Hub.
845
843
846
844
```javascript
847
845
var temperatureThreshold = 25;
848
846
```
849
847
850
-
3. Replace the entire `PipeMessage`functionwith the `FilterMessage` function.
848
+
1. Replace the entire `PipeMessage` function with the `FilterMessage` function.
851
849
852
850
```javascript
853
851
// This function filters out messages that report temperatures below the temperature threshold.
@@ -868,15 +866,15 @@ The sample C# code that comes with the project template uses the [ModuleClient C
868
866
869
867
```
870
868
871
-
4. Replace the functionname`pipeMessage` with `filterMessage`in`client.on()` function.
869
+
1. Replace the function name `pipeMessage` with `filterMessage` in `client.on()` function.
872
870
873
871
```javascript
874
872
client.on('inputMessage', function (inputName, msg) {
875
873
filterMessage(client, inputName, msg);
876
874
});
877
875
```
878
876
879
-
5. Copy the following code snippet into the `client.open()`functioncallback, after `client.on()` inside the `else` statement. This functionis invoked when the desired properties are updated.
877
+
1. Copy the following code snippet into the `client.open()` function callback, after `client.on()` inside the `else` statement. This function is invoked when the desired properties are updated.
880
878
881
879
```javascript
882
880
client.getTwin(function (err, twin) {
@@ -892,11 +890,11 @@ The sample C# code that comes with the project template uses the [ModuleClient C
892
890
});
893
891
```
894
892
895
-
6. Save the **app.js** file.
893
+
1. Save the **app.js** file.
896
894
897
-
7. In the Visual Studio Code explorer, open the **deployment.template.json** file in your IoT Edge solution workspace.
895
+
1. In the Visual Studio Code explorer, open the **deployment.template.json** file in your IoT Edge solution workspace.
898
896
899
-
8. Add the filtermodule module twin to the deployment manifest. Insert the following JSON content at the bottom of the `moduleContent` section, after the `$edgeHub` module twin:
897
+
1. Add the filtermodule module twin to the deployment manifest. Insert the following JSON content at the bottom of the `moduleContent` section, after the `$edgeHub` module twin:
900
898
901
899
```json
902
900
"filtermodule": {
@@ -906,7 +904,7 @@ The sample C# code that comes with the project template uses the [ModuleClient C
[Push](https://docs.docker.com/engine/reference/commandline/push/) your module image to the local registry or a container registry.
1100
1098
1101
-
`docker push <ImageName>`
1099
+
```bash
1100
+
docker push <ImageName>
1101
+
```
1102
1102
1103
1103
For example:
1104
1104
@@ -1179,7 +1179,7 @@ To further verify what the build and push command did, go to the [Azure portal](
1179
1179
1180
1180
In your container registry, select**Repositories**then**samplemodule**. Verify that both versions of the image push to the registry.
1181
1181
1182
-
:::image type="content" source="./media/tutorial-develop-for-linux/view-repository-versions.png" alt-text="Screenshot of where to view both image versions in your container registry." lightbox="./media/tutorial-develop-for-linux/view-repository-versions.png":::
1182
+
:::image type="content" source="./media/tutorial-develop-for-linux/view-repository-versions.png" alt-text="Screenshot of where to view both image versions in your container registry." lightbox="./media/tutorial-develop-for-linux/view-repository-versions.png":::
1183
1183
1184
1184
<!--Alternative steps: Use Visual Studio Code Docker tools to view ACR images with tags-->
1. In the Visual Studio Code explorer, under the **Azure IoT Hub** section, expand **Devices** to see your list of IoT devices.
1216
1216
1217
-
2. Right-click the IoT Edge device that you want to deploy to, then select **Create Deployment for Single Device**.
1217
+
1. Right-click the IoT Edge device that you want to deploy to, thenselect**Create Deployment for Single Device**.
1218
1218
1219
1219
:::image type="content" source="./media/tutorial-develop-for-linux/create-deployment.png" alt-text="Screenshot showing how to create a deployment for a single device.":::
1220
1220
1221
-
3. In the file explorer, navigate into the **config** folder then select the **deployment.amd64.json** file.
1221
+
1. In the file explorer, navigate into the **config** folder thenselectthe**deployment.amd64.json** file.
1222
1222
1223
1223
Don't use the deployment.template.json file, which doesn't have the container registry credentials or module image values in it. If you target a Linux ARM32 device, the deployment manifest's name is **deployment.arm32v7.json**.
1224
1224
1225
-
4. Under your device, expand **Modules** to see a list of deployed and running modules. Select the refresh button. You should see the new SimulatedTemperatureSensor and SampleModule modules running on your device.
1225
+
1. Under your device, expand **Modules** to see a list of deployed and running modules. Select the refresh button. You should see the new SimulatedTemperatureSensor and SampleModule modules running on your device.
1226
1226
1227
1227
It may take a few minutes for the modules to start. The IoT Edge runtime needs to receive its new deployment manifest, pull down the module images from the container runtime, then start each new module.
1228
1228
@@ -1234,7 +1234,7 @@ The SampleModule code receives messages through its input queue and passes them
1234
1234
1235
1235
1. In the Visual Studio Code explorer, right-click the IoT Edge device that you want to monitor, then select **Start Monitoring Built-in Event Endpoint**.
1236
1236
1237
-
2. Watch the output window in Visual Studio Code to see messages arriving at your IoT hub.
1237
+
1. Watch the output window in Visual Studio Code to see messages arriving at your IoT hub.
1238
1238
1239
1239
:::image type="content" source="./media/tutorial-develop-for-linux/view-d2c-messages.png" alt-text="Screenshot showing where to view incoming device to cloud messages.":::
0 commit comments