Send temperature sensor module messages from lower layer device to upper layer device in Azure IoT - azure-iot-edge

Scenario is to build a hierarchy of IoT devices and at the upper layer I need to receive the messages send from the child device. I have tried giving BrokeredEndpoint at the routes in the deployment.json file in the upper layer at the input.
My code
"routes": {
"pythondepmoduleToIoTHub": "FROM /messages/modules/pythondepmodule/outputs/* INTO $upstream",
"sensorTopythondepmodule": "FROM /messages/modules/childdeviceModule/outputs/output INTO BrokeredEndpoint("/modules/pythondepmodule/inputs/input1")"
},
At the upper layer(deployment.json file)
"routes": {
"childdeviceModuleToIoTHub": "FROM /messages/modules/childdeviceModule/outputs/* INTO $upstream",
"sensorTochilddeviceModule": "FROM /messages/modules/SimulatedTemperatureSensor/outputs/temperatureOutput INTO BrokeredEndpoint("/modules/childdeviceModule/inputs/input1")"
},
At the lower layer

Related

Azure IoT Hub - Publish and subscribe to same MQTT topic

I want to publish a message to IoT Hub and also receive the message via the same topic. I connected to IoT Hub and then subscribed to the same topic to which i send the messages, but I don't receive any message. As Client I am using MQTTX windows. Messages are sent and received correctly at the cloud endpoint (telemetry data). Here is a screenshot from my MQTT client: MQTT Client
I see you are using MQTTX as a leaf device to IoT Edge in a transparent gateway pattern, where edge will just pass through messages to IoTHub.
IoTHub does not support custom topic or respond back on the same topic so this "devices/plc2/messages/events/topic" will not work
Subscription to devices/{device_id}/messages/devicebound/# will work but you will need to explicitly send C2D message for that device_id as a response
The Azure IoT Hub is not a generic MQTT broker, see more details here.
I do recommend to read also the doc for Azure IoT Edge MQTT broker.
UPDATE:
Based on your needs, such as a round trip time test, the following is an example how can be achieved this loopback in the Azure IoT Central. Note, that the Iot Central App has a built-in great features to simplify your test without using additional azure resource such as an Azure function.
The concept of this example is based on the following:
REST API for invoking a durable command (Queuing command) to generate a C2D Message.
Using the Data Transformation for exporting a message to the webhook destination
First of all, we have to create a device template (in my example loopback) for our test:
{
"#id": "dtmi:rk2022iotcfree:loopback_24v;1",
"#type": "Interface",
"contents": [
{
"#id": "dtmi:rk2022iotcfree:loopback_24v:message;1",
"#type": "Command",
"displayName": {
"en": "Message"
},
"name": "message",
"request": {
"#type": "CommandPayload",
"displayName": {
"en": "Info"
},
"name": "Info",
"schema": {
"#type": "Object",
"displayName": {
"en": "Object"
},
"fields": [
{
"displayName": {
"en": "ts"
},
"name": "ts",
"schema": "dateTime"
},
{
"displayName": {
"en": "msg"
},
"name": "msg",
"schema": "string"
}
]
}
},
"durable": true
},
{
"#id": "dtmi:rk2022iotcfree:loopback_24v:counter;1",
"#type": "Telemetry",
"displayName": {
"en": "Counter"
},
"name": "counter",
"schema": "double"
},
{
"#id": "dtmi:rk2022iotcfree:loopback_24v:time;1",
"#type": "Telemetry",
"displayName": {
"en": "Timestamp"
},
"name": "time",
"schema": "double"
}
],
"displayName": {
"en": "loopback"
},
"#context": [
"dtmi:iotcentral:context;2",
"dtmi:dtdl:context;2"
]
}
Once we have the device template, we can create a device (in my example device1) with assigning to this device template (loopback).
Now, we need to declare a destination webhook endpoint:
where the Callback URL is:
https://2a92220d-42e3-4a73-b700-2cb858c9c5e7.azureiotcentral.com/api/devices/device1/commands/message?api-version=1.2-preview
and the Authorization token is generated as the IoT Central Api token
Next step is declaring a Data transformation for this destination endpoint:
import "iotc" as iotc;
if .device.id == "device1" then
{
request: {
Info:{
ts:.enqueuedTime,
msg:("Feedback from device: id=" + .device.id + ", counter=" + (.telemetry | iotc::find(.name == "counter").value | tostring) + ", time=" + (.telemetry | iotc::find(.name == "time").value | tostring))
}
}
}
else
empty
end
That's all at the IoT Central App. Based on the above Data transformation, any received telemetry data message from the device1 is exported to the webhook endpoint for invoking a C2D message.
In my example, for the device side is used my tool for virtual MQTT device (either the Azure IoT Hub Tester or Azure IoT Central Tester), but it can be used any other similar tool or MQTT client.
As you can see the above screen snippet, the device1 sent the telemetry data such as a counter and time and the device received the C2D message:
As the above screen snippet shows, there are three timestamps. The two highlighted timestamps are represented a round trip time (from the device to the IoT Central and back to the device). The third one is represented a timestamp at the IoT Central app:
Start device: 2022-05-19T13:50:06.4213024Z
IoT Central App: 2022-05-19T13:50:07.107Z
End device: 2022-05-19T13:50:13.6934397Z

