Hi Guys,
I have a problem and cannot find a solution … but you determine:
In my app I receive some measured values as numbers collected in a string via Bluetooth from an Arduino.
These respective numbers are separated in the string with “:” and can be 1, 2, 3 or 4 digits long.
Example: 223:334:412 or 98:1223:9 or 332:1:49 etc.
How can I split the string and store the individual numbers separately in different variables etc.?
Hi and may thanks for reply,
I have already tried all of this functions and then get the result (as sample): [“432”, “99”, “1002”] in and from this moment on I don’t know what to do …
Sorry, I haven’t worked with lists etc. yet.
I just have to store the 432 in a varibale “a”, store the 99 in a varibale “b”, and store the 1002 in a variable “c”.
How does it work ?
Hi again,
thanks for the hint … I had already read the tutorial … but I have no idea how I have to implement this in order to save from [“432”, “99”, “1002”] into individual variables . (“I have a knot in my head”).
The problem is, that the numbers can have different numbers of digits … and I can’t get that solved at all.
Do you have a tip for me?
When you “split text at” you actually receive a list [“432”, “99”, “1002”] . See in my example how to work with that list . The digits in the numbers won’t be a problem since you split at :
The excess length can possibly also be caused by incorrect values from Arduino … I will leave it like this until everything is ready.
Thanks again and good night!!!
Hello again,
pity … it works so well, but then I increased the quantity of numbers from 3 to about 11 (see red number series) … and then the crash comes from the list.
How can I solve the problem ?
This is a BlueTooth Delimiter Required problem.
Your list text is being clipped by the Clock.
(boiler plate):
Please see the Delimiter article in FAQ
Be sure to use println() at the end of each message to send from the sending device, to signal end of message. Do not rely on timing for this, which is unreliable.
In the AI2 Designer, set the Delimiter attribute of the BlueTooth Client component to 10 to recognize the End of Line character.
Also, return data is not immediately available after sending a request,
you have to start a Clock Timer repeating and watch for its arrival in the Clock Timer event. The repeat rate of the Clock Timer should be faster than the transmission rate in the sending device, to not flood the AI2 buffers.
In your Clock Timer, you should check
Is the BlueTooth Client still Connected?
Is Bytes Available > 0?
IF Bytes Available > 0 THEN
set message var to BT.ReceiveText(-1)
This takes advantage of a special case in the ReceiveText block:
ReceiveText(numberOfBytes)
Receive text from the connected Bluetooth device. If numberOfBytes is less than 0, read until a delimiter byte value is received.
If you are sending multiple data values per message separated by | or comma, have your message split into a local or global variable for inspection before trying to select list items from it. Test if (length of list(split list result) >= expected list length) before doing any select list item operations, to avoid taking a long walk on a short pier. This bulletproofing is necessary in case your sending device sneaks in some commentary messages with the data values.
Here I am,
Many thanks to everyone who showed me how to solve the problem.
It works great now and I can increase the number of variables at any time ..... actually very easy if you understand it.
Enclosed the information: