Once in a while we get power shortage at home.
When i turn the power on, it takes some time for the internet to recover, by that time the arduino stops searching for connection, and than i need to restart it manualy, what command can i give it to restart it automaticly, i read about watchdog but i didn't understand it very well...please help
Nobody but a psychic could possibly answer that without details of your software and hardware.
shaniyakov:
Once in a while we get power shortage at home.
When i turn the power on, it takes some time for the internet to recover, by that time the arduino stops searching for connection, and than i need to restart it manualy, what command can i give it to restart it automaticly, i read about watchdog but i didn't understand it very well...please help
So I assume that your Arduino loses power too...
So then you have to wait until your lan and its connection to the internet is restored.
There are methods to check to see if you have connection, and you can wait for that to happen on power-up.
shaniyakov:
by that time the arduino stops searching for connection
It just a random suggestion as you have chosen not to provide any details of your setup, but it might be an idea to increase the time the arduino searches for a connection maybe ?
Sorry, I thought it obvious.
BulldogLowell, you right,thats what i meant.
I have an arduino uno with ethernet shiled, i am runing a server on it, so when the internet turn off the arduino turn off as well and the same when i power up.
How do you implement the solution you suggested?
shaniyakov:
How do you implement the solution you suggested?
No idea at all, it was just a suggestion.
You presumably have the code\program that runs the Arduino in question ?
/*
Created by Rui Santos
Visit: http://randomnerdtutorials.com for more arduino projects
Arduino with Ethernet Shield
*/
#include <SPI.h>
#include <Ethernet.h>
int led = 9;
int count = 0;
boolean BoilerON = false;
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 150 }; // ip in lan
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(6882); //server port Â
String readString;
void setup(){
pinMode(9, OUTPUT); //pin selected to control
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();
Serial.begin(9600);
delay(1000);
Serial.println("server LED test 1.0"); // so I can keep track of what is loaded
digitalWrite(led, LOW);
}
void loop(){
       Â
// Create a client connection
EthernetClient client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
//read char by char HTTP request
if (readString.length() < 100) {
//store characters to string
readString += c;
//Serial.print(c);
}
//if HTTP request has ended
if (c == '\n') {
///////////////
Serial.println(readString); //print to serial monitor for debuging
     client.println("HTTP/1.1 200 OK"); //send new page
     client.println("Content-Type: text/html");
     client.println(); Â
     client.println("<HTML>");
     client.println("<HEAD>");
     client.println("<meta name='apple-mobile-web-app-capable' content='yes' />");
     client.println("<meta name='apple-mobile-web-app-status-bar-style' content='black-translucent' />");
     client.println("<link rel='stylesheet' type='text/css' href='http://randomnerdtutorials.com/ethernetcss.css' />");
     client.println("<TITLE>Yakov's Boiler</TITLE>");
     client.println("</HEAD>");
     client.println("<BODY>");
     client.println("<H1>Boiler</H1>");
       if (BoilerON==true)
           {
        client.println("<td align='center'><font color='green' size='5'>status: ON");
       client.println("<hr />");
       client.println("
");Â
       client.println("<a href=\"/?button1off\"\">Turn off</a>
");
       }
    Â
       else
     {
       client.println("<td align='center'><font color='black' size='5'>status: OFF");
       client.println("<hr />");
       client.println("
");Â
       client.println("<a href=\"/?button1on\"\">Turn On</a>
");
       }
     client.println("
");Â Â
     client.println("
");
     client.println("<p>Shani Yakov</p>");Â
     client.println("
");
     client.println("</BODY>");
     client.println("</HTML>");
 Â
     delay(1);
     //stopping client
     client.stop();
     //controls the Arduino if you press the buttons
     if (readString.indexOf("?button1on") >0)
       {
         digitalWrite(led, HIGH);
         BoilerON = true;
       }
      Â
     if (readString.indexOf("?button1off") >0)
     {
       digitalWrite(led, LOW);
       BoilerON = false;
     }
    Â
      Â
      //clearing string for next read
      readString="";Â
    Â
    }
   }
  }
}
}
To check if you have internet connectivity, one method is to issue periodically an http GET command to a server on the internet (find one that does not redirect to https://) and see if you get a result back. Google for Arduino web client. In the case of failure, issue a command to restart your Arduino. Google for reset Arduino with code.
Where should i put the get command in my code?
In the setup or the loop section?
You would pus such code in the loop() because any communication issues (router restart etc.) will most likely happen when your sketch is running in the loop().
For developing and testing, it would be more convenient initially to have it in the setup(). Write a separate sketch for this.