I am keep getting very strange results every time i am trying to do things using strings and pointers.
i have this function :
void ParseGetRequest(char* data)
{
String parseGET=data;
String from="GET /";
String to="HTTP";
int ind1 = parseGET.indexOf(from);
int ind2 = parseGET.indexOf(to);
parseGET=parseGET.substring(ind1+from.length(), ind2-1);
strcpy(data, parseGET.c_str () );
}
Why am i getting strange behaviour when using it ? sometimes it brings back good results, sometimes garbage, sometimes the chip is reseting .
this is how i use it :
uint8_t buffer[128] = {0};
uint8_t mux_id;
uint32_t len = wifi.recv(&mux_id, buffer, sizeof(buffer), 100);
char serverData[100]={0};
if (len > 0)
{
for(uint32_t i = 0; i < len; i++)
serverData[i]=(char)buffer[i];
ParseGetRequest( serverData );
sometimes the chip is reseting .
That might be a power issue, or maybe something in the code you did not post.
MarkT
October 9, 2015, 4:52pm
3
You don't check the result of indexOf is valid - I suspect you are using -1 as in index causing
out-of-bounds access.
Mark well. I have check things out and its very strange ! my print is just not printing everything !
Is there a buffer for the print command that is full or something ??
check this out :
parseGET=parseGET.substring(ind1+from.length(), ind2-1);
Serial.println("!!");
Serial.println(data);
Serial.println("!!");
Serial.println(parseGET);
Serial.println("!!");
strcpy(data, parseGET.c_str () );
Will output this :
!!
GET /setWifi:name:num HTTP/1.1
Host: 192.168.4.1
Accept: */*
Accept-Language: en-us
Conne
Where the hell the rest of it ?!
Can you change these?
Serial.println("!!");
Maybe the !! is causing weird things to happen?
Maybe the !! is causing weird things to happen?
Good eye on the old !! issue.
Robin2
October 9, 2015, 6:08pm
8
It is not a good idea to use Strings (capital S) in the small memory of an Arduino. It can cause memory corruption. It is much safer to use strings (small s). These are the string functions
...R