General Discussions
MQTT Publisher

Greetings,
I, as most people, am working to create an RTU that utilizes the MQTT communications protocol. Right now I am testing with a local broker and have data reliably getting to VTScada.
However, I need the ability to write data back to a certain topic with a certain metric. The ability seems to exist, yet I have not had any luck with VTScada publishing the message correctly yet.

Using JSON formatting lets say I wanted the data to write like this
{"LSP":XX.XX}

Where...
Topic: DD/Write
Metric: LSP

and XX.XX is the value input to my analog widget.

Right now when I try to get my data to publish as such, I get the topic == DD/Write, but the metric is no where to be found in the message. The only data in the message is the integer entered.

See the attached image for how I have my write address set up.672131ba43c1a

Greetings, I, as most people, am working to create an RTU that utilizes the MQTT communications protocol. Right now I am testing with a local broker and have data reliably getting to VTScada. However, I need the ability to write data back to a certain topic with a certain metric. The ability seems to exist, yet I have not had any luck with VTScada publishing the message correctly yet. Using JSON formatting lets say I wanted the data to write like this {"LSP":XX.XX} Where... Topic: DD/Write Metric: LSP and XX.XX is the value input to my analog widget. Right now when I try to get my data to publish as such, I get the topic == DD/Write, but the metric is no where to be found in the message. The only data in the message is the integer entered. See the attached image for how I have my write address set up.![672131ba43c1a](serve/attachment&path=672131ba43c1a)

The MQTT Publisher is built to only publish the value to the topic and ignores the metric. There are specific reasons for this but I am not aware of the details as to why this behaviour was chosen.

If you want, you can create a custom decoder for the MQTT driver which will work for you. An example snippet of code which should be able to get you started is shown below:

Help on writing a custom MQTT Decoder: https://www.vtscada.com/help/Content/Scripting/Tasks/pro_MQTTParser.htm

{=========================== JSONEncoder ===================================}
{ Computes a Payload in a JSON format to Publish via MQTT }
{===========================================================================}
(
Data { A value to be written out. };
MemAddr { "Indexing trail" from the Write address of the IO };

)
[
X;
JsonDict;
]

Only [
If Watch(1);
[
JsonDict = Dictionary();
JsonDict[MemAddr] = Data;
JsonDict["Timestamp"] = CurrentTime(1); { Now }

X = JSonEncode(JsonDict);

Return(X);
]
]

Note, implementing this requires a more advanced knowledge of VTScada. If you have SupportPlus, I'd encourage you to reach out to our support team for assistance here.

The MQTT Publisher is built to only publish the value to the topic and ignores the metric. There are specific reasons for this but I am not aware of the details as to why this behaviour was chosen. If you want, you can create a custom decoder for the MQTT driver which will work for you. An example snippet of code which should be able to get you started is shown below: Help on writing a custom MQTT Decoder: https://www.vtscada.com/help/Content/Scripting/Tasks/pro_MQTTParser.htm ```` {=========================== JSONEncoder ===================================} { Computes a Payload in a JSON format to Publish via MQTT } {===========================================================================} ( Data { A value to be written out. }; MemAddr { "Indexing trail" from the Write address of the IO }; ) [ X; JsonDict; ] Only [ If Watch(1); [ JsonDict = Dictionary(); JsonDict[MemAddr] = Data; JsonDict["Timestamp"] = CurrentTime(1); { Now } X = JSonEncode(JsonDict); Return(X); ] ] ```` Note, implementing this requires a more advanced knowledge of VTScada. If you have SupportPlus, I'd encourage you to reach out to our support team for assistance here.

Trihedral Engineering Ltd.

Dave, you are the man! This works like a charm!

Dave, you are the man! This works like a charm!

Thanks for following up. I'm glad that this worked well for you and that you were able to get it implemented. The code came from our dev team so I can't take credit for it; I'm just the messenger smile

Thanks for following up. I'm glad that this worked well for you and that you were able to get it implemented. The code came from our dev team so I can't take credit for it; I'm just the messenger :P

Trihedral Engineering Ltd.

38
3
2
live preview
enter atleast 10 characters
WARNING: You mentioned %MENTIONS%, but they cannot see this message and will not be notified
Saving...
Saved
With selected deselect posts show selected posts
All posts under this topic will be deleted ?
Pending draft ... Click to resume editing
Discard draft