Can someone help me to understand how to do this, i tried many many ways but there is always an error when i tried to compile my script
What i'm trying to do is convert a string to a char array, and for some crazy reasons whatever i try it always give me a compile error.
Here what i try to convert string
This is juste a small portion of the string coming from loading a web page containing parameters for different led panel 16x16 as an example
001,16,16,256,000,0
000,#FF0000,000,1,0,0
001,#00FF00,001,0,0,0
002,#0000FF,002,1,0,0
003,#FFFFFF,003,0,0,1
004,#FFFFFF,004,0,0,1
005,#FFFFFF,005,0,0,1
006,#FFFFFF,006,0,0,1
007,#FFFFFF,007,0,0,1
008,#00FF00,008,0,0,0
009,#FFFFFF,009,0,0,1
010,#FFFFFF,010,0,0,1
011,#FFFFFF,011,0,0,1
012,#FFFFFF,012,0,0,1
This is an US-ASCII file encoded
NOTE I don't have a choice to use STRING since the function return a String object
Here is my sample code
// note the payload string come from httpGet from httpClient lib
void setPanelDataToObject(String payload) {
/* function to process the panels data into memory of esp32
the data is contained in payload string and must be parsed
to the panel and led objects
*/
// get the first line of panel
const char *lineSep = "\r\n" ;
const char *delimiter = "," ;
char *p ;
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 *myString[strlength] ;
payload.toCharArray(myString,strlength) ;
// char *strncpy(myString,payload.c_str(),strlength) ;
Serial.println("Payload String from panel1.html") ;
Serial.println(payload) ;
char *token = strtok(myString,lineSep) ;
while (token != NULL) {
Serial.println(token) ;
// this is to get every line separate and later get each parameter of that line
// to be put in an object class that can be used!
token = strtok(NULL,lineSep) ;
}
}
type or paste code here
And this is the error that i get when compiling
MULTI-PANEL-8266-SETUP:295:47: error: no matching function for call to 'String::toCharArray(char* [strlength], int&)'
payload.toCharArray(myString,strlength) ;
^
In file included from C:\Users\jchar\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/Arduino.h:165,
And if this is not the same error it don't give,it always gives me the non possibility to convert to Char array by using other method like strncpy in c String class etc.
This normally will take me a week or 2 to finish my code in other language that i use currently.
I must say that i never programmed in C++ or in adruino but i know how to program stuff i know my way around in other language.
The only thing that should be simple enought already take me 2 month to understand (to some extend) the C++ language and mosthly it's illarious syntax that supposedly to be simple in Adruino.
I programs other stuff in Adruino but here i hit a wall, cause i don't know what i'm doing wrong, i follow many samples in the forum but i'm stuck here, maybe i'm doing something wrong i don't know and i'm on the verge of abandonning this project that took me way too much time.
So PLEASE if someone knows a way to fix this i would really really appreciate the inlightning of this code.
Thanks all and Happy programming