pahoMqttExt icon


Paho MQTT Connector Extension
< All topics

Registered StackHub users may elect to receive email notifications whenever a new package version is released or a comment is posted on the forum.

There are 9 watchers.

need support on Parsing MQTT data JSON format on Desigo Optic with pahoMqtt
William LiuTue 30th Jan

Hi guys,

we just started to use Desigo Optic recently. try to creat Mqtt connection on Optic. we have some troulbe on parsing predefined Mqtt data format, which was predefined in the gateway hardware. the parsing axon function could work propely in Skyspark 3.1. but it looks that the configuration method on Optic is different from skyspark. does anybody have detailed documentation for config the pahomqtt in Desigo Optic to share, that would be very helpful. as the folio version is 3.0.29 in Desigo Optic, for the Mqtt connection, is there any other option besides pahomqtt?

thank you in advance.

John MacEnriTue 30th Jan

Hi William.

I can't tell from the note what the problem is. Have you configured on the connector what your axon parser function name is? And is that function working when you test it with a sample message?

This MQTT Connector is intended to be completely agnostic of what payload formats you're dealing with, hence I built it such that you can configure in your own parser function.

Please can you provide some more detail on what is failing.

Regards, John.

William LiuWed 31st Jan

Hi John,

thank you for your reply. here is the data format example which was sent from our gateway:

Topic: /edge/mqttsn001/20249ED38CBF48B385B776906A52D55C/rtgQoS: 0 {"devs":[{"d":[{"dq":192,"m":"FanC","ts":1706596835,"v":1},{"dq":192,"m":"SN","ts":1706596835,"v":0},{"dq":192,"m":"FanMA","ts":1706596835,"v":0},{"dq":192,"m":"FanAml","ts":1706596835,"v":0},{"dq":192,"m":"FanS","ts":1706596835,"v":0},{"dq":192,"m":"T","ts":1706596835,"v":0.000},{"dq":192,"m":"H","ts":1706596835,"v":0.000},{"dq":192,"m":"Valve","ts":1706596835,"v":-198656.000},{"dq":192,"m":"TSP","ts":1706596835,"v":0.000}],"dev":"Device"}],"pKey":"mqttsn001","sn":"20249ED38CBF48B385B776906A52D55C","ts":1706596835,"ver":"2.0.0"}

and we had edited a function from an example in finstack's website, which could only parse one point's data in Desigo Optic, below is the code for function: (msg,params: null) => do

jsonData: ioReadJson(msg)
tags = tags.set("curVal",jd.get(0)->v)
tags = tags.set("curStatus","ok")


as we try to pass an parameter to the function, but the function did not work, here is the rewrited function code: (msg,params: null,x) => do

jsonData: ioReadJson(msg)
tags = tags.set("curVal",jd.get(x)->v)
tags = tags.set("curStatus","ok")


any fault in this function?

Regards, William

John MacEnriWed 31st Jan

Hi William.

I'm not sure this Paho MQTT Connector is the right thing for your use case. I think you just need a subscriber to parse the messages and write to point history.

This Paho connector is quite old so I'd recommend moving to using the built in SkySpark support for MQTT.

Your message indicates you've got values for multiple points in the one message, and the fact that there is a timestamp means it's not really a curVal message.

I would suggest reading the SkySpark MQTT docs, set up a native SkySpark MQTT connector to your MQTT Broker, and paying particular attention to the Subscribe section, I think that would give you a much better means of processing these messages and writing directly to point history for all points in the message using the timestamp each has, along with its value.

William LiuThu 1st Feb

Hi John,

i think you are right. what i need just a subscriber to parse the messages and write to point history.

we had already wroten an axon function in skyspark with its buildin MQTT. the function could work properly.

my problems is that we need to work in Desigo Optic, which is the Siemens product name of FinStack. till now, the latest Desigo Optic only support to folio 3.0.29, which still don't have built in MQTT. that's why we choose the pahomqtt, and this is also the suggestion from Siemens.

we don't know why our axon function could not work in Desigo Optic. does the pahomqtt have any restrict on axon function? here is the code:

(msg,params: null) => do


jsonData: ioReadJson(msg)
//tags = tags.set("curVal",jd.get(0)->v)
//tags = tags.set("curStatus","ok")
fanc:read(point and navName == "FanC"and equipRef->navName==ename)
sn:read(point and navName == "SN"and equipRef->navName==ename)
fanma:read(point and navName == "FanMA"and equipRef->navName==ename)
fanaml:read(point and navName == "FanAml"and equipRef->navName==ename)
fans:read(point and navName == "FanS"and equipRef->navName==ename)
t:read(point and navName == "T"and equipRef->navName==ename)
h:read(point and navName == "H"and equipRef->navName==ename)
valve:read(point and navName == "Valve"and equipRef->navName==ename)
tsp:read(point and navName == "TSP"and equipRef->navName==ename)
 hisWrite({ts: dt, val:jd.get(0)->v},  fanc)
 hisWrite({ts: dt, val:jd.get(1)->v},  sn)
 hisWrite({ts: dt, val:jd.get(2)->v},  fanma)
 hisWrite({ts: dt, val:jd.get(3)->v},  fanaml)
 hisWrite({ts: dt, val:jd.get(4)->v},  fans)
 hisWrite({ts: dt, val:jd.get(5)->v},  t)
 hisWrite({ts: dt, val:jd.get(6)->v},  h)
 hisWrite({ts: dt, val:jd.get(7)->v},  valve)
 hisWrite({ts: dt, val:jd.get(8)->v},  tsp)


could you help us check this code? thanks.


John MacEnriThu 1st Feb

Hi William.

I understand. It's a bit unfortunate to be forced to be stuck on a version of SkySpark that's now nearly 3 years old!

Anyway, given that, I'd suggest you move to using the pahoMqttSub extension instead. You don't need the connector, you just need an MQTT Subscription to give you the messages when they arrive and you just handle the content, as laid out in your code.

As for the validity of the code, there seems to be no space before the and in each of the read calls to get the points. And you're using a variable called ename that hasn't been declared or set.

The function (even it corrected) would still be very prone to errors as it relies on unchanging navNames and the order of values in the MQTT message. I'll write something that could work, but it might be a couple of days before I get back to you.

Regards, John.

William LiuFri 2nd Feb

Hi John,

thank you for your advice. i will try pahoMqttSub then. and I appreciate your kind help very much.



John MacEnriMon 12th Feb

Hi William.

As a rough guide for what I think the code in a subscriber func should do:

jsonData: ioReadJson(msg)
metrics.each(metric => do
  pt: read(point and someTag == metric->m, false)
  if (pt != null) do
    ts: m->ts.fromJavaMillis(pt->tz)
    hisWrite({ts:ts, val:m->v}, pt)    

You just need to decide on the name of some tag to mark the 9 points with a value that equals the value of m in each metric.

William LiuMon 19th Feb

Hi John,

i just came back from vocation. thank you for your kind support. i will try this func soon, and let you know.

Log in or Sign up to post a reply.