Support for object repetition inside arrays in Driver MQTT.

This article presents an example of support for object repetition inside arrays in a Driver MQTT.

Question:

Usually, controllers send messages under a specific topic, as in the example below:

{"MessageType":"TagValues","WagoProtocol":"1.5.0","CollectionId":0,"TagData":[{"Time":"2021-08-02T13:35:03.442-3:00","Values":{"OEE":0.11999999731779099,"Disponibilidade":3.4100000858306885,"Performace":3.4100000858306885,"Qualidade":99.680000305175781,"Produtos Produzidos":929,"Produtos Rejeitados":3}}]}

However, a few controllers have a kind of buffer that, when losing connection to the basis, accumulate messages locally. In this example, in the first message after reconnection, the following message is sent in the same topic:

{"MessageType":"TagValues","WagoProtocol":"1.5.0","CollectionId":0,"TagData":[{"Time":"2021-08-02T13:35:08.442-3:00","Values":{"OEE":0.11999999731779099,"Disponibilidade":3.4300000667572021,"Performace":3.4300000667572021,"Qualidade":99.680000305175781,"Produtos Produzidos":934,"Produtos Rejeitados":3}},{"Time":"2021-08-02T13:35:13.442-3:00","Values":{"OEE":0.11999999731779099,"Disponibilidade":3.4500000476837158,"Performace":3.4500000476837158,"Qualidade":99.680000305175781,"Produtos Produzidos":939,"Produtos Rejeitados":3}},{"Time":"2021-08-02T13:35:18.443-3:00","Values":{"OEE":0.11999999731779099,"Disponibilidade":3.4700000286102295,"Performace":3.4700000286102295,"Qualidade":99.680000305175781,"Produtos Produzidos":944,"Produtos Rejeitados":3}}]}

In the example above, there are three accumulated messages.

Solution:

Since the release of version 1.0.25 of Driver Elipse MQTT, when declaring the template, you have been able to add a keyword  Repeat_E3VAL right after the bracket representing the array, where the object can repeat itself. Therefore, it is now possible to have object repetition in a driver MQTT.

Adding this word turns the JSON invalid, but the driver removes this keyword and “marks” the spot of its position; then, it starts using a template.

{"MessageType":"DUMMY","WagoProtocol":"1.5.0","CollectionId":"DUMMY","TagData":[Repeat_E3VAL{"Time":"TS_TEXT(%Y-%m-%dT%H:%M:%S.%f%+)","Values":{"OEE":"E3VAL","Disponibilidade":"E3VAL","Performace":"E3VAL","Qualidade":"E3VAL","Produtos Produzidos":"E3VAL","Produtos Rejeitados":"E3VAL"}}]}

Hence, after the driver has processed each element of an array whose elements can repeat themselves, the driver proceeds to:

  1. copy the values it has so far,
  2. adds it as an element from another set of values,
  3. and then continues to process the next element that it will copy “over” the values of the first item, whichever is in the second one.

If the template declares one or more E3VAL before the repetition point, each set will repeat these values up until this point.

So, if there are 10 sets inside the array, the result is a set of values with 10 values inside; this in turn is sent to the block/tag in Elipse E3, and the OnRead event is called 10 times, one for each set.

Related articles:


Print Friendly, PDF & Email

Este artigo foi útil? Was this helpful?

Classificação média - Average rating 0 / 5. Count: 0

Leave a Reply

Your email address will not be published.Required fields are marked *