If you do need to process long strings and have to chop them up, it would probably be easier to define them as a char array rather than a C++ String, as you can stipulate 'lengths' of strings in characters and not require delimiters for strtok() to find - unless of course the real data actually arrives with convenient delimiters. Note that String Object uses more memory though.
For Serial1, #include <SoftwareSerial.h> needs to be added to the Sketch, because you also output to the Arduino Serial Monitor and the Uno only has one Serial channel.
Hi ChrisWard !
First Thank you very very very much !!!
I answer you with delay… and Google translate… sorry.
MitSendReceiveBLE.aia (163.2 KB) MitSendReceiveHC05.aia (169.9 KB)
"What is all that play one time, play 2x, play 3x? (with delays in between)? »
> When Arduino sends message sometimes data is lost, I don't know why. With delays It's better but not perfect .If Arduino plays twice, that's fine. So I play 3 times to be sure !!!
"Do you just require to send the integer values ar and jr to the App?"
> For the project, I will need to send a dozen integer values like: ar = 11, aj = 22, ak = 333, an = 2313, ap = 54, at = 6574 ...
"….floats or integers?"
> Integers, I declare "int: xx »
"…. Uno only has one Serial channel."
> I use Mega.
I try what you sent me today and I will tell you tonight.
Have a good day !
Which library do you use?
#include <BLEDevice.h>
#include <BLEServer.h>
#include <BLEUtils.h>
#include <BLE2902.h>
They are inter-related, <BLEServer.h> is being used in the Sketch for your Test.
Good evening Chris,
Yes I saw. I spend all my time trying to find solutions! first with your sketch and also with tutorials found here! I row !
with all informations I take here, I'm learning a lot!
I will allow myself to show you what I managed to do! And if that can help other people, that will be cool!
There are some good links plus tips on my website:
https://www.professorcad.co.uk/appinventortips#TipsArduino
https://www.professorcad.co.uk/appinventortips#TipsBluetooth
Hello,
I finally managed to receive the strings and split them properly!
Thanks to ChrisWard and ABG for helping me.
Now, I must succeed in sending strings of more than 20 characters from the app to the arduino!
I continue to move forward ... slowly ... but I move forward!
And message from arduino :
Serial1.println("a=" + String(a) );
delay(100);
Serial1.println("j=" + String(j) );
delay(100);
Serial1.println("d=" + String(d) );
delay(100);
Serial1.println("m=" + String(m) );
I give you my first remarks on sending Strings :
example 1:
If I send data like this, I only get the first twenty characters:
d = 29 & b = 12 & y = 2020 & h = 1
example 2:
If I send data like this, I receive all characters in monitoring serial arduino : d=29&b=12&y=2020&h=15&m=25&s=12
But my "decoupeur" only sees the first twenty characters too
void decoupeur(String inputString){
char inputChar[inputString.length()+1] ;
inputString.toCharArray(inputChar,inputString.length()+1);
char* command = strtok(inputChar, "&");
// boucle sur toutes les commandes
while (command != 0)
{
char* valueCommand = strchr(command, '=');
if (valueCommand != 0)
{
*valueCommand = 0;
++valueCommand;
if(String(command) == "d"){
ddBase = String(valueCommand).toFloat();
}
if(String(command) == "b"){
bbBase = String(valueCommand).toFloat();
}
if(String(command) == "y"){
yyBase = String(valueCommand).toFloat();
}
if(String(command) == "h"){
acc = String(valueCommand).toFloat();
}
if(String(command) == "m"){
jrec = String(valueCommand).toFloat();
}
if(String(command) == "s"){
setPar = String(valueCommand).toFloat();
}
}
command = strtok(0, "&");
}
}
You do not need those delays! Just manage the Loop properly with elapsed milliseconds.
First of all, as I have said before, send only values, no labels. That alone saves bytes.
So your string could be less characters:
29|12|2020|01|00|00
However, you could send the values as individual packets and not need the decoupeur procedure at all, just a code for Substring + Switch to work with on receipt of data.
why it's better with millis ?
A delay() blocks everything.
You are a difficult one to help Sledge because you have no stated goal - what, at the end of the day, will be the purpose of your App? Where do the long strings come from and what are they for?
Hi ChrisWard,
yes I know ! me too !!! I don't know where I'm going
I try to understand by doing experiments.
I have a display project but for now I am experimenting.
I have a new question:
I see I can send 2 packets of strings to arduino.
How can I combine them into one dans l'arduino ?
Sorry... How can I combine them into one IN arduino ?