MQTT - How to change the behaviour of the default parser for JSON on the CE (SenML)?

I have a gateway fromKhomp manufacturer which delivers packages in the following format (SenML):
message: [
{
"bn": "000D6FFFFE642E09",
"bt": 1611339204
},
{
"n": "model",
"vs": "nir21z"
},
{
"n": "Geladeira Temp",
"u": "Cel",
"v": 4.0
}
When I connect to the Thingsboard platform, the internal GW/Parser breaks as an array before the Input in the Root Rule Chain, and threats as individual packets, but since the first position in this array corresponds to the device ID (MAC) I need to have the whole message to be parser in a script. Does anyone know a way to get the information before the GW parses the message?
If you're using Thingsboard CE then I think you will need to first forward the data to a middleware service to restructure the payload. If you are familiar with AWS Lambda you can do it there.
It would just be a simple script that takes an input payload, restructures, and then forwards to your Thingsboard deployment.
If you're using Thingsboard PE then you can use Integration/Data Converters to do this.

Map custom properties when ingesting IoT hub into ADX

I have the following setup: an IoT Hub ih1 routing messages to Azure Data Explorer adx1. Messages on the IoT hub look like the following:
{
"body": {
{ "value": "myValue" }
},
"messageId": "deadbeef-1234-5678-9abc-0123456789ab",
"properties": {
"myCustomProperty": "myCustomValue"
}
}
(There are more root properties and more custom properties, but the above outline should be clear).
I want to map the custom properties of the IoT Hub message onto a table column. So far, I've only been able to map the system properties and the body property content (in above example: "value": "myValue") to a column.
Using the $.propertyName will only refer to properties within the body property, not on properties on the root of the message.
How can I map custom properties to a column?
Currently this is not implemented in ADX.
As a workaround you can route messages to en Event Hub and then to ADX. Then you should be able to access that properties.
Payload enrichment for IoT Hubs and Event Hubs in ADX is currently not fully implemented and is limited to system properties only.
Full support is on the backlog but we have no ETA at the present time.

FIWARE Metadata in IoTAgent

I try to set up a TTN based LoRaWAN Monitoring of my Gateways and devices inside a FIWARE-Environment. Therefore it would be essential to access data not in payload_field of the MQTT-Broker of TTN.
I wonder if it is possible to access field like counter, port, app_id and metadata.
I did not find a possibility yet. Does any of you face the same problem and got a solution to this challenge?
I use the following relevant FIWARE-components in a docker environment:
fiware/orion:2.2.0
fiware/iotagent-lorawan:1.2.3
mongo:3.6.8
If you need to receive metadata directly from LoRaWAN, you will have to customize the code within the LoRaWAN IoT Agent - this just passes measures by default, but the IoT Agent node lib interface is capable of receiving metadata as well.
Alternatively a recent PR Request for the IoT Agent node lib allows for additional static metadata to be added during the provisioning stage and sent as part of the requests to the context broker. You would need to use the latest development code base as the library hasn't been ported to the LoRaWAN IoT Agent yet - amend the iotagent-node-lib dependency in the package.json as shown:
"dependencies": {
...
"iotagent-node-lib": "git://github.com/telefonicaid/iotagent-node-lib.git#master",
...
},
... etc
The documentation can be found here
Attributes with metadata are provisioned with an additional parameter as shown:
"attributes": [
{"object_id": "s", "name": "state", "type":"Text"},
{"object_id": "l", "name": "luminosity", "type":"Integer",
"metadata":{
"unitCode":{"type": "Text", "value" :"CAL"}
}
}

Best way to send xml from iot device to azure iot hub?

I have an energy monitor that can only output xml data via http post. I am looking to send this data to an azure-iot hub for processing and storage. What is the best way to send xml data to from several of these devices to the hub? I have looked at various gateways but havent found a simple, scalable, cost effective way to do this. I am open to having some sort of intermediary but they all introduce a layer of complexity to simply sending the data to the hub.
Your energy monitor can publish a telemetry data direct to the Azure IoT Hub using a HTTPs protocol.
The following is an example:
and the body:
and the Device Explorer output:
and the blob Storage:
{
"EnqueuedTimeUtc": "2019-09-25T15:58:25.0900000Z",
"Properties": {
"abcd": "abcd1234"
},
"SystemProperties": {
"connectionDeviceId": "device2",
"connectionAuthMethod": "{\"scope\":\"device\",\"type\":\"sas\",\"issuer\":\"iothub\",\"acceptingIpFilterRule\":null}",
"connectionDeviceGenerationId": "636842109368955167",
"contentType": "application/xml",
"contentEncoding": "",
"enqueuedTime": "2019-09-25T15:58:25.0900000Z"
},
"Body": "PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4gDQo8UGFyYUluZm8gPg0KICA8TmFtZT5Wb2x0YWdlPC9OYW1lPg0KICA8Q29kZT5VczwvQ29kZT4NCiAgPFVuaXQ+VjwvVW5pdCA+DQogIDxGcmVxPjQwPC9GcmVxID4NCiAgPFN0YXJ0PjA8L1N0YXJ0Pg0KICA8RW5kPjI4OS41PC9FbmQ+DQo8L1BhcmFJbmZvPg0K"
}
Note, that the body is a Base64 encoded xml text:

Resources