HI All,
I'm working on a project and i read a page or data page from an external web server, i got the data alright it seems ok BUT,
when i transfer the string received from the HTTPClient httpClient.getString() i got the data in infos ok but when i convert the data using
payload.toCharArray(charArray,strlength) ; the charArray is an char array define in the same function as where i receive the page data from httpclient, and strlength is equal the length of the string payload + 1 .
The problem is the data display ok when i print the string received, but when i transfer it to the charArray i get all garbage.
Ex:
251,#FFFFFF,251,0,0,1
252,#FFFFFF,252,0,0,1
253,#FFFFFF,253,0,0,1
254,#FFFFFF,254,0,0,1
255,#00FFFF,255,1,0,0
This is some part of the data received, and this is the part of charArray printed character by character.
'⸮?8⸮?⸮4⸮?⸮⸮⸮'⸮?8⸮?⸮,'⸮?3
not exactly like that but you get the picture.
I know the page was saved using the character set UTF-8, i change it to ANSI and saved the page again erasing the old coding from UTF-8 to ANSI.
Normally everything should be ok but..
Here is a small example of the code
void setPanelDataToObject(String payload) {
const char *lineSep = "\r\n" ;
const char *delimiter = "," ;
char *token ;
char *p ;
char *mystring ;
int strlength = 0;
Serial.println("Result of parsing for each lines") ;
Serial.println("Should be complete lines with data each") ;
strlength = payload.length() + 1 ;
char charArray[strlength] ;
Serial.println(payload) ; // this print alwright
Serial.print("Size of charArray") ;
// that give me 11306 char element of 5662 bytes for the page
int size = sizeof(charArray) / sizeof(charArray[1]) ;
size += sizeof(charArray) / sizeof(charArray[0]) ;
Serial.println(size);
int i = 0;
payload.toCharArray(charArray,strlength) ;
// print the charArray caracter by caracter
while (i < size) {
Serial.print((String)charArray[i]) ;
i ++ ;
}
I don't know if there is a character set specific for adruino or the C string that prevent the right caracter from being copy to the charArray
So if somewhone knows a trick to transfer correctly to the charArray to have the right caracter, i must be missing something here i'm stuck here can't go any furter on my code because of this
Please help someone !!!