Page 1 of 1

Help with strings

Posted: Fri Mar 30, 2018 7:13 pm
by BaartCM
Hello,

This post is a request for help using painlessMesh, but it is to do with string manipulation above all else.

I am creating a character array of 65536 elements representing 32784 ADC readings.

The ADC read routine is

Code: Select all

rdg=analogRead(ADC0);
twf[a]=(char)encoder((int(rdg/64)));
twf[a+1]=(char)encoder((int(rdg%64)));
The loop increments by 2 each time.

As the ADC is 12 bits, I encode each value to 2 ascii characters using this function to ensure certain character values are avoided

Code: Select all

int encoder(int data){
  if (data < 52)
    return data + 40;
  else
    return data + 45;
}
This results in an array of ascii characters from 40 to 52 and 57 to 109 avoiding problematic characters in JSON.

I want to send the data in 128 packets of 512 characters using the painlessMesh library. So I need to put the first 512 characters into a String (followed by further 512 char packets) called pkt so I can send it out over WiFi using

Code: Select all

mesh.sendBroadcast(pkt);
I have tried using

Code: Select all

  for(a=0; a<512; a++)
    pkt[a]=twf[a];
  pkt[512]='\0';
with pkt declared as a String and the code compiles and runs but doesnt work. I have also tried the same declaring pkt as char[513] and char* but both of those have errors at compile time.

If I replace the above code with pkt = "Anything at all", it works and me seconde ESP32 reports an incoming message perfectly. Where am I going wrong?

Please help, Im going insane trying to work it out! Steve.

Re: Help with strings

Posted: Fri Mar 30, 2018 10:54 pm
by kolban
When you say "String" ... do you mean String as in an Arduino environment? If so, this question might be best asked in the ESP32 Arduino forum?