
Hi !
In my previous post I shared some details on how to configure the Azure IoT Module to interact with the sensors / servos / LEDs connected to the Raspberry Pi. I also shared the base code to send telemetry. Let’s add some more details related to the Send Telemetry part.
Send Telemetry
In the code sample below:
- 2 imports are required,
- azure.iot.device.aio import IoTHubModuleClient, to interact with the Azure IoT Module
- azure.iot.device import Message, to create the Azure IoT Hub message to be sent
- A JSON message is created with the 3 door properties, and added as the message body. Lines 13 to 15.
- The message adds also 3 custom properties [action, door state and door state description]. Lines 15 to 18.
To have more details on the class modules and properties, I checked
Sample Messages
This is a sample of 2 messages received and processed in Azure IoT. First message to open the door, second message to close the door.
Tue Aug 17 2021 09:18:00 GMT-0400 (Eastern Daylight Time):
{
"body": {
"action": "Door closed",
"doorState": "0",
"doorStateDesc": "closed"
},
"enqueuedTime": "Tue Aug 17 2021 09:18:00 GMT-0400 (Eastern Daylight Time)",
"properties": {
"action": "Door closed",
"doorState": "0",
"doorStateDesc": "closed"
},
"systemProperties": {
"iothub-connection-device-id": "rpiIoTDoor2",
"iothub-connection-module-id": "DoorController",
"iothub-connection-auth-method": "{\"scope\":\"module\",\"type\":\"sas\",\"issuer\":\"iothub\",\"acceptingIpFilterRule\":null}",
"iothub-connection-auth-generation-id": "637637771398106938",
"iothub-enqueuedtime": 1629206280400,
"iothub-message-source": "Telemetry",
"x-opt-sequence-number": 71,
"x-opt-offset": "4294968816",
"x-opt-enqueued-time": 1629206280463
}
}
Tue Aug 17 2021 09:17:51 GMT-0400 (Eastern Daylight Time):
{
"body": {
"action": "Door opened",
"doorState": "1",
"doorStateDesc": "open"
},
"enqueuedTime": "Tue Aug 17 2021 09:17:51 GMT-0400 (Eastern Daylight Time)",
"properties": {
"action": "Door opened",
"doorState": "1",
"doorStateDesc": "open"
},
"systemProperties": {
"iothub-connection-device-id": "rpiIoTDoor2",
"iothub-connection-module-id": "DoorController",
"iothub-connection-auth-method": "{\"scope\":\"module\",\"type\":\"sas\",\"issuer\":\"iothub\",\"acceptingIpFilterRule\":null}",
"iothub-connection-auth-generation-id": "637637771398106938",
"iothub-enqueuedtime": 1629206271635,
"iothub-message-source": "Telemetry",
"x-opt-sequence-number": 70,
"x-opt-offset": "4294968312",
"x-opt-enqueued-time": 1629206271744
}
}
References
- Seeedstudio, Grove
- Create an IoT hub using the Azure portal
- Tutorial: Develop and deploy a Python IoT Edge module for Linux devices
- Azure Container Registry
Happy coding!
Greetings
El Bruno
More posts in my blog ElBruno.com.
More info in https://beacons.ai/elbruno
Azure ☁ IoT
- Install ☁ Azure IoT on Raspberry Pi
- Deploy ☁ Azure Blob Storage on IoT Edge, lessons learned
- Connect to ☁ Azure Blob Storage on IoT Edge using Microsoft Azure Storage Explorer
- Lesson learned and tips on how to install Azure IoT Edge on Ubuntu on a Raspberry Pi
- Azure IoT Explorer, in preview and awesome
- Mapping a local ☁ Azure IoT Edge folder module with an Edge device folder 📁
- Creating a folder 📂 in the docker definition in an ☁ Azure IoT Edge
- Granting access to Raspberry Pi GPIO from an ☁ Azure IoT Edge Module
Create an Azure IoT Module using Raspberry Pi and Grove Sensors
- Raspberry Pi + Grove Sensors, read temperature and humidity values
- Raspberry Pi + Grove Sensors, send temperature and humidity values as telemetry to Azure IoT Hub
- Raspberry Pi + Grove Sensors, create a Azure IoT Module to send temperature and humidity values as telemetry to Azure IoT Hub
- Raspberry Pi + Grove Sensors, publish and use the Azure IoT Module
- Raspberry Pi + Grove Sensors, notes on build and configuration
- Raspberry Pi + Grove Sensors, details on how to send a telemetry message and sample messages
Create an Azure IoT Module from Azure Custom Vision project
- Create and export a Custom Vision Project as Docker image
- Analyze the content of the CV Docker image
- Create and analyze an Azure IoT Module
- Merge the CV project as an Azure IoT Module
- Deploy to an Azure IoT device and test the CV module
- Send telemetry for each analyzed image
- Add digital twin configuration to the Azure IoT module (coming soon)
¿Con ganas de ponerte al día?
En Lemoncode te ofrecemos formación online impartida por profesionales que se baten el cobre en consultoría:
- Si tienes ganas de ponerte al día con Front End (ES6, Typescript, React, Angular, Vuejs…) te recomendamos nuestros Máster Front End: https://lemoncode.net/master-frontend#inicio-banner
- Si te quieres poner al día en Backend (stacks .net y nodejs), te aconsejamos nuestro Bootcamp Backend: https://lemoncode.net/bootcamp-backend#bootcamp-backend/banner
- Y si tienes ganas de meterte con Docker, Kubernetes, CI/CD…, tenemos nuestro Bootcamp Devops: https://lemoncode.net/bootcamp-devops#bootcamp-devops/inicio