I have a basic webduino server running on my Arduino + WIZ811MJ. Everything works fine, I can pull up the page from the server, click a button on the page, reload the page.
The problem comes up after the server has been running for several hours (aprox 4-8hrs), the server seems to go offline. I am then unable to access the server through my web browser. If I hit the reset button on the Arduino, everything returns to working order.
Here is the code. This is based off the Web_Buzz example that comes with the Webduino library.
I am using dyndns.org , but when it goes offline I am unable to access the Arduino via the dyndns.org domian or via the IP address on the local network. Also, it has failed several times today, so it is not necessarily the 4-8 hrs that I suggested in the original post.
Let me know if you have any ideas.
/* Based on Web_Buzzer.pde - example sketch for Webduino library */
#include "SPI.h" // new include
#include "avr/pgmspace.h" // new include
#include "Ethernet.h"
#include "WebServer.h"
// no-cost stream operator as described at
// http://sundial.org/arduino/?page_id=119
template<class T>
inline Print &operator <<(Print &obj, T arg)
{ obj.print(arg); return obj; }
/* CHANGE THIS TO YOUR OWN UNIQUE VALUE. The MAC number should be
* different from any other devices on your network or you'll have
* problems receiving packets. */
static uint8_t mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
/* CHANGE THIS TO MATCH YOUR HOST NETWORK. Most home networks are in
* the 192.168.0.XXX or 192.168.1.XXX subrange. Pick an address
* that's not in use and isn't going to be automatically allocated by
* DHCP from your router. */
static uint8_t ip[] = { 192, 168, 1, 200 };
/* all URLs on this server will start with /led because of how we
* define the PREFIX value. We also will listen on port 80, the
* standard HTTP service port */
#define PREFIX "/led"
WebServer webserver(PREFIX, 8180);
/* the piezo speaker on the Danger Shield is on PWM output pin #3 */
#define LED_PIN 6
/* this is the number of microseconds to wait after turning the
* speaker on before turning it off. */
int ledStatus = 0;
int clickCount = 100;
void ledCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete)
{
if (type == WebServer::POST)
{
bool repeat;
char name[16], value[16];
do
{
/* readPOSTparam returns false when there are no more parameters
* to read from the input. We pass in buffers for it to store
* the name and value strings along with the length of those
* buffers. */
repeat = server.readPOSTparam(name, 16, value, 16);
/* this is a standard string comparison function. It returns 0
* when there's an exact match. We're looking for a parameter
* named "led" here. */
if (strcmp(name, "led") == 0)
{
/* use the STRing TO Unsigned Long function to turn the string into a number value */
ledStatus = strtoul(value,NULL,10);
clickCount++;
}
} while (repeat);
Serial.println("WebServer::POST (" + String(clickCount) + ")");
// after procesing the POST data, tell the web browser to reload
// the page using a GET method.
server.httpSeeOther(PREFIX);
return;
}
/* for a GET or HEAD, send the standard "it's all OK headers" */
server.httpSuccess();
/* we don't output the body for a HEAD request */
if (type == WebServer::GET)
{
Serial.println("WebServer::GET (" + String(clickCount) + ")");
/* store the HTML in program memory using the P macro */
P(htmlHead) =
"<html>"
"<head>"
"<title>Feltpad Arduino LED</title>"
"<meta name='viewport' content='width=device-width,maximum-scale=1.0' />"
"</head>"
"<body style='background-color:black; color:white;'>";
server.httpSuccess();
server.printP(htmlHead);
server << "<div>
";
server << "The LED is currently ";
server << (ledStatus==1 ? "ON (" : "OFF (");
server << clickCount;
server << ")
";
server << "<form action='/led' method='POST'>";
server << "<p><button name='led' value='0'>Turn it Off</button></p>";
server << "<p><button name='led' value='1'>Turn it On</button></p>";
server << "</form>";
server << "</div></body></html>";
}
}
void setup()
{
// set the PWM output for the led to out
pinMode(LED_PIN, OUTPUT);
// setup the Ehternet library to talk to the Wiznet board
Ethernet.begin(mac, ip);
/* register our default command (activated with the request */
webserver.setDefaultCommand(&ledCmd);
/* start the server to wait for connections */
webserver.begin();
Serial.begin(9600);
}
void loop()
{
// process incoming connections one at a time forever
webserver.processConnection();
//Serial.println("Value: " + String(ledStatus));
/* every other time through the loop, turn on and off the speaker if
* our delay isn't set to 0. */
if (ledStatus == 1)
{
digitalWrite(LED_PIN, HIGH);
} else {
digitalWrite(LED_PIN, LOW);
}
}
I am wondering if it is something with my setup, or something with my network... I loaded the standard WebServer example and it runs for about an hour before I cannot pull it up in my browser. Hard to say what's going on, I will put in some Serial outputs and monitor what happens.
Not sure about the make of your ethernet arduino, but if it can run the same server code as a standard w5100 shield, you might want to try the below meta refresh code. I loaded it on my arduino and opened the refreshing page using the IE brouser. I let it run over night and while at work. When I got home from work it was still refreshing with the page showing a 30k+ count.
// for W5100 ethernet shield
// the IP address will be dependent on your local network/router
// port 80 is default for HTTP, but can be changed as needed
// use IP address like http://192.168.1.102:84/ in your brouser
#include <SPI.h>
#include <Ethernet.h>
int x=0;
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 102 };
Server server(84);
void setup()
{
// start the server
Ethernet.begin(mac, ip);
server.begin();
}
void loop()
{
// listen for incoming clients
Client client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
// see if HTTP request has ended with blank line
if (c == '\n') {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
//meta-refresh page every 2 seconds
x=x+1;
client.print("<HEAD>");
client.print("<meta http-equiv=\"refresh\" content=\"2\">");
client.print("<TITLE />Zoomkat's meta-refresh test</title>");
client.print("</head>");
client.print("page refresh number ");
client.println(x);
client.println("
");
client.println("
");
// output the value of each analog input pin
for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
client.print("analog input ");
client.print(analogChannel);
client.print(" is ");
client.print(analogRead(analogChannel));
client.println("
");
}
break;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
}
}
Okay I tried Zoomkat's script and the browser got stuck around 2500 (aprox 2 hrs). I hit the refresh button and it then loaded fine - but I am not sure how long it was stuck before I refreshed it. I continued to run it over night and when I woke up it was stuck around 7000. Again, I hit the refresh button and it then loaded fine...
Any ideas what this means / what is going on here?
Edit:
So I guess this tells me that it is not a problem with the Webduino code, but something with my hardware or network?
So I guess this tells me that it is not a problem with the Webduino code, but something with my hardware or network?
Why do you think that?
It's possible that resetting your Arduino changes something in your network but equally it could be a problem with the Arduino code or even an issue with your Arduino / Shield.
If you think it's your network, have you tried running it without connecting to the network, or perhaps just connecting it to your development machine (a very small network). You will probably have to give your development machine a static IP address temporarily while you run the test.
What are you using on your development machine? Windows, Mac or Linux?
What is displayed in the brouser, a no connection error? Is any part of your network wireless? If you reload the page in the brouser, does the refresh restart? If your arduino is connected to a router, does the router still show the arduino connected on that port?
When I say "So I guess this tells me that it is not a problem with the Webduino code, but something with my hardware or network?", what I mean is that I don't think the problem is with the Webduino Server Framework, which I was using with the original setup. When I was using the the Webduino Server Framework, I would get a "Page not available" error.
But, zoomkat's script does not use the Webduino Server Framework. When the server stopped responding, the browser just continued spinning as if it was receiving data. When I hit the refresh button, it instantly started working again.
My (Arduino) Ethernet WIZ811MJ Module is connected to a wireless bridge, which is connected through WiFi to my Router. I can see that could be one spot where problems could be arising - but when I was using the Webduino Server Framework, the problem was fixed by resetting the Arduino, not by resetting the wireless bridge.
As an aside, zoomkat's script has been running uninerrupted for the last 8 hours...