Jump to content

Advice on how to check a string of data for relevant info.

Dov Magrobi

Recommended Posts

I have data coming in via Mqtt, i need to strip out only one piece of data and then use that in the logic, the format is as follows


The data i need is the "Data":"140EE1"

The string changes in length depending on the incoming mqtt message.

which function is suited to this ?

Link to comment
Share on other sites

  • MVP 2023

You haven't attached your program so we don't have much to go on.

Is that data copied into a string variable?  If so, you need to find a couple of pointers within the string to help you extract what you want from a string that is not a predictable length.  You need to make the PLC think like a human, which can be tricky.

I would use the "Find Substring" function to look for the string "Data": and store the location.  Then look for "RfK".  Then do some adding and subtracting  to get the location of the beginning of your actual data and its length.  Finally, use the "Middle of String" function to pull out what you need.

Or, once you've found "Data": you can use the "Right Part of String" to grab everything left over and strip out ","RfK".

Or, there may be another way.  Take a poke at it and post your work here if you need help.  

Joe T.

Link to comment
Share on other sites

  • MVP 2023

Strings are a more complex subject in PLCs.  PLCs were not meant to parse and combine letters.

I learned String functions by making some string variables in a test application and trying things out while online to watch their behavior.  You may also want to make some buffer variables and move things in and out of them so you can see the data in its raw hex form.  This is what I mean by "take a poke".

Feel free to post any of your play programs here with questions.  You're not going to break the PLC by downloading anything, and the interaction with generating the code is how you will learn it.

Joe T.  

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...