benthos Sparkplug B
# archived-umh-development
j
Hi, I am probably the only one using Sparkplug B for Benthos right now, since it is not released yet, but I was hoping more people want to join in on the fun. I have a challenge that needs to be solved, and I think it will require a modification in the current code to achieve it. So my use case is the following:
- I read OPC UA data and publish it over Sparkplug B - I listen to Sparkplug B DCMD commands to write back to OPC UA Pretty simple so far, right?
j
@mparris
The writing back part sounds difficult, my article with MQTT, QoS and ACK and data contracts etc
j
I want the setup per device to be as straight forward as possible, so I created a json that the end customer can fill in:
Copy code
{
  "mappings": [
    {
      "opc_ua_path": "default.PaintRoom1.CarsPainted",
      "sparkplug_name": "paint_booth.cars_painted",
      "sparkplug_alias": 102,
      "sparkplug_type": "integer",
      "writeable": false,
      "deadband_time": 15
    },
    {
      "opc_ua_path": "default.PaintRoom1.Spraytan1.Color",
      "sparkplug_name": "paint_booth.spray_gun.color",
      "sparkplug_alias": 103,
      "sparkplug_type": "string",
      "writeable": true,
      "deadband_time": 15
    },
    {
      "opc_ua_path": "default.PaintRoom1.Spraytan1.Pressure",
      "sparkplug_name": "paint_booth.spray_gun.pressure",
      "sparkplug_alias": 104,
      "sparkplug_type": "integer",
      "writeable": false,
      "deadband_time": 15
    }
  ]
}
Here is where my issue starts. When I write my initial messages, the only way to define my aliases is to put them in the Sparkplug B output 'metrics' variable. But this variable does not take my json as input, nor does it accept extra fields. So I am not able to define my alias, and even if I would use it, I would never be able to map the alias back to the OPC UA value, since the mapping is only done in my output... I see the following solutions: - Transform my json mapping to yaml, and change the output so that it can also accept extra fields --> Is it possible to ignore extra fields in Benthos? Right now it throws linting errors if I try. - Change the output metrics, so that it can be a expression, based on a variable in my processors - Maybe even change the base format for metrics, so you build in that there might be a source-tag-path? What option sounds most Benthos-like? Or how would any of you approach this issue? See in attachement my processing of DCMD commands, finding back the tags in the json. It works when it knows the aliases, but I don't want to have 2 definitions of my tags.
I've been looking for the best solution, and right now I'm actually not using the metrics property, but just letting it dynamically build it's aliases. That might be an easier problem to solve, because it just needs something like a debouncer if you don't want 200 birth messages the first second you're online ... Any suggestions to the debounce strategy? Is this configurable, or should we look towards a fix @Jermuk
I've managed a working example for the following: - Read OPC tags from autodiscovery on OPC server - Map the tags to their UNS name by a config json - Publish them on Sparkplug B - Receive DCMD, map them back to the opc tags if they are writeable - Write back to opc if allowed
j
i need some focus time here to go through it, i'll try to do it in the evening
found some time. about the debouncer: this is something that is not easy to do in benthos as we need to decide on the spot for each incoming message if we want to pass it on or not. i think this is also wanted in benthos to get straightforward flows and not complex stuff that can happen when working with node-red. maybe one can add a logic, that upon first startup waits for 10seconds before emitting the first birth message? i did similar logic in the downsamplers. so on every new incoming message check if 10 seconds have passed sicne last startup and only send the birth message if yes. might result in birth messages being sent after the original sparkplug message has been sent. as trigger you cannot use the time here, but you can use incoming messages. so check it everytime new messages come in. i did somethign simlar with the downsampler.
j
Hmm, it is an option yes. I do wonder if there is a way to define the metrics dynamically based on a json/ something generated, because in a lot of cases we would do the dataops in the layer of Benthos, so we would know what metrics we want to send up. So something like metrics right now, but generated on a property in processor. Is that something that could be ‘normal’?
j
By the way: currently on vacation. Let’s talk once I am back 🙂
how about adding a sparkplugb alias cache? something like
Copy code
cache_resources:
  - label: sparkplug_metrics
    file:  # or redis for distributed setups
      directory: /tmp/benthos-cache

output:
  sparkplug_b:
    mqtt:
      urls: ["tcp://mosquitto:1883"]
    
    metric_cache_resource: sparkplug_metrics
So then on startupo, you would preload the sparkplug metrics from the specified cache. I think this could make it more benthos "natural"
j
I love that! I think a cache would even be great for general dataOps with UMH, converting OPC to uns structure or sparkplug.
3 Views