Pages: [1]   Go Down
Author Topic: Ethernet Sheild was working, any tips?  (Read 1140 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
Using an RF remote, an arduino, and an ethernet sheild I built a device that would tweet if my garage door was open or closed. Everything worked great and for two days I was getting tweets on the garage door status. I was plugged into a Belkin Router. We just switched to a new ISP this weekend and with the new service came a modem/router combo box. I have done the "ipconfig" to determine the router home page. I went to the router page and it showed the local IP addresses I have available and the ones being used. I chose 192.168.1.100 which was available. It still does not work. Any ideas?
Logged

New Jersey
Offline Offline
Faraday Member
**
Karma: 65
Posts: 3638
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

192.168.1.100 sounds a bit suspicious - it's often the first address the router gives out to devices as they ask for them - you may have a conflict with another device on your lan - try 192.168.1.99 for the Arduino. Before you change it though, can you ping the device by IP? What happens if you try to ping that address when the Arduino is powered down?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The way the code worked with the Ethernet shield in the past was that you set the IP you want the shield to be on in the start up code. I choose 100 because the range available on the modem/router was something like 67 - 200. I could see that numbers 67, 68, 69, and 70 were being used already. So I chose a number that would not interfere with current or additional computers. I have very little knowledge on how the IP stuff works so if I am way off feel free to correct me. How can I ping the shield?
Logged

New Jersey
Offline Offline
Faraday Member
**
Karma: 65
Posts: 3638
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ah, 100 sounds ok then - most of the routers I've had start giving out addresses at 100. To ping the Arduino, open a command window (or terminal if your O/S is UNIX based) and type ping 192.168.1.100

It should show you whether there is connectivity to the Arduino at least
Logged

0
Offline Offline
Tesla Member
***
Karma: 141
Posts: 9470
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Usually it is a good practice to post the code you are using for a second check. Does your new modem/router have an owner's manual? For an arduino client, your router/modem should see it just like a pc with a static IP assigned to it.
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here is the code:
/ Tweeting when the garage door opens and closes using two reed switches
#if defined(ARDUINO) && ARDUINO > 18   // Arduino 0019 or later
#include <SPI.h>
#endif
#include <Ethernet.h>
#include <EthernetDNS.h>
#include <Twitter.h>
#define LED 13  // Define LED pin
#define SWT 7  // Define the input pin for switch 1 Top Switch
#define SWB 8  // Define the input pin for switch 2 Bottom Switch

// Ethernet Shield Settings
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x3F, 0x99 };

// substitute an address on your own network here
byte ip[] = { 192,168,1,100 };

// Your Token to Tweet (get it from http://arduino-tweet.appspot.com/)
Twitter twitter("3xxxxxxxxxxxxxxxxxxx");

const char* msg ="/meh/";   //Placeholder message otherwise compiler will error

int count = 0;   //Random integer to insert into Tweets
int valT = 0;  // Variable used to store the state of the top switch
int valT_old;  // Variable used to store old value and prevent repeat tweets
int valB = 0;  // Variable used to store the state of the bottom switch
int valB_old;  // Variable used to store old value and prevent repeat tweets
int state = 0;

void setup() {
  delay(1000);
  Serial.begin(9600);
  Ethernet.begin(mac, ip);
  pinMode(LED, OUTPUT);
  pinMode(SWT, INPUT);
  pinMode(SWB, INPUT);
  }
  
void loop(){
  valT = digitalRead(SWT);  // Read the top switch
  valB = digitalRead(SWB);  // Read the bottom switch
 
 if ((valT == HIGH) & (valB == LOW)){  // If top switch gets triggered first we know it is going down
       if ((valT == HIGH) & (valT_old == LOW)){  // This prevents retweets if garage door stops on the switch
          state = 0;  // Give the status of the door as closed for LED
          msg = "Garage Door is Closed";  // Message to tweet
          Tweet();  // Run tweeting program
          delay(5000);  // Wait for the door to pass both switches before checking again
        }}
      
 if ((valT == LOW) & (valB == HIGH)){  // If bottom switch gets triggered first we know it is going up
        if ((valB == HIGH) & (valB_old == LOW)){ // This prevents retweets if the garage door stops on the switch
          state = 1;  // Give the status of the door as open for the LED
          msg = "Garage Door is Open";  // Message to tweet
          Tweet();  // Run tweeting program
          delay(5000);  // Wait for the door to pass both switches before checking again
          }}  
 valT_old = valT;
 valB_old = valB;
 if (state == 1){  // Check the state of the garage door
   digitalWrite(LED, HIGH);}  // If the garage is open turn ont he LED
 else {digitalWrite(LED, LOW);}  // Otherwise turn off the LED
 }

 // Tweeting Program
 void Tweet(){
  char S[50];              //Define twitter message as "S"

  /**********
   *  SprintF "stitches" together a string(msg) and a variable(randomVariable) into
   *  another string, "S".
   **********/
  count = count +1;
  sprintf(S, "%s %i",msg, count);  //

  Serial.println(S);
  Serial.println("connecting ...");

  //The rest is lifted from the Twitter post example.
  if (twitter.post(S))
  {int status = twitter.wait();
   if (status == 200)
    {Serial.print("OK. code ");
     Serial.println(status);
    }
    else
    {Serial.print("failed : code ");
     Serial.println(status);
    }
  }
  
  else
  {Serial.println("connection failed.");
  }}
« Last Edit: October 24, 2011, 08:58:55 pm by speemike » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

When I pinged it said four packets sent and four packets recieved.
When I twigger the switch and watch it on the serial port it comes back with "connection failed".
« Last Edit: October 24, 2011, 08:46:28 pm by speemike » Logged

California
Offline Offline
Faraday Member
**
Karma: 88
Posts: 3359
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

When I pinged it said four packets sent and four packets recieved.
When I twigger the switch and watch it on the serial port it comes back with "connection failed".
I'm fairly certain the Ethernet shield doesn't automatically respond to ICMP requests, so any ping responses would be from another device with the same IP address. Did you try a different IP address?
Logged

New River, Arizona
Offline Offline
God Member
*****
Karma: 19
Posts: 928
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The arduino ethernet board that uses the 5100 chip DOES respond to a ping.
Logged

Trying to keep my house under control http://www.desert-home.com/

New River, Arizona
Offline Offline
God Member
*****
Karma: 19
Posts: 928
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I took a look at your code and saw nothing that was an obvious problem.  That makes sense because you only replaced the DSL modem and didn't change the code.  The twitter library you're using only returns true or false so there's no discrimination between a DNS lookup failure or a connection problem.  There are some things you can do to isolate the problem, but you'd have to put some more error checking in the twitter library code.  I suspect you don't want to do that.

However, I suspect that there is a DNS problem (google it) that is related to the new equipment.  Most home routers serve as the DNS host or forwarder and will handle the lookups for you.  This may not be happening with the new equipment.  I suggest you go to the configuration page for the device (whatever it is) and prowl around through the menus looking for something like enable DNS or Domain Name Service.  If you can't find anything, take a look on the web for the user manual, not that little quick start page they usually send you to get you started without telling you anything real about it.  In the user manual you may well find an option to turn this on or something to that effect.

See, a lot of us use the router as our DNS and configure the address 192.168.0.1 as the Domain Name server.  The twitter code doesn't do that, it uses other facilities for this by defaulting to the google dns server at 8,8,8,8.  It looks like that is what was working originally before you made the change of ISP.

Alternately, you can add a line to your code to set the DNS server to your router.  Something like:

byte dnsServerIp[] = { 192, 168, 0, 1 };  // put this somewhere up near the top
EthernetDNS.setDNSServer(dnsServerIp); // and this in setup somewhere

But, if this stuff doesn't work, you'll have to get into the twitter library code and expand on the error checking to isolate to a finer degree what is messing up for you.

good luck and have fun with it.
Logged

Trying to keep my house under control http://www.desert-home.com/

Pages: [1]   Go Up
Jump to: