Hi there,
I have a problem with my code and sometimes stops running.Most of the times when I am sending large data strings. I think its because of the size of the client readstring().It just saves 50 charactes send from /GET.
I tried to find the readstring function to modify its size but it just says "size" in the Ethernetclient.cpp file. How can I set it? Where is it stored?
Does anybody know?
EthernetClient client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
//read char by char HTTP request
if (readString.length() < 150) {
//store characters to string
readString += c;
//Serial.print(c);
}
//if HTTP request has ended
if (c == '\n') {
....................
...............
}
}
}
I use a character array of a fixed size to store the GET request from a client. Try this code. http://playground.arduino.cc/Code/WebServerST
It is the variable tBuf[] that holds the request string.
I have a problem with my code and sometimes stops running.
And it will continue to have problems until you get rid of the String.
I tried to find the readstring function to modify its size
readString is an instance of the String class. It has methods, not functions. The readStrring instance takes care of its size by itself. You don't need to do anything to help it.
I managed to change all my scketch using arrays this time.
How can I search for a word in an array???
for example: if I have an array with size of 50, called char array[];
and I need to search for the word "key" how can I do it?
I am trying using if (strcmp,"key"==0) but its not the right one.
There are so many assumptions in this question. How do you define a word?
You can use a number of string functions to search for a string in a string. None of them will know, or care, that the string being searched for meets your definition of a word.
if I have an array with size of 50, called char array[];
and I need to search for the word "key" how can I do it?
Is array properly NULL terminated? Have you looked at strstr()?
I am trying using if (strcmp,"key"==0) but its not the right one.
Not for finding a string in a string, unless the string being search is exactly the string be searched for, which seems unlikely. Or, it would be working.
http://www.cplusplus.com/reference/cstring/strstr/
That's the link I found.It helped me with strstr but only when tBuf just contains "off" if it contains more info it can't find off.
Why is this happening?
I am not so familiar with string manipulation so I don't know much. I am trying to do that all day with no luck.
char offarray[] ="off";
char tBuf[64];
if(strstr(tBuf,"off") != NULL)//checks for off
{
digitalWrite(9,HIGH); // set pin 4 low
Serial.println("Led On");
Serial.println(tBuf);
delay(500);
}
What tBuf contains: "GET /?username=off&password=&submit=Log+In HTTP/1.1"
"if(strstr(tBuf,"off") != NULL)" never goes TRUE
but "if(strstr(tBuf,"GET") != NULL)" does because it starts with that...
The sketch runs smoothly if we have just 2 ifs. If I add the third one, no matter which is it, it needs reset. and it doesn;t print anything. Strange right?
I've serial prints in every if statement but it doesn;t print not even the first one.
"if(strstr(tBuf,"off") != NULL) {
loggedin=0;
digitalWrite(9, LOW); // set pin 4 high
Serial.println("Led Off!");
}"
But when I add it to this one it needs to be reseted. it stops in the first loop.it doesn't do anything else.arduino freezes none of the serials print on monitor....