Go Down

Topic: Trouble with Ethernet Shield as a client (Read 346 times) previous topic - next topic

Chorob

Hello,

I had this sketch running successfully for 3 days then it stopped working.  All sketches I try now that are clients using the ethernet shield do not work.  I can send a twitter using the basic twitter example though.

I am using Arduino 17 to build these sketches.  Am I running into a memory issue?  Thanks for the help.  I am a newb.

#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[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 0, 35 };
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!!";


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, gateway, subnet);
 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();
   // Serial.println(time);  //prints time since program started
   delay(1000); // wait a second so as not to send massive amounts of data
   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
 }    
}


Digger450

Are you sure about that ip?

Code: [Select]
byte server[] = { 64, 233, 187, 99 }; // Google

That doesn't ping for me.

Also, when posting code if you use the # icon it makes it much easier to read  ;)

Chorob

Thank you!  I can't believe I overlooked that.  It is the IP address provided in the example code and I took it as gospel.

Thanks!!!

Go Up