Dov Magrobi Posted January 3, 2021 Report Posted January 3, 2021 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 {"Time":"2021-01-01T21:02:01","RfReceived":{"Sync":24580,"Low":1210,"High":2590,"Data":"140EE1","RfK 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 ?
MVP 2023 Joe Tauser Posted January 3, 2021 MVP 2023 Report Posted January 3, 2021 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.
Dov Magrobi Posted January 5, 2021 Author Report Posted January 5, 2021 Thanks for the reply. I will attach more data once i have "taken a poke " In short i am very new to working with String functions, any assistance will be greatly appreciated.
MVP 2023 Joe Tauser Posted January 5, 2021 MVP 2023 Report Posted January 5, 2021 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.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now