Copy string to byte array

Hi all sorry for this question, I'm totally new arduino user , my question is how to copy this string coming from server.arg parameter

String 168,0,1,2,50,1,1,255,100,0,52,48,54,52
To
Byte store[] = {176,1,0,2,64,50};

someone help my please
I don't want to convert it, just need the same numbers
Thanks

i send that parameter from mit app inventor
http://192.168.4.1/action_page?soft=168,0,1,2,50,1,1,255,100,0,52,48,54,52,55,53,9,8,65,66,8,0,38

void handleForm() {
softstring = server.arg("soft");
 String s = "<a href='/'> Go Back </a>";
 server.send(200, "text/html", s); //Send web page
 Serial.begin(9600);
 Serial.print(softstring);

serial result
168,0,1,2,50,1,1,255,100,0,52,48,54,52,...........

this is not proper String
so, how your string looks really like?

1 Like

Do you mean:
String s = "176,1,0,2,64,50"; // Comma separated values

1 Like

yes any idea plz

serial result
168,0,1,2,50,1,1,255,100,0,52,48,54,52,...........

Use:

To find each comma.

Use:

To pull out the part of the string between commas.

1 Like
byte Array [6] = {0};
if (Serial.available() >= 1) {
  for (byte i = 0; i < 6; i++) {
    Array[i] = Serial.parseInt();
  }
}
1 Like
void handleForm() {
softstring = server.arg("soft");
 String s = "<a href='/'> Go Back </a>";
 server.send(200, "text/html", s); //Send web page
 Serial.begin(9600);
 Serial.print(softstring);

 byte Array [128] = {0};
if (Serial.available() >= 1) {
  for (byte i = 0; i < 128; i++) {
    Array[i] = Serial.parseInt();
    Serial.print(Array[i]);
  }
}  
byte WriteData[128];
memcpy(WriteData,Array,128*sizeof(byte));
   }

serial print the string only and print 0 every second after the string
where is the problem plz

are you sure that 128 bytes are really ready to be read from serial? show how you send it actually.

so, at the end is no ending symbol

128 up to 512

what end symbol i have to write?

you can send first byte(or two) to say how much byte of data will be sent and last byte (or two) should be checksum.

You are reading 128 numbers even if the data runs out. When you are out of data and still call Serial.parseInt() it will time-out after 1 second and return 0.

Try:

if (Serial.available() > 0) {
  for (byte i = 0; i < 128; i++) {
    Array[i] = Serial.parseInt();
    Serial.print(Array[i]);
    if (Serial.available() == 0)
     break;
  }
}  
1 Like

it show one 0 and break
reading 5 numbers also the same

do you able to sent numbers not as sequence of decimal digits but as single byte?
and why you sending URL over serial?

void handleForm() {
softstring = server.arg("soft");
 String s = "<a href='/'> Go Back </a>";
 server.send(200, "text/html", s); //Send web page
 Serial.begin(9600);
 Serial.print(softstring);

is this routine which send the string?
do you place this line in both sketches?
#define SERIAL_BUFFER_SIZE 256

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.