MQTT Raw Parsing [message #1767270] |
Tue, 04 July 2017 11:58 |
Ahmed Mujtaba Chang 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 #1767319 is a reply to message #1767308] |
Tue, 04 July 2017 15:51 |
|
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)
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04167 seconds