page_type | description | products | languages | |||
---|---|---|---|---|---|---|
python and linux script |
Configure and deploy IoT Edge on STM32MP1 board |
|
|
- Azure account: Bring your own Azure account to keep all your dev works. or apply one for trial https://azure.microsoft.com/en-us/free/
- Install VS Code: https://code.visualstudio.com/download
- Install Azure IoT Explorer: https://github.com/Azure/azure-iot-explorer/releases. How to use: https://docs.microsoft.com/en-us/azure/iot-pnp/howto-use-iot-explorer
- Install extensiton for VS code Azure IoT tools: https://marketplace.visualstudio.com/items?itemName=vsciot-vscode.azure-iot-tools vsciot-vscode.azure-iot-edge vsciot-vscode.azure-iot-toolkit
- Connection your board with USB, have your STCubeProgrammer read on your host computer
- Copy flashed image from One drive [place link here] to your local host. Unzip to folder "stm32mp1"
- Copy the stm32mp1 folder in c:\
- Open a command prompt terminal ("cmd")
- Move to c:\stm32mp1 directory ("cd cd:\stm32mp1")
- Type the following command <path_to_STM32CubeProgrammer_installation_directory>\bin\STM32_Programmer_CLI.exe -c port=usb1 -w c:\stm32mp1\flashlayout_st-image-weston\trusted\FlashLayout_sdcard_stm32mp157a-dk1-trusted.tsv
For example:
"C:\Program Files (x86)\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin\STM32_Programmer_CLI.exe" -c port=usb1 -w c:\stm32mp1\flashlayout_st-image-weston\trusted\FlashLayout_sdcard_stm32mp157a-dk1-trusted.tsv
- After completing flash, swith board to "on", restart it
-
Create IoT Hub. Ignore if you have your own Hub already. Follow below link. https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-create-through-portal?view=iotedge-2018-06
-
Register an IoT Edge device
Create a device identity for your IoT Edge device so that it can communicate with your IoT hub. The device identity lives in the cloud, and you use a unique device connection string to associate a physical device to a device identity.
[Azure Portal] Goes to your IOT Hub, click IoT Edge link in left hand navigator. Click "Add an IoT Edge Device" in top area.
Input "Device ID": my-iotworkshop-edge01, click "Save". Reclick the new edge "my-iotworkshop-edge01" created, copy the "primary connection string", save to your notepad to use later.
-
Switch your new flashed board to "on"
-
Connect your board to internet, either via Ethernet or Wifi dongle
-
Network SSH or use Tera Term to terminal to connect to your board
PC> ssh root@your_board_ip_address
PC> cd /etc/iotedge
PC> cp ./config.yaml ./config.yaml.orig
-
Input the previous Edge connection string to config.yaml file below. Also modify hostname.
PC> vi ./config.yaml
-- Manual provisioning configuration provisioning: source: "manual" device_connection_string: ""
-- Sample connection string as below HostName=yourhub.azure-devices.net;DeviceId=my-iotworkshop-edge01;SharedAccessKey=yourkey
--
Then, save config.yaml
-
Restart your edge to take effect
PC> systemctl restart iotedge
It will take around 3 - 5 mins for yor edge to download firat IoT Edge module, edgeAgent
-
Some usful commands to check your edge status
PC> systemctl status iotedge PC> iotedge list PC> iotedge logs -f edgeAgent
- Open your VS code
Git clone https://github.com/philipcaffeine/azureiot-stm32mp1
- Connect your VS code to IoT Hub
Copy IoT Hub string from Azure Portal. Open Azure Portal, click your Iot Hub, click "Shared access policies" in left hand side. Select "iothubowner", copy the "connection string-primary key" to notepad.
Open your VS code, in command platte, select "Azure IOT Hub, set connection string"
- Deployment new edge modules via VS code commitcommitcin
First to replace the password get from your instructor.
also, create a new folder for binding
cd /home/root
mkdir sensor
also, create a new folder for binding
cd /home/root/sensor
mkdir output
Right click "deployment.template.local.json" to generate the deployment to your edge device.
-
You can watch logs from edgeAgent to check installation progesss as well
PC> iotedge logs -f edgeAgent
-
Verify if your IoT Hub is getting telemetry from Edge module to Hub
Open Azure IoT Explorer from your laptop. Add new connection from your previous "IOT Hub conenctrion string"
Click the previous created Edge from list. Click "Telemetry" from left hand navigator. Click start to monitor the data.
- Create Stream Analytics Job in Azure Portal
provide name and region.
- Create consumer group in your IoT Hub
Select "Build in endpoint" from IoT Hub, and crreate a new consume group, naming like "stsajob01consume"
- Configure Stream Analytics Job
Add "input" from left hand side, select "IoT Hub"
Leave all default value, just provide "input alias" and select the consumer group just created
Add "Output", and select "PowerBI"
Authorize with your existing Power BI account, or "Sign up" a free 60 days trial account.
Add output alias, choose Power BI workspace, input dataset and table name. Select "user token" as authentication method.
Select "Query", and add below query string:
SELECT
machine.temperature as mTemperature,
machine.pressure as mPressure,
ambient.temperature as aTemperature,
ambient.humidity as aHumidity,
timeCreated
INTO
[stmp1powerbi]
FROM
[phil-iothub01]
Back to "overview" and click "start".
- View streaming dataset in PowerBi.com
Navigate link of https://powerbi.microsoft.com Sign in with account just created.
Select your workspace.
Found there is a new dataset just generated.
Add new dashboard from it.
Add a tile in your dashboard
Select real time dataset
Select the new dataset from stmp1 board
Select "clustered column chart", Axis "timeCreated", values as "mTemparature", and time windows as "last 1 minute" to display
You can add more real time tiles into same dashboard as you want.