Skip to main content
Version: 2.8

Publisher Configuration

AzureIoTClient Publisher Configuration

Each publisher instance represents an Azure IoT Client dedicated publishing data to the Azure IoT platform. Each publisher has its own configuration.

The Host name of the Global Device Endpoint must be set in the property Connection.

The following table contains the specific properties of the AzureIoTClientPlugin Publisher configuration. It extends the general DataLogger publisher configuration documented in Common DataLogger Configuration.

ParameterDescriptionData Type
CertificateFileCertificate file for secure communication with the IoT Hub using a X509 certificateSystem.String
CertificatePasswordCertificate password.System.String
DeviceIdId of the device in Azure IoTSystem.String
IdScopeID ScopeSystem.String
PrimaryKeyPrimary key for SAS communicationSystem.String
SecondaryKeySecondary key for SAS communicationSystem.String
TransportTypeDifferent transport types are supported. Possible values are: Amqp (default), Http1, Amqp_WebSocket_Only, Amqp_Tcp_Only, Mqtt, Mqtt_WebSocket_Only, Mqtt_Tcp_Only.

Example

{
"Disabled": false,
"Publishers": [
{
"Id": "c3cb496b-a24c-43f4-b781-04b36029c2f8",
"Name": "SingleValuePublisher",
"Connection": "global.azure-devices-provisioning.net",
"DeviceId": "MyDevice",
"IdScope": "<input your id scope here>",
"PrimaryKey": "<input your primary key here>",
"SecondaryKey": "<input your secondary key here>",
"TransportType": "Amqp",
"NetworkTimeout": 20,
"PayloadScriptFile": "AzureIoTPayload.cs",
"SamplerType": "OnlyLastValue",
"SamplingRate": 30,
"PayloadDumpEnabled": true,
"PayloadDumpFileName": "$(AppConfig:CommonAppPath)AzureClientDumps\\SingleValuePublisher.log",
"PayloadDumpRetentionTime": 2,
"DataSets": [
{
"Name": "DataSet",
"Type": "DataNode",
"NodeFilter": "node.hasProperty<string>(\"EnableAmqp\", \"1\")",
"Fields": [
{
"Name": "Id",
"DataType": "System.String",
"Query": "item.GlobalId"
},
{
"Name": "Value",
"DataType": "System.String",
"Query": "item.Value"
},
{
"Name": "State",
"DataType": "System.Int32",
"Query": "item.DataState"
},
{
"Name": "TimeStamp",
"DataType": "System.DateTime",
"Query": "item.TimeStamp"
},
{
"Name": "SensorName",
"DataType": "System.String",
"Query": "item.Node.Name"
},
{
"Name": "DeviceId",
"DataType": "System.Guid",
"Query": "item.Node.getProperty<Guid>(\"DeviceId\")"
}
]
}
]
}
]
}

Publisher Payload Scripting

HumanOS® Azure IoT Client offers a simple C# script to design the payload out of the data sets.

The script file is placed in the common app path under .\Config\HumanOS.PeSeL.AzureIoTClient. The name of the script file must be specified in the publisher configuration.

The script is derived by the TAbstractDataLoggerScriptObject<byte[]>. The byte[] indicates that the payload is binary, that is a byte array.

Following example shows how to transform a data set into a JSON format, then transforming it into a byte array.

namespace MyNameSpace
{
/// <summary>
/// Script defining the payload
/// </summary>
public class TAzureIoTPayload : TAbstractDataLoggerScriptObject<byte[]>
{
///<see cref="TAbstractDataLoggerScriptObject{T}"/>
public override void initialize(IKernelAccess Kernel, TPayloadProcessingContext Context)
{
TLogger.writeInfo("AzureIoTPayload script initialized");
}

///<see cref="TAbstractDataLoggerScriptObject{T}"/>
public override void postProcess(IKernelAccess Kernel, TPayloadProcessingContext Context)
{
}

///<see cref="TAbstractDataLoggerScriptObject{T}"/>
public override byte[][] processPayload(IKernelAccess Kernel, TPayloadProcessingContext Context, List<TDataSet> lstDatasets)
{
List<byte[]> lstRetval = new List<byte[]>();
foreach (TDataSet DataSet in lstDatasets)
{
m_iCounter++;

JObject Content = new JObject();

Content.Add(new JProperty("messageId", m_iCounter));
Content.Add(new JProperty("deviceId", DataSet.getFieldValue<Guid>("DeviceId")));
Content.Add(new JProperty("sensorId", DataSet.getFieldValue<Guid>("Id")));
Content.Add(new JProperty("sensorName", DataSet.getFieldValue<string>("SensorName")));
Content.Add(new JProperty("sensorValue", DataSet.getFieldValue<string>("Value")));
Content.Add(new JProperty("sensorState", DataSet.getFieldValue<string>("State")));
Content.Add(new JProperty("timestamp", DataSet.getFieldValue<DateTime>("TimeStamp").ToString("o")));

lstRetval.Add(Encoding.UTF8.GetBytes(Content.ToString()));
}

return lstRetval.ToArray();
}

private int m_iCounter = 0;
}
}

The payload script must conform the data set specification in the settings.json file. The upper example uses following data set configuration:

{
"Name": "DataSet",
"Type": "DataNode",
"NodeFilter": "node.hasProperty<string>(\"EnableAmqp\", \"1\")",
"Fields": [
{
"Name": "Id",
"DataType": "System.String",
"Query": "item.GlobalId"
},
{
"Name": "Value",
"DataType": "System.String",
"Query": "item.Value"
},
{
"Name": "State",
"DataType": "System.Int32",
"Query": "item.DataState"
},
{
"Name": "TimeStamp",
"DataType": "System.DateTime",
"Query": "item.TimeStamp"
},
{
"Name": "SensorName",
"DataType": "System.String",
"Query": "item.Node.Name"
},
{
"Name": "DeviceId",
"DataType": "System.Guid",
"Query": "item.Node.getProperty<Guid>(\"DeviceId\")"
}
]
}