Thanks for the help!
I have been making some good progress but just ran into a snag. Here is my setup:
-An arduino
-an official ethernet shield
- three LEDs (Red, Green, White)
The Arduino checks if it can connect to google to verify the internet connection to my house. While checking the connection the white LED is on.
If it confirms that it has an internet connection it twitters "the house is online" then turns the green LED on.
If it cannot connect to the internet it turns the red LED on.
It checks the internet connection every 2.5 minutes.
My ultimate goal is to automatically reset the internet modem if it verifies there is no connection to the internet. I have had many issues with needing to reboot the router every 2-3 days.
The code below was working wonderfully for the last 3 days but as of today it cannot connect to the internet. I even took the unit over to my neighbors and tried it on his internet connection with zero luck.
I have also tried commenting out the twitter functionality to see if it was causing the issue. No luck.
Any ideas? Thanks!
#include <Ethernet.h>
#include <Twitter.h>
// these are the LED definitions
int greenPin = 8; // Green LED connected to digital pin 8. indicates intenet is working
int redPin = 9; // Red LED connected to digital pin 9. indicates internet is not working
int whitePin = 7; // white LED connected to digital pin 7. indicates arduino is testing the internet connection
unsigned long time; // this defines the time variable
byte mac[] = { 0xAE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 0, 32 };
// byte gateway[] = { 192, 168, 0, 1 };
// byte subnet[] = { 255, 255, 0, 0 };
byte server[] = { 64, 233, 187, 99 }; // Google
// byte server[] = { 69, 147, 76, 15 }; // Yahoo
Client client(server, 80);
// this is the twitter definition
Twitter twitter("twitterusername:twitterpassword");
char msg[] = "This is the 13th Test. I am the Arduino DSL internet Watchdog!!"; // not currently using this, see below
void setup()
{
pinMode(greenPin, OUTPUT); // sets the digital pin as output
pinMode(redPin, OUTPUT); // sets the digital pin as output
pinMode(whitePin, OUTPUT); // sets the digital pin as output
Ethernet.begin(mac, ip);
Serial.begin(9600);
delay(1000);
}
void loop()
{
digitalWrite(whitePin, HIGH); // Sets the white LED on
Serial.println();
Serial.println("Testing your Internet connection...");
if (client.connect()) {
Serial.println("You are connected to the Internet");
Serial.print("Time: ");
time = millis();
//prints time since program started
Serial.println(time);
// wait a second so as not to send massive amounts of data
delay(1000);
Serial.println("Connecting to Twitter...");
if (twitter.post("The house is online!")) {
int status = twitter.wait();
if (status == 200) {
Serial.println("Tweet Successful!!");
digitalWrite(redPin, LOW); // sets the red LED off
digitalWrite(greenPin, HIGH); // sets the Green LED on
client.stop();
digitalWrite(whitePin, LOW); // sets the white LED off
delay(150000); // delays restart of program after success for 2.5 minutes
}
}
} else {
Serial.println("You are not connected to the Internet!");
digitalWrite(greenPin, LOW); // sets the Green LED off
digitalWrite(redPin, HIGH); // sets the red LED on
delay(500); // waits for half a second
client.stop();
digitalWrite(whitePin, LOW); // sets the white led off
delay(150000); // delays restart of the program after failure for 2.5 minutes
}
}