help string comparison indxof


good evening, created sketch receive request php curl. has find string in request. code:

code: [select]
#include <spi.h>
#include <ethernet.h>
#include <wstring.h>

byte mac[] = {0xde, 0xad, 0xbe, 0xef, 0xfe, 0xed};

ipaddress ip(192, 168, 0, 177);

ethernetserver server(90);

void setup()
{
serial.begin(9600);
ethernet.begin(mac, ip);
server.begin();
serial.print("server @ ");
serial.println(ethernet.localip());
}

void rispondi(string risposta, ethernetclient ethclient)
{
ethclient.println("http/1.1 200 ok");
ethclient.println("content-type: text/html");
ethclient.println("connection: close");// connection closed after completion of response
ethclient.println("refresh: 5");// refresh page automatically every 5 sec
ethclient.println();
ethclient.println("<!doctype html>");
ethclient.println("<html><body>");
ethclient.println(risposta);
ethclient.println("</body></html>");
}

void loop()
{
string result = string();
string prova = string();
char c;
ethernetclient client = server.available();
if (client)
{
serial.println("new client");
boolean currentlineisblank = true;
boolean sentheader = false;
while (client.connected())
{
if (client.available())
{
while(client.available())
{
char c = client.read();
    result += c;
    if(c == '\n')
    {
    break;
    }
}
}

int on = result.lastindexof('pin13=on');
int off = result.lastindexof('pin13=off');

        //rispondi(result, client);//debug
if(on > 0)
{
digitalwrite(13, low);
rispondi("on", client);
}
if(off > 0)
{
digitalwrite(13, low);
rispondi("off", client);
}
break;

}

}
delay(1);
client.stop();
serial.println("client disconnected");
}


the script writes on if request off, can help?

code: [select]
int on = result.lastindexof('pin13=on');
i don't use or strings, i'm pretty sure should double quotes.


Arduino Forum > Using Arduino > Programming Questions > help string comparison indxof


arduino

Comments

Popular posts from this blog

invalid use of void expresion in FlexiTimer2 library

error: a function-definition is not allowed here before '{' token

LED Strip Code