-
Notifications
You must be signed in to change notification settings - Fork 51
Description
Hi,
When working as a Sparkplug edge node I cannot receive device data in DCMD.
With the code below when I publish to spBv1.0/group1/DCMD/node1/device1 I see this cases:
-
For DCMD payload with metrics
Control/DeviceValue1andControl/DeviceValue2I see in the console:DCMD received for device1No metrics are received.
And if I plug in a logger it outputs:The metric SparkplugNet.VersionB.Data.Metric is removed because it is unknown. The metric cast didn't work properly. The metric SparkplugNet.VersionB.Data.Metric is removed because it is unknown. The metric cast didn't work properly. -
For DCMD payload with metrics
Node Control/NodeValue1andNode Control/NodeValue2I see:DCMD received for device1 - Node Control/NodeValue1: 123 - Node Control/NodeValue2: Test 123And nothing in logs.
This is totally backwards.
Why does device receive metrics defined for the edge node?
Why do I need to define device metrics as edge node metrics?
What if device metrics schema is determined at runtime as the device comes online and the node does not know about them until it connects?
What if separate devices have conflicting metrics definitions?
When NBIRTH is sent what should the device metrics values be when the same metric is shared between devices or device is not even connected?
The code (I omitted usings and main loop for brevity):
List<Metric> nodeMetrics = new ()
{
new Metric("Node Control/Rebirth", DataType.Boolean, false),
new Metric("Node Control/NodeValue1", DataType.Int32, 0),
new Metric("Node Control/NodeValue2", DataType.String, ""),
};
const string deviceIdentifier = "device1";
List<Metric> deviceMetrics = new ()
{
new Metric("Control/DeviceValue1", DataType.Int32, 0),
new Metric("Control/DeviceValue2", DataType.String, ""),
};
var node = new SparkplugNode(nodeMetrics, SparkplugSpecificationVersion.Version30);
node.DeviceCommandReceived += HandleDeviceCommand;
var nodeOptions = new SparkplugNodeOptions("localhost", 1883, "node 1", "", "", null, null, null, null, null, "group1", "node1", CancellationToken.None);
await node.Start(nodeOptions);
await node.PublishDeviceBirthMessage(deviceMetrics, deviceIdentifier);
Task HandleDeviceCommand(SparkplugNode.DeviceCommandEventArgs ev)
{
Console.WriteLine($"DCMD received for {ev.DeviceIdentifier}");
foreach (var metric in ev.Metrics)
{
Console.WriteLine($" - {metric.Name}: {metric.Value}");
}
return Task.CompletedTask;
}