Hi,
I'm trying to have simple protocol to command Arduino over enc28j60 from pc to adjust servo position, read sensor, etc.
I use a lib from here now:
First please have a look in my code:
...
String strSrvCmdArr = ""; //initialized
...
void loop()
{
analogWrite(5, 0);
char* params;
if (params = e.serviceRequest())
{
e.print("<H1>Hello there!</H1>");
for(int i=1;params[i];i++)
{
strSrvCmdArr += params[i];
}
Serial.println(strSrvCmdArr);
strSrvCmdArr = "";
e.respond();
}
}
Based on info of the web site I got the ENC28J60 lib from, "params = e.serviceRequest()" will load params either with incoming request including '?' char or params will be null.
Next, this is my guess that if I request like:
http://arduino-ip/?someCmd=smth
then param will have first character as '?', then there will be these characters: someCmd=something, and finally a '\n' (or '\0'?). But trying like:
for(int i=1;params[i]!='\n';i++)
returned the string correct, but continued with many strange characters (including squares that serial window didn't recognized as characters).
Next and the main problem:
when I changed to:
for(int i=1;params[i];i++)
I started to get this output:
someCmd=smth
someCmd=smthavicon.ico
where the avicon.ico is not mine! I ordered as: http://arduino-ip/?someCmd=smth, in my browser! I guess that is favicon.ico, but these questions:
- why I got 2 times the request?
- how favicon.ico jumped into string?
- what is the best practice? may be better to make request like:
http://arduino-ip/?someCmd=smth&endOfCmd
and just extract between ? and endOfCmd, to hit right service request parameters? - how to protect one command to not to be sent for 2 times, this way? In browser I hit enter key only once, but my params got loaded 2 times, what to do?
- why this didn't work:
for(int i=1;params[i]!='\n';i++)
Please help so I get a clear mind to go on..