Skip to content

Instantly share code, notes, and snippets.

@rido-min
Last active July 11, 2021 19:36
Show Gist options
  • Select an option

  • Save rido-min/234d7b746b1038314130517b96f25d44 to your computer and use it in GitHub Desktop.

Select an option

Save rido-min/234d7b746b1038314130517b96f25d44 to your computer and use it in GitHub Desktop.
DTDL Maps
{
"@context": "dtmi:dtdl:context;2",
"@id": "dtmi:rido:maps;1",
"@type": "Interface",
"displayName": "maps",
"contents": [
{
"@type": "Property",
"writable": true,
"name": "networkConfig",
"schema": {
"@type": "Map",
"mapKey": {
"name": "name",
"schema": "string"
},
"mapValue": {
"name": "networkAdapter",
"schema": {
"@type": "Object",
"fields": [
{
"name": "AdapterName",
"schema": "string"
},
{
"name": "IPAddress",
"schema": "string"
},
{
"name": "MACAddress",
"schema": "string"
},
{
"name": "DefaultGateway",
"schema": "string"
}
]
}
}
}
}
]
}
class NetworkAdapter
{
public string AdapterName { get; set; }
public string IPAddress { get; set; }
public string MACAddress { get; set; }
public string DefaultGateway { get; set; }
}
Dictionary<string, NetworkAdapter> networkAdapters = new Dictionary<string, NetworkAdapter>
{
{
"Wifi",
new NetworkAdapter
{
AdapterName = "Wifi",
IPAddress = "1.1.1.1",
MACAddress = "A43B32G32FF"
}
},
{
"Eth0",
new NetworkAdapter
{
AdapterName = "eth0",
IPAddress = "2.3.4.5",
MACAddress = "B23B32G32AA"
}
}
};
TwinCollection twin = new TwinCollection();
twin["networkConfig"] = new
{
ac = 100,
av = 1,
value = networkAdapters
};
await dc.UpdateReportedPropertiesAsync(twin);
{
"deviceId": "mapDemo",
"etag": "AAAAAAAAAAc=",
"deviceEtag": "MTAwOTY1OTc4NA==",
"status": "enabled",
"statusUpdateTime": "0001-01-01T00:00:00Z",
"connectionState": "Connected",
"lastActivityTime": "0001-01-01T00:00:00Z",
"cloudToDeviceMessageCount": 0,
"authenticationType": "sas",
"x509Thumbprint": {
"primaryThumbprint": null,
"secondaryThumbprint": null
},
"modelId": "dtmi:rido:maps;1",
"version": 10,
"properties": {
"desired": {
"networkConfig": {
"eth0": {
"AdapterName": "Ethernet 0",
"IPAddress": "3.4.3.5",
"MACAddress": "ADADSFASDFA",
"DefaultGateway": "1.1.1.1"
},
"wifi": {
"AdapterName": "Wi-Fi",
"IPAddress": "5.5.5.5",
"MACAddress": "FFRAFAFRFRd",
"DefaultGateway": "2.2.2.2"
}
},
"$metadata": {
"$lastUpdated": "2021-07-11T19:26:33.3589545Z",
"$lastUpdatedVersion": 7,
"networkConfig": {
"$lastUpdated": "2021-07-11T19:26:33.3589545Z",
"$lastUpdatedVersion": 7,
"eth0": {
"$lastUpdated": "2021-07-11T19:26:33.3589545Z",
"$lastUpdatedVersion": 7,
"AdapterName": {
"$lastUpdated": "2021-07-11T19:26:33.3589545Z",
"$lastUpdatedVersion": 7
},
"IPAddress": {
"$lastUpdated": "2021-07-11T19:26:33.3589545Z",
"$lastUpdatedVersion": 7
},
"MACAddress": {
"$lastUpdated": "2021-07-11T19:26:33.3589545Z",
"$lastUpdatedVersion": 7
},
"DefaultGateway": {
"$lastUpdated": "2021-07-11T19:26:33.3589545Z",
"$lastUpdatedVersion": 7
}
},
"wifi": {
"$lastUpdated": "2021-07-11T19:26:33.3589545Z",
"$lastUpdatedVersion": 7,
"AdapterName": {
"$lastUpdated": "2021-07-11T19:26:33.3589545Z",
"$lastUpdatedVersion": 7
},
"IPAddress": {
"$lastUpdated": "2021-07-11T19:26:33.3589545Z",
"$lastUpdatedVersion": 7
},
"MACAddress": {
"$lastUpdated": "2021-07-11T19:26:33.3589545Z",
"$lastUpdatedVersion": 7
},
"DefaultGateway": {
"$lastUpdated": "2021-07-11T19:26:33.3589545Z",
"$lastUpdatedVersion": 7
}
}
}
},
"$version": 7
},
"reported": {
"networkConfig": {
"ac": 200,
"av": 7,
"value": {
"eth0": {
"AdapterName": "Ethernet 0",
"IPAddress": "3.4.3.5",
"MACAddress": "ADADSFASDFA",
"DefaultGateway": "1.1.1.1"
},
"wifi": {
"AdapterName": "Wi-Fi",
"IPAddress": "5.5.5.5",
"MACAddress": "FFRAFAFRFRd",
"DefaultGateway": "2.2.2.2"
}
}
},
"$metadata": {
"$lastUpdated": "2021-07-11T19:27:18.2555653Z",
"networkConfig": {
"$lastUpdated": "2021-07-11T19:27:18.2555653Z",
"ac": {
"$lastUpdated": "2021-07-11T19:27:18.2555653Z"
},
"av": {
"$lastUpdated": "2021-07-11T19:27:18.2555653Z"
},
"value": {
"$lastUpdated": "2021-07-11T19:27:18.2555653Z",
"eth0": {
"$lastUpdated": "2021-07-11T19:27:18.2555653Z",
"AdapterName": {
"$lastUpdated": "2021-07-11T19:27:18.2555653Z"
},
"IPAddress": {
"$lastUpdated": "2021-07-11T19:27:18.2555653Z"
},
"MACAddress": {
"$lastUpdated": "2021-07-11T19:27:18.2555653Z"
},
"DefaultGateway": {
"$lastUpdated": "2021-07-11T19:27:18.2555653Z"
}
},
"wifi": {
"$lastUpdated": "2021-07-11T19:27:18.2555653Z",
"AdapterName": {
"$lastUpdated": "2021-07-11T19:27:18.2555653Z"
},
"IPAddress": {
"$lastUpdated": "2021-07-11T19:27:18.2555653Z"
},
"MACAddress": {
"$lastUpdated": "2021-07-11T19:27:18.2555653Z"
},
"DefaultGateway": {
"$lastUpdated": "2021-07-11T19:27:18.2555653Z"
}
}
}
}
},
"$version": 3
}
},
"capabilities": {
"iotEdge": false
}
}
@rido-min
Copy link
Author

DTDL Maps demo

Sample DTDL interface using a map, to validate IoTExplorer and Central

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment