Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » 4DIAC - Framework for Distributed Industrial Automation and Control » MQTT Raw Parsing(How to effectively parse the MQTT Raw parsing)
MQTT Raw Parsing [message #1767270] Tue, 04 July 2017 11:58 Go to next message
Ahmed Mujtaba Chang is currently offline Ahmed Mujtaba ChangFriend
Messages: 9
Registered: May 2017
Junior Member
Hello,

I want to communicate with RAW MQTT.

I have simple commands to send which need to be parsed.

Before I ask you about parsing, there is one issue that I am facing.

I am using a Subscriber_1 FB, with ID as
raw[].mqtt[tcp://192.168.1.144:1883, forte,switch]

Whenever I receive a message from RAW MQTT, event IND is fired and RD_1 contains the data. Suppose I send the data as "welcome".
RD_1 reads "welcome" (as expected).
However if I receive another RAW MQTT message which is "HELLO", now in this case
RD_1 read "HELLOme". Basically overwriting the previous message (welcome is overwritten by hello, if the second message has equal or large length of the first message, first message is completely overwritten).

1) My first question is that how can I avoid this?

2) Also in some cases if I send a message, I receive a space at the end? Like, "hello ". Why does it happen? And how to avoid that?

3) My second question is that, is there any way to add variables in the 4-Diac application? I would like to reuse some values.

4) My last question is that what should be the way to parse the data, I have simple commands like:

  • activate
  • deactivate
  • 00
  • 01
  • 10
  • 11

I have taken the simple approach to take left characters until I find the string I want to. However, what is the most efficient way to parse? If there any way to use split() equivalent function in 4-Diac?

Thank you.

Kind regards,
Re: MQTT Raw Parsing [message #1767273 is a reply to message #1767270] Tue, 04 July 2017 12:07 Go to previous messageGo to next message
Martin Melik Merkumians is currently offline Martin Melik MerkumiansFriend
Messages: 117
Registered: March 2016
Senior Member
My first question to your first problem. Do you also send your MQTT messages via 4diac or are you using your own solution?.

Second Problem: Is it possible that you send the space in addition? This cannot be avoided, as the payload has no meaning for MQTT so everything you send is transported. You could probably use the TRIM FB to remove trailing spaces.

To you variables question: I am not quite sure what you mean? Do you mean something like global application variables or FB variables? Why not simply reuse Input or Output variables.

To your last question: There are several String manipulation FBs available, so please take a look on the library (There should be something like split, left and right in the library IEC61131-3 / CharacterString). If nothing suits your needs, then a simple way to solve your problem would be to create a SIFB and doe the parsing in plain C/C++.

Best regards,
Martin
Re: MQTT Raw Parsing [message #1767279 is a reply to message #1767273] Tue, 04 July 2017 12:22 Go to previous messageGo to next message
Ahmed Mujtaba Chang is currently offline Ahmed Mujtaba ChangFriend
Messages: 9
Registered: May 2017
Junior Member
I send the messages through external MQTT client (mosquitto).

I could send additional spaces in the messages but it would be not a efficient way to force the sender to adopt certain messages.

Variables, I meant, a simple variable like "myvar" for which I could use as a data input to several FBs and instead of typing it again, I could change myvar and all of the FBs can have access to.

SIFB, how can I write a code in C++, is there any website which has any information about it? If yes, please share. Thank you.
Re: MQTT Raw Parsing [message #1767306 is a reply to message #1767279] Tue, 04 July 2017 14:45 Go to previous messageGo to next message
Jose Maria Jesus Cabral Lassalle is currently offline Jose Maria Jesus Cabral LassalleFriend
Messages: 199
Registered: February 2016
Senior Member
Which commit of forte are you using? I just tested mine and didn't have the problem of the overwriting nor the blank space. I think what Martin asked was if weren't you sending the message from your client already with a space?

You can use F_EQ that can compare two strings, your incomming message and STRING#activate for example. You can put many of these in parallalel and next to each, you can put a a E_PERMIT, that will filter the event output of the right command. It might not be the best solution, but I think it will work to have a quick implementation to test.
Re: MQTT Raw Parsing [message #1767308 is a reply to message #1767306] Tue, 04 July 2017 14:48 Go to previous messageGo to next message
Jose Maria Jesus Cabral Lassalle is currently offline Jose Maria Jesus Cabral LassalleFriend
Messages: 199
Registered: February 2016
Senior Member
Regardoing "myVar" I'm not sure that I understand what you are looking for, but it sounds like virtualDNS. Check https://www.eclipse.org/4diac/documentation/html/4diacIDE/otherUseful.html#VirtualDNS and see if that's what you are looking for.

And an example for writing a SIFB you can find here:

https://www.eclipse.org/4diac/documentation/html/tutorials/flipFlop_asSIFB.html
Re: MQTT Raw Parsing [message #1767319 is a reply to message #1767308] Tue, 04 July 2017 15:51 Go to previous messageGo to next message
Alois Zoitl is currently offline Alois ZoitlFriend
Messages: 1585
Registered: January 2014
Senior Member

There was an issue in 4diac which resulted in your problems 1 and 2. I'm not sure if it is fixed in 1.8.x or in the top of the 1.8.x ranch of the repository. Please check which version you have.

Regarding parsing. 4diac implements all IEC 61131-3 string functions (see below for a quick list). With that functions you should be able to parse your strings. You can use these functions in a basic function's algorithms or as FBs in a fb network (see the 1131-3 folder). However I think for your problem a basic function block would be more suitable. There you can also declare variables. But I'm not sure if I understood your question 3.

The IEC 61131-3 string functions are:
* LEN(val)
* LEFT(STRING In, INT L)
* RIGHT(STRING In, INT L)
* MID(STRING In, INT L, INT P)
* CONCAT(STRING In1, STRING In2)
* INSERT(STRING In1,STRING In2, INT P)
* DELETE(STRING In, INT L, INT P){
* REPLACE(STRING In1, STRING In2, INT L, INT P)
* FIND(STRING In1, STRING In2)
* TOUPPER(STRING In)
* TOLOWER(STRING In)

Re: MQTT Raw Parsing [message #1767534 is a reply to message #1767319] Thu, 06 July 2017 22:48 Go to previous messageGo to next message
Ahmed Mujtaba Chang is currently offline Ahmed Mujtaba ChangFriend
Messages: 9
Registered: May 2017
Junior Member
Thank you for your replies that was helpful.

When I say variables, I mean some sort of re-usable term. Just as @Jose pointed out, %ip% for writing in the System Configuration. Is there way to initiate other variables and use them in the Applications instead of System Configuration?

Re: MQTT Raw Parsing [message #1767550 is a reply to message #1767534] Fri, 07 July 2017 06:12 Go to previous message
Jose Maria Jesus Cabral Lassalle is currently offline Jose Maria Jesus Cabral LassalleFriend
Messages: 199
Registered: February 2016
Senior Member
You can use the %variable% in the System Configuration as well as in the Application
Previous Topic:There are some differences between my ide and document.
Next Topic:MODBUS Client FB dont write Coil registers and create one connection by Block
Goto Forum:
  


Current Time: Fri Apr 26 04:23:49 GMT 2024

Powered by FUDForum. Page generated in 0.03360 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top