Hello @Christopher Sasso , welcome to Microsoft Q&A and thank you for posting your question.
I understand you are trying to get familiar with Azure Digital Twins and for the use case you stated here, you can monitor the status of the LED light on the Azure Digital Twin by just creating a model with a single "boolean" property. The boolean property reflects the state of the LED light. You can set this property as "writable" during creation and can modify this property value through the code or Azure Digital Twin Explorer.
Here is the JSON snippet I have used to generate the Azure Model.
{
"@id": "dtmi:com:example:LightUp;2",
"@type ": "Interface",
"displayName": "LightPLC2",
"contents": [
{
"@type ": "Property",
"name": "setLightStatus",
"writable": true,
"schema": "boolean"
}
],
"@Георгий Георгиевский ": "dtmi:dtdl:context;2"
}
You can then create the Azure Model using the JSON by using the code specified in the following tutorial - Coding with the Azure Digital Twins SDK Here is the code snippet for your reference.
string adtInstanceUrl = "https://<your-Azure-Digital-Twins-instance-hostName>";
var credential = new DefaultAzureCredential();
var client = new DigitalTwinsClient(new Uri(adtInstanceUrl), credential);
Console.WriteLine($"Service client created – ready to go");
Console.WriteLine($"Upload a model");
string dtdl = File.ReadAllText("<YourModelFileName>.json");
var models = new List<string> { dtdl };
// Upload the model to the service
try
{
await client.CreateModelsAsync(models);
Console.WriteLine("Models uploaded to the instance:");
}
catch (RequestFailedException e)
{
Console.WriteLine($"Upload model error: {e.Status}: {e.Message}");
}
AsyncPageable<DigitalTwinsModelData> modelDataList = client.GetModelsAsync();
await foreach (DigitalTwinsModelData md in modelDataList)
{
Console.WriteLine($"Model: {md.Id}");
}
Please make sure to modify the instance URL and the file name in the above code.
Once you have the Azure Model created, you can then generate Azure Digital Twins based on the Model using the following code snippet.
var twinData = new BasicDigitalTwin();
twinData.Metadata.ModelId = "dtmi:com:example:LightUp;2";
twinData.Contents.Add("setLightStatus", true);
try
{
twinData.Id = "Lightup2";
await client.CreateOrReplaceDigitalTwinAsync<BasicDigitalTwin>(twinData.Id, twinData);
Console.WriteLine($"Created twin: {twinData.Id}");
}
catch (RequestFailedException e)
{
Console.WriteLine($"Create twin error: {e.Status}: {e.Message}");
}
You can now view the Azure Digital Twin created through the Azure Digital Twin Explorer.
Please find the below image to refer the Azure Digital Twin I have created and the properties I see from it on the Azure DigitalTwin Explorer portal.
You can further use the resources provided in this tutorial Manage digital twins to update or get values out of your Azure Digital Twins.
Please let me know if you have any further questions or need further clarification on this issue.
Hello Satish,
I have followed a few sample models from the iot-plugandplay-models on GitHub in an attempt to describe the function I want to replicate.
I am attempting to use the command properties to send requests to another model for a light to turn on and off:
I am not sure if the schema I used in the above snippet is correct.