Wireless outlet control via web interface


I am currently working for a college arduino based project. I am making, as the subject states, a system that controls some outlets ( via radio transmitter ). The controlling is happening in a web interface that i create in-line in the arduino code ( so NOT imported from an SD card ). Currently my system works but it only has the basic on/off functions. I'm trying to add a timer to that, so i can activate the outlets in or for x time. For that i implemented a NTP clock on my web server in arduino, and here is where i have a problem.

Currently i am printing the hour inside my html code using client.print(hour()) etc. As it stands the time only refreshes when i refresh the webpage. I am asking for help for a way that the time runs by itself without the page being refreshed.

Thanks and have a nice day, Tudor.

If you are using Wi-Fi example code, then you need to add a refresh command
Try this:

client.println("HTTP/1.1 200 OK");
                client.println("Connection: close");  // the connection will be closed after completion of the response
                client.println("Refresh: 5");  // refresh the page automatically every 5 sec

If you had posted your code, I would have put this in the place it needs to go, and more people would be able to help you.

Thanks for the quick response.

I’m using Ethernet direct cable and i saw what you posted in the example. sadly that’s not a viable solution for me as i need the time to refresh every second ( for the timer i want to make ). This is the part in my code that handles the web server, and i need the time to be incremented, without refreshing the web page, if that’s even possible.

Thanks again for the help!

EthernetClient client = server.available();  // try to get client

    if (client) {  // got client?
        boolean currentLineIsBlank = true;
        counter = 0;
        while (client.connected()) {  
            if (client.available()) {   // client data available to read
                char c = client.read(); // read 1 byte (character) from client
                // last line of client request is blank and ends with \n
                // respond to client only after last line received
                 if ((c!='\n') && (c!='\r')){
         if (inString.length() < maxLength) {
//         Serial.print(c);
//        Serial.print(inString);
                if (c == '\n' && currentLineIsBlank) {
                    // send a standard http response header
                    client.println("HTTP/1.1 200 OK");
                    client.println("Content-Type: text/html");
                    client.println("Connection: close");
                    client.println(F("<!DOCTYPE html>"));
    Here is my HTML code, too big to fit. Cut everything to the part that handles the time:
client.println("Este ora:");
                    HTTP_req = "";    // finished with request, empty string
                    // send web page

                // every line of text received from the client ends with \r\n
                if (c == '\n') {
                    // last character on line of received text
                    // starting new line with next character read
                    currentLineIsBlank = true;
                else if (c != '\r') {
                    // a text character was received from client
                    currentLineIsBlank = false;
            } // end if (client.available())
        } // end while (client.connected())
        if (c == '\n') {//17
          currentLineIsBlank = true;//18


I'm actually interested in the same thing you are trying to do. When It is refreshing, if you click on a button it messes up the display link (shows the script rather than the page) until it refreshes again. If you have a rather large sketch, the refresh each time can take up to 3 seconds. Rather annoying and inconvenient. The count down should be constant, there is no reason it shouldn't be.

I don't know how to address this, but I will say that two people are trying hard to figure this out. I will continue to monitor this post, if you find a solution please post it! I will do the same.

Yes, not to mention that even if the refresh would happen every 1 second, it stills is quite inconvenient, say you want to open or close the outlets after an x amout of time, the page refreshing itself is clearly not a viable solution. I was hoping there is a way to increment the data internally by the webpage, without refreshing it as a whole. Maybe someone has a clue about how to do it, hopefully.

Well I mean you could hook up bluetooth so that it transfers to your phone directly, which would not require the refresh (I think). But personally I'd rather you continue on your current path because I'm interested in this as well.

I have found a solution ( not sure if it is the most optimal ) using javascript. Let me know how it works for you, please, i have not tried it yet! Here's the link for refference :


The below tutorial has some embedded actions for web pages. Not sure the reason for your time display, but you could put the meta refresh time page in a frame in the main web page.


Have you incorporated any security in the system so your friends/enemies cannot sabotage your project?