Wifi shield disconnect
hello everyone,
i've problems arduino wifi shield.
i created simple code turn on /off led via browser. looked on internet exemple , found code use methode. encountered issues:
so don't have time change state of led because takes long between each methode , because server disconnect after short time.
i hope have been clear.
thank .
i've problems arduino wifi shield.
i created simple code turn on /off led via browser. looked on internet exemple , found code use methode. encountered issues:
- after +/- 30 seconds/ 1minute can't connect server ( inaccessible web page on browser
- i read http request on the serial monitor , between differents request when press on(get /?ledon http/1.1) or off(get /?ledon http/1.1) each time press on/off or when refresh page arduino send different header( get/host/connection/accepte/...)
so don't have time change state of led because takes long between each methode , because server disconnect after short time.
code: [select]
include <spi.h>
#include <wifi.h>
char ssid[] = "labowifi"; // network ssid (name)
char pass[] = "wilfart2013"; // network password
int keyindex = 0;// network key index number (needed wep)
string readstring;
wifiserver server(80);
int status = wl_idle_status;
int blue =6;
int green=5;
int red=3;
int brightness = 0;
int delay =5;
//////////////////////
void setup(){
pinmode(6, output); //pin selected control
//start ethernet
server.begin();
status = wifi.begin(ssid, pass);
//enable serial data print
serial.begin(115200);
serial.println("server led test 1.0"); // can keep track of loaded
printwifistatus();
}
void loop(){
// create client connection
wificlient client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
//read char char http request
if (readstring.length() < 100) {
//store characters string
readstring += c;
serial.print(c);
}
//if http request has ended
if (c == '\n') {
///////////////
serial.println(readstring); //print serial monitor debuging
//now output html data header
if(readstring.indexof('?') >=0) { //don't send new page
client.println("http/1.1 204 zoomkat");
client.println();
client.println();
}
else {
client.println("http/1.1 200 ok"); //send new page
client.println("content-type: text/html");
client.println();
client.println("<html>");
client.println("<head>");
client.println("<title>projet lamp-wifi</title>");
client.println("</head>");
client.println("<body>");
client.println("<h1>projet wifi-lamp</h1>");
client.println("<a href=\"/?ledon\" target=\"inlineframe\">on</a>");
client.println("<a href=\"/?ledoff\" target=\"inlineframe\">off</a>");
client.println("<iframe name=inlineframe style=\"display:none\" >");
client.println("</iframe>");
client.println("</body>");
client.println("</html>");
}
delay(1);
//stopping client
client.stop();
///////////////////// control arduino pin
if(readstring.indexof("ledon") >0)//checks on
{
digitalwrite(6, high); // set pin 6 high
serial.println("led on");
}
if(readstring.indexof("ledoff") >0)//checks off
{
digitalwrite(6, low); // set pin 6 low
serial.println("led off");
}
//clearing string next read
readstring="";
}
}
}
}
}
void printwifistatus() {
// print ssid of network you're attached to:
serial.print("ssid: ");
serial.println(wifi.ssid());
// print wifi shield's ip address:
ipaddress ip = wifi.localip();
serial.print("ip address: ");
serial.println(ip);
// print received signal strength:
long rssi = wifi.rssi();
serial.print("signal strength (rssi):");
serial.print(rssi);
serial.println(" dbm");
}
i hope have been clear.
thank .
the wifi library/firmware server code unreliable. has been known send corrupted files , incorrect files, when 2 requests pending simultaneously. socket problem. wifi firmware uses 1 socket server, , socket never quits listening new requests, second request while first request still being processed causes corruption problem.
Arduino Forum > Using Arduino > Programming Questions > Wifi shield disconnect
arduino
Comments
Post a Comment