Showing arduino status on a web page

I need to be able to show the status of my Arduino on a web page. If the Arduino is running and the ethernet shield is fully functional, it should show "operational". If for some reason someone unplugged the Arduino, it should show "off line".

I've tried commands like "client.println" from the Arduino to an iframe on a web site without success.

Can anyone help me here?

I need to be able to show the status of my Arduino on a web page.

This won't happen by magic. Something has to serve up that web page. Something has to (periodically) request that web page and do some processing of the data.

If the Arduino is running and the ethernet shield is fully functional, it should show "operational". If for some reason someone unplugged the Arduino, it should show "off line".

So, the Arduino is to act as a server, and send a web page that includes some text that says "operational". When the server is offline, powered down, put in a box in a drawer, etc. it should still serve up a page that includes some text that says "off line".

Do you have any idea how ridiculous that sounds?

I've tried commands like "client.println" from the Arduino to an iframe on a web site without success.

Was this when the Arduino was offline, in a box, in a drawer?

Can anyone help me here?

I'm starting to have my doubts. But, you need to define whether you have had success with even the sample web server sketch on the Arduino. If you are having issues getting it to work as a web server at all, that's one thing.

If you are having problems getting it to serve up a page when it is offline, powered down, in a box in a drawer, that's another thing.

PaulS - thanks, but sarcastic answers like that are not particularly helpful.

Yes, I have the Arduino fully functioning as a web server and receiving commands from a web page. And no, I don't expect it to serve up web pages when powered down, in a drawer, etc. I expect the code on the web site to realize it is not receiving an "operational" response from the Arduino and display the default "off line" status.

The trouble I'm having, especially as shown in my client.println example, is in sending a status message from the arduino to the website. I'm also interested in what the default code on the web page would look like if it doesn't receive the "operational" status.

You haven't given any details on what you are doing on either the client or server side. It is difficult to guess why it "isn't working."

If I were approaching your situation, I wouldn't bother with the Arduino pushing it's status to the server. Instead, I would use the server to poll the Arduino when the web page is loaded. If after a reasonable amount of time no response occurs assume the Arduino isn't operating.

You could put a simple arduino meta refresh frame in your main web page that just cycled once a minute thru something like 1-10. when the arduino is off line an error message will appear instead of the number. Below is some simple arduino meta refresh code.

// 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/ 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(80);

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();
  }
}

I expect the code on the web site to realize it is not receiving an "operational" response from the Arduino and display the default "off line" status.

It usually works better when your expectations meet reality, at least part way.

There is no "code on the website" to "realize" anything. Some application on the PC, typically a web browser, makes a GET request to a server. The server either responds with a reply that contains a stream of data that the browser recognizes, or it doesn't.

If, after some period of time, there is no reply from the server that the GET request was directed to, it is up to the application that made the request to take appropriate action. Typically, that involves displaying a generic page that says that the server was taking to long to respond.

You would have to be running an open source browser, and you would have to hack the source code that displayed the generic "server not available" page to display some different data if the GET request was made to a specific server.

I'm confused about the OPs task... Is there a computer monitoring the Arduino that is acting as a web server, or is the web server actually on the Arduino? I would think the former, but his reference to an enet connection on the Arduino has me unsure.

I should have clarified in my original post. I have a website hosted on Dreamhost, my website hosting company. I have an Arduino board with an Ethernet shield that will be running all the time. I prefer to host the website with my hosting company since they can handle the bandwidth and have nice visitor statistics that I can track.

I temporarily solved the problem with the following code running on my Arduino, sending data to an iframe on the web page. It works, but not as well as I'd like. It only sends an "I'm online!" status to the website, but there is no way to say "Oops, I'm offline now."

I'll try the meta refresh frame shortly to see if that's any better.

client.print("<img src=\"http://www.mydomain.com/online_status.jpg\" border=\"0\" width=\"200\" height=\"25\" />");

Give the Arduino a RTC, have it sent the date/time to the webpage frame, and then the webpage can show "Last heard from Arduino at... (date/time)"

It only sends an "I'm online!" status to the website, but there is no way to say "Oops, I'm offline now."

That is somewhat like expecting a person to phone you and say that they have just dropped over dead. :slight_smile:

zoomkat:
That is somewhat like expecting a person to phone you and say that they have just dropped over dead. :slight_smile:

Yes, unless if the website was smart enough to know that it wasn't receiving an "I'm alive" update every once in a while and in which case it says "It's offline now." as a default. In other words, if the guy isn't calling you on the phone every 5 minutes, he must have dropped over dead! :wink:

Well, that sounds like server side programming on the web site maintaining the page. You probably need to contact your web service provider to see what they can do for you.

This would be pretty simple with a little PHP. The arudino loads a page (which is a PHP script) that logs what time the hit occurred. Your visitor viewable web page also loads a PHP-based script that checks what the last Arduino hit was and decides to print "online" or "offline."

The simplest way to do this may to just have the web page ping the Arduino each time it is reloaded. If the Arduino answers, well great, have the web page report "Number 5 Alive Stephanie!". if not, dead Arduino. How sophisticated is the user interface on the web side? As someone said, this is not really an Arduino project so much as a web dev project, not that I mind...