I am new to MIT and have tried to split a string.
How to split string at | and result to variables ?
The ESP32 code
if(currentMillis - previousMillis_BLE1 > interval_BLE1) {
float TemperatureBLE1 = random(10,60000)/1000.0; // 3 decimals
float HumidityBLE1 = random(5,99000)/1000.0; // 3 decimals
String temperatureBLE1 = String(TemperatureBLE1,2);
String humidityBLE1 = String(HumidityBLE1,2);
String tem_hum_BLE1 = temperatureBLE1 + "|" + humidityBLE1 + "|" + humidityBLE1;
std::string value = pCharacteristic->getValue();
pCharacteristic->setValue(tem_hum_BLE1.c_str()); // Notify.
pCharacteristic->notify();
TIMAI2
November 25, 2021, 10:22am
2
Use the split at
block in the text palette
splits by the delimiter to a list which you can then apply to variables
2 Likes
Am I heading in the right direction?
How to read the values from the list ?
TIMAI2
November 25, 2021, 1:16pm
4
You should use the replacement blocks and join the lbl_receiveBLE1.Text before you split. The way you have it is converting the list back into a string.
1 Like
Dear TIMA12,
Can you make a example ?
TIMAI2
November 25, 2021, 2:10pm
6
Please provide some output that you are trying to parse, as text here.
1 Like
The string from te ESP32 = (49.44|71.03|22.56)
What I want to achieve;
lbl_1_1 gets 49.44
lbl_1_2 gets 71.03
lbl_1_3 gets 22.56
Create a local list variable, and assign it to the split value. Set lbl_1_1's text to the 1st index of the list (use the get from list block), lbl_1_2's text to the 2nd index, and lbl_1_3's text to the 3rd index.
Yes, it works.
Thanks for the effort.
system
Closed
December 3, 2021, 7:27am
11
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.