Protobuf using new tag processor /nodered_js
# umh-support
r
I'm implementing a Protocol Converter for Sparkplug B payloads to UMH Historian format. My setup subscribes to
spBv1.0/administration/DDATA/node-red/time_activity
via MQTT. My requirements: - Process each Sparkplug B metric as a separate tag in UMH - Use metric names as tag names - Preserve original data types - Extract timestamp from Sparkplug payload when available My sample Sparkplug B payload (post-decoding):
Copy code
json
{"metrics":[{"name":"pageId","value":"1eb96444-d9bc-800e-ac74-c4f89ada05c7","dataType":"String"},{"name":"lastEdited","value":1746560100000,"dataType":"DateTime"},{"name":"notes","value":"UNS Article","dataType":"String"}]}
My current implementation challenge: Past discussions describe using Bloblang/YAML for protobuf processing, but the current management console only shows a field to write code for a JavaScript processor. I'm struggling to bridge this gap and implement an effective JavaScript solution. Questions: 1. Is the protobuf decoding handled before the JavaScript processor, or should I implement it in JavaScript? 2. What's the optimal way to handle Sparkplug B in the UMH Protocol Converter JavaScript environment? 3. Are there specific libraries available in this environment for Sparkplug B? My simplified processor logic attempt:
Copy code
// Process decoded Sparkplug payload
let payload = typeof msg.payload === 'string' ? JSON.parse(msg.payload) : msg.payload;
let messages = [];

if (payload && payload.metrics) {
  const timestamp = payload.timestamp || Date.now();
  
  payload.metrics.forEach(metric => {
    messages.push({
      meta: {
        location_path: "R-Maestas-LLC.Curtice.Utility",
        data_contract: "_historian",
        tag_name: metric.name
      },
      payload: { 
        [metric.name]: metric.value, 
        timestamp_ms: timestamp 
      }
    });
  });
  
  return messages;
}

return msg;
Any guidance would be greatly appreciated.
j
Let me think
Decoding protobuf inside of js is not trivial I guess. So what needs to be done is there needs to be a protobuf yaml decoder from benthos before nodered_js, so let me check how this is possible
some more thoughts: 1. either we need the capability in the frontend to add more than one YAML processor node 2. or we need to add a protobuf library by default in nodered_js (which is inherited by the tag_processor as well). something like this: https://github.com/protobufjs/protobuf.js/. Then you can simply import that package and use it in that environment
what are your thoughts on this?
b
Depends how juiced you want tag_processor to be. Protobuf would be great.
r
Thanks for the tips all. @Brian Pribe I'll study the documentation in the link you sent today.
2 Views