Ballscrewbob,
Thanks for your immediate answer.
I read your experiences about resetting the board, so thanks for avoiding me this task.
My IDE is the official, last 1.6.8 version, running over Windows 10. The WiFi101 library is version 0.9.1.
I know ESP's but, working with infrared codes, i needed to deal with processor-level instructions to set timers, and found more support over MKR boards. This part is now working fine, and the problem i'm facing is the webserver simple page stability.
I tryed to reduce it still more. Here you have the code:
#include <WiFi101.h>
const char ssid[] = "abc"; // created AP name
const char wifiPass[] = "def"; // AP password.
// the IP address for the shield:
const IPAddress privateIP(192, 168, 1, 61);
const IPAddress dns(192, 168, 1, 1);
const IPAddress gateway(192, 168, 1, 1);
const IPAddress netMask(255, 255, 255, 0);
WiFiServer server(80);
WiFiClient acServerClient;
void setup() {
WiFi.config(privateIP, dns, gateway, netMask);
delay(10000);
reconnectWifiIfNecessary();
server.begin(); // start the web server on port 80
}
void loop() {
reconnectWifiIfNecessary();
// Sending AC webpage:
processAcServer();
delay(200);
}
void reconnectWifiIfNecessary() {
while ( WiFi.status() != WL_CONNECTED) {
// Connect to WPA/WPA2 network:
WiFi.begin(ssid, wifiPass);
// wait 20 seconds for connection:
delay(20000);
}
}
void processAcServer() {
acServerClient = server.available(); // listen for incoming clients
if (acServerClient) { // if you get a client,
String currentLine = ""; // make a String to hold incoming data from the client
while (acServerClient.connected()) { // loop while the client's connected
if (acServerClient.available()) { // if there's bytes to read from the client,
char c = acServerClient.read(); // read a byte, then
if ((c == '\n') && (currentLine == "")) { // 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:
sendAcControlWebPage();
break;
}
if (c == '\n') { // 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
}
}
}
// close the connection:
acServerClient.stop();
}
}
void sendAcControlWebPage() {
// 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:
acServerClient.println("HTTP/1.1 200 OK");
acServerClient.println("Content-type:text/html");
acServerClient.println("Connection: close");
acServerClient.println();
// send web page
acServerClient.println("<!DOCTYPE html>");
acServerClient.println("<html>");
acServerClient.println("<head>");
acServerClient.println("<title>Control aire condicionat</title>");
acServerClient.println("</head>");
acServerClient.println("<body>");
acServerClient.println("<h3>CONTROL AIRE CONDICIONAT</h3>");
acServerClient.print("<h4>(PLANTA BAIXA) Versió: 1.0</h4>");
acServerClient.print("<p>Estat actual del aire condicionat: PARAT");
acServerClient.println("<form method=\"get\">");
acServerClient.println("<input type=submit value=\"Enviar\">");
acServerClient.println("</form>");
acServerClient.println("</body>");
acServerClient.println("</html>");
}
It would be very helpfull if someone could test the bahaviour of the sketch, compiling and trying to access the page.
To do this, simply replace the ssid name and password for the right ones, compile and upload the sketch. After waiting 1-2 minutes for the board to connect your wifi, try accessing it typing "192.168.1.61" in your browser. The goal is confirm if webpage is still available after a few hours.
Of course, you should change IP private addres & netmask if necessary, to match yours.
Thanks in advance!