Hi,
I'm a owner of a MKR1000, and i think we got same problem.
I was trying to control a home device through a webpage on my wifi board but, after a few hours working fine, it stops responding http requests from a webrowser.
This issue was explained in this post:
http://forum.arduino.cc/index.php?topic=401107.0
After a lot of issues and debugs, i concluded it's because a problem in the wifi part of the sketch, so
i extracted all unnecessary code to detect the problem.
Finally, and to be sure, i loaded the example included with the WiFi101 library, named 'AP_SimpleWebserver', and cleaned the unnecessary sentences (basically, deleted all the 'Serial.println()' ones).
So the code lasts this way:
/*
WiFi Web Server LED Blink
A simple web server that lets you blink an LED via the web.
This sketch will print the IP address of your WiFi Shield (once connected)
to the Serial monitor. From there, you can open that address in a web browser
to turn on and off the LED on pin 9.
If the IP address of your shield is yourAddress:
http://yourAddress/H turns the LED on
http://yourAddress/L turns it off
created 25 Nov 2012
by Tom Igoe
*/
#include <SPI.h>
#include <WiFi101.h>
int led = LED_BUILTIN;
char ssid[] = "wifi101-network"; // created AP name
char pass[] = "1234567890"; // AP password (needed only for WEP, must be exactly 10 or 26 characters in length)
int keyIndex = 0; // your network key Index number (needed only for WEP)
int status = WL_IDLE_STATUS;
WiFiServer server(80);
void setup() {
pinMode(led, OUTPUT); // set the LED pin mode
// attempt to connect to Wifi network:
while ( status != WL_CONNECTED) {
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
status = WiFi.begin(ssid, pass);
// wait 10 seconds for connection:
delay(10000);
}
server.begin(); // start the web server on port 80
}
void loop() {
WiFiClient client = server.available(); // listen for incoming clients
if (client) { // if you get a client,
String currentLine = ""; // make a String to hold incoming data from the client
while (client.connected()) { // loop while the client's connected
if (client.available()) { // if there's bytes to read from the client,
char c = client.read(); // read a byte, then
if (c == '\n') { // if the byte is a newline character
// if the current line is blank, you got two newline characters in a row.
// that's the end of the client HTTP request, so send a response:
if (currentLine.length() == 0) {
// HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
// and a content-type so the client knows what's coming, then a blank line:
client.println("HTTP/1.1 200 OK");
client.println("Content-type:text/html");
client.println();
// the content of the HTTP response follows the header:
client.print("Click <a href=\"/H\">here</a> turn the LED on<br>");
client.print("Click <a href=\"/L\">here</a> turn the LED off<br>");
// The HTTP response ends with another blank line:
client.println();
// break out of the while loop:
break;
}
else { // if you got a newline, then clear currentLine:
currentLine = "";
}
}
else if (c != '\r') { // if you got anything else but a carriage return character,
currentLine += c; // add it to the end of the currentLine
}
// Check to see if the client request was "GET /H" or "GET /L":
if (currentLine.endsWith("GET /H")) {
digitalWrite(led, HIGH); // GET /H turns the LED on
}
if (currentLine.endsWith("GET /L")) {
digitalWrite(led, LOW); // GET /L turns the LED off
}
}
}
// close the connection:
client.stop();
}
}
Due to the absence of Serial outputs, you wont be informed about your board ip address, but this could be done asking your router's DHCP client's list.
This code starts working perfect but, after a variable time, stops responding the webbrowser.
I asked Arduino Support, but got still no response.
It would be very helpfull if someone could also verify this behaviour, and find some explanation.
Thanks!
mephala