Skip to content

Cannot receive device metrics via DCMD #114

@tszpakowicz

Description

@tszpakowicz

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:

  1. For DCMD payload with metrics Control/DeviceValue1 and Control/DeviceValue2 I see in the console:

    DCMD received for device1
    

    No 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.
    
  2. For DCMD payload with metrics Node Control/NodeValue1 and Node Control/NodeValue2 I see:

     DCMD received for device1
      - Node Control/NodeValue1: 123
      - Node Control/NodeValue2: Test 123
    

    And 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;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions