Pages: 1 [2] 3 4 ... 6   Go Down
Author Topic: [SOLVED] Email Orb not working  (Read 3608 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 65
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

When you run your Orb code do you still get this message?
Quote
Failed to initialize ethernet!
And you don't get that message with any other ethernet dhcp example code like DhcpAddressPrinter?


When I run my orb code I now get this message:

"connecting...
connected
lost connection before data was read
inboxCount:0"

And no, DHCPAdressPrinter works fine. I now know that my IP Address is 192.168.1.1 smiley
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 147
Posts: 6040
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Show me what you replaced this malformed request with.
Code:
     client.print("GET ");
// missing the page you want here
// and stick to HTTP/1.0 below for now
      client.println(" HTTP/2.0");
      client.print("Host: ");
// missing your domain (server_name) here
      client.println();

Here is an example from my client code.
http://playground.arduino.cc/Code/WebClient
Code:
  if(client.connect(ipBuf,thisPort))
  {
    Serial.println(F("connected"));

    sprintf(outBuf,"GET %s HTTP/1.1",page);
    client.println(outBuf);
    sprintf(outBuf,"Host: %s",serverName);
    client.println(outBuf);
    client.println(F("Connection: close\r\n"));
  }
  else
  {
    Serial.println(F("failed"));
    return 0;
  }
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 616
Posts: 49433
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

My output is in setup:
Code:
pinMode(LED_PIN, OUTPUT);

Does LED_PIN have a value of 10? No, it does not.

Regardless of whether you think you need to, or not, you MUST set pin 10 to OUTPUT. The default is INPUT for all pins. The example does set pin 10 to OUTPUT, and it works. Your code does not, and it doesn't work. See a pattern?
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 65
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

My output is in setup:
Code:
pinMode(LED_PIN, OUTPUT);

Does LED_PIN have a value of 10? No, it does not.

Regardless of whether you think you need to, or not, you MUST set pin 10 to OUTPUT. The default is INPUT for all pins. The example does set pin 10 to OUTPUT, and it works. Your code does not, and it doesn't work. See a pattern?

Do you want me to set all of my pins to output or just 10 then???
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 65
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

My output is in setup:
Code:
pinMode(LED_PIN, OUTPUT);

Does LED_PIN have a value of 10? No, it does not.

Regardless of whether you think you need to, or not, you MUST set pin 10 to OUTPUT. The default is INPUT for all pins. The example does set pin 10 to OUTPUT, and it works. Your code does not, and it doesn't work. See a pattern?
I tried setting pin 10 to output and it still says:
"connecting...
connected
lost connection before data was read
inboxCount:0"
I'M STUCK UGHHH!!!!!
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 65
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Show me what you replaced this malformed request with.
Code:
     client.print("GET ");
// missing the page you want here
// and stick to HTTP/1.0 below for now
      client.println(" HTTP/2.0");
      client.print("Host: ");
// missing your domain (server_name) here
      client.println();

Here is an example from my client code.
http://playground.arduino.cc/Code/WebClient
Code:
  if(client.connect(ipBuf,thisPort))
  {
    Serial.println(F("connected"));

    sprintf(outBuf,"GET %s HTTP/1.1",page);
    client.println(outBuf);
    sprintf(outBuf,"Host: %s",serverName);
    client.println(outBuf);
    client.println(F("Connection: close\r\n"));
  }
  else
  {
    Serial.println(F("failed"));
    return 0;
  }

This is what I replaced it with:
Code:
      client.print("GET phpmaster.comule.com");
      client.print("SCRIPT_PATH");
      client.println(" HTTP/1.0");
      client.print("Host: server48.000webhost.com");
      client.print("SERVER NAME");
      client.println("phpmaster.comule.com");
Now it says
"connecting...
connected"
and then about 10 seconds later it says:
"lost connection before data was read
inboxCount:0"...
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 65
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Anyone else?
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 147
Posts: 6040
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You are still using a malformed request. This should be good for your site.
Code:
      client.println("GET /checkGmail.php HTTP/1.1");
      client.println("Host: phpmaster.comule.com");
      client.println("Connection: close\r\n");
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 65
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You are still using a malformed request. This should be good for your site.
Code:
      client.println("GET /checkGmail.php HTTP/1.1");
      client.println("Host: phpmaster.comule.com");
      client.println("Connection: close\r\n");

Same thing:
Quote
connecting...
connection failed
inboxCount:0
connecting...
connected
lost connection before data was read
inboxCount:0

Here's my current sketch:
Code:
/*
  The "Email Orb": This is an internet-connected device
  that shows you how many new emails are waiting for
  you in your gmail account's inbox by pulsing an attached
  LED: one pulse per message.  If there are more than 10
  messages, the LED will remain on.
 
  This project requires an Ethernet Shield and an LED (with
  an appropriate resistor) connected to pin 9. It also requires
  a "proxy" php script to handle the https request to your
  gmail account and xml parsing.
 
  IMPORTANT: Read the comments below, as you will need
  to edit this file before compiling and uploading!
 */

#include <SPI.h>
#include <Ethernet.h>

// set TEST_MODE = true to pulse LED 3x without
// making network connection to remote server.
// Handy for making sure your electronics work!
boolean TEST_MODE = false;

// BEFORE UPLOADING:
// You will need to set some of the configuration options below:

// Set your ethernet sheild's hardware address:
// Uncomment the line below and replace each "??" with the
// values from the sticker on your Ethernet Shield box.

byte mac[] = {  0x00, 0x11, 0x22, 0x33, 0x44, 0x55 };

// Uncomment the line below and replace the current
// value with IP address of the server you uploaded
// your PHP script to.  Note that the octets
// are sperated by commas, not periods.

IPAddress server(31,170,160,112);
IPAddress ip(31,170,160,112);

// Uncomment the line below and replace with the
// host name of your php server:

char server_name[] = "phpmaster.comule.com";

// Uncomment the line below and replace with the
// path to your php script on the server:

char script_path[] = "/checkGmail.php";

// Some other config options (these defaults should be OK):
// interval between checking email (in millis):
unsigned long GET_INTERVAL = 1000 * 30;
// Affects rate of pulse:
int RAMP_DELAY = 3;
// LED output pin:
int LED_PIN = 9;
// end configuration options

// global variables:
long lastGet = 0 - GET_INTERVAL;
int inboxCount = 0;

EthernetClient client;

void setup() {
  Serial.begin(9600);
  pinMode(LED_PIN, OUTPUT);
  pinMode(10, OUTPUT);
    /*
      Leave the Ethernet.begin(mac) statement below as-is if your network
      uses DHCP to assign IP addresses.  To assign a static IP address,
      use one of the following forms:
     
        Ethernet.begin(mac, ip);
        Ethernet.begin(mac, ip, dns);
        Ethernet.begin(mac, ip, dns, gateway);
        Ethernet.begin(mac, ip, dns, gateway, subnet);
       
     For more info:
       http://arduino.cc/en/Reference/EthernetBegin
    */
    Ethernet.begin(mac, ip);
    if (Ethernet.begin(mac) == 0) {
      Serial.println("Failed to initialize ethernet!");
      // Failed, so do nothing, forever:
      Ethernet.begin(mac, ip);
      for(;;)
        ;
    }
    // Allow Shield time to initialize:
    delay(1000);
}

void loop()
{
  // Main loop: check for messages every GET_INTERVAL millis:
  unsigned long now = millis();
  if ( ( now - lastGet ) > GET_INTERVAL ) {
    lastGet = now;
    int result = getInboxCount();   
    if ( result != -1 ) {
      inboxCount = result;
    }
    Serial.print("inboxCount:");
    Serial.println(inboxCount);     
  }
  else {
    pulseInboxCount();
  }
}

int getInboxCount() {
  if (TEST_MODE) {
    Serial.println("TEST MODE: returning dummy inbox count");
    return 3;
  } else {
    Serial.println("connecting...");
    // if you get a connection, report back via serial:
    if (client.connect(server, 80)) {
      Serial.println("connected");
      // Make an HTTP request:
      client.print("GET /checkGmail.php HTTP/1.1");
      client.print("Host: phpmaster.comule.com");
      client.println("Connection: close\r\n");
     
      boolean weAreReadingTheNumber = false;
      // let's arbitrarily cap the number at 2 digits,
      // and initialize it with spaces:
      char inboxCountStr[] = {"  "};
      byte strPos = 0;
      int inboxCountInt;
      while(client.connected()) {
        if (client.available()) {
          char c = client.read();
          //Serial.print(c);   
          if (weAreReadingTheNumber) {
            if ( c == ']') {
              inboxCountInt = atoi(inboxCountStr);
              client.stop();
              return(inboxCountInt);
            }
            else if (strPos > 1) {
              Serial.println("WARNING: Exceeding allowed number of digits");
              client.stop();
              return 99; // use the max of 99 if more than 2 digits
            }
            else {
              inboxCountStr[strPos++] = c;
            }
          }
          else {
            if ( c == '[' ) {
              weAreReadingTheNumber = true;
            }     
          }
        }
      }
      Serial.println("lost connection before data was read");
      client.stop();
      return -1;
    }
    else {
      // if you didn't get a connection to the server:
      Serial.println("connection failed");
      return -1;
    }
  }
}

void pulseInboxCount() {
  //Serial.print("pulse count:");
  //Serial.println(inboxCount);
  if (inboxCount < 10) {
    analogWrite(LED_PIN,0);
    for ( int i = 0 ; i < inboxCount ; i ++ ) {
      singlePulse();
    }
    // ensure pin is off between sets of pulses:
    analogWrite(LED_PIN,0);
  }
  else { // if 10 ore greater, steady on:
    analogWrite(LED_PIN,255);
  }
  delay(1000); // delay between sets of pulses
}

void singlePulse() {
  int v;
  // After some experimentaiton, I adjusted starting/ending
  // values of loops to create smoother sets of pulses.
  // Ramp brightness up:
  for ( v = 50 ; v < 256 ; v++ ) { 
    analogWrite(LED_PIN,brightness(v));
    delay(RAMP_DELAY);
  }
  // Ramp brightness down:
  for (v = 255 ; v > 50 ; v-- ) {
    analogWrite(LED_PIN,(int)brightness(v));
    delay(RAMP_DELAY);
  }
}

/*
 Brightness function: this is used to translate a linear range of values
 to something resembling an exponential curve.  This is useful because
 humans perceive phenomena such as brightness logarthmically, not linearly.
 The result is an LED that appears to pulse much more evenly.
 */
int brightness(int input) {
  //return (int)(pow(input,4)*255.0);
  return (int)(pow((float)input / 255.0, 4) * 255.0);
}
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 147
Posts: 6040
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Use only one Ethernet begin(). I recommend using the dhcp version, since it worked before.
Code:
   // comment out this
    // Ethernet.begin(mac, ip);
    // leave this
    if (Ethernet.begin(mac) == 0) {
      Serial.println("Failed to initialize ethernet!");
      // Failed, so do nothing, forever:
      Ethernet.begin(mac, ip);
      for(;;)
        ;
    }

If you are using a static ip, this will cause that fail:
Code:
IPAddress ip(31,170,160,112);
Your localnet is 192.168.1.x.

edit: And if the dhcp server assigned you 192.168.1.1, then that is not the dns server or gateway ip. If you use a static assignment, you must specify all the other settings. Otherwise, 192.168.1.1 will be used for the dns server and the gateway, which it isn't.
« Last Edit: September 06, 2013, 03:08:40 pm by SurferTim » Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 65
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Use only one Ethernet begin(). I recommend using the dhcp version, since it worked before.
Code:
   // comment out this
    // Ethernet.begin(mac, ip);
    // leave this
    if (Ethernet.begin(mac) == 0) {
      Serial.println("Failed to initialize ethernet!");
      // Failed, so do nothing, forever:
      Ethernet.begin(mac, ip);
      for(;;)
        ;
    }

If you are using a static ip, this will cause that fail:
Code:
IPAddress ip(31,170,160,112);
Your localnet is 192.168.1.x.

edit: And if the dhcp server assigned you 192.168.1.1, then that is not the dns server or gateway ip. If you use a static assignment, you must specify all the other settings. Otherwise, 192.168.1.1 will be used for the dns server and the gateway, which it isn't.


Still nothing...
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 147
Posts: 6040
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I used the GET sketch code here
http://playground.arduino.cc/Code/WebClient

I used this as the server stuff
Code:
IPAddress server(31,170,162,43); // your ip

//Change to your domain name for virtual servers
char serverName[] = "phpmaster.comule.com";

The network settings are mine in the sketch. Change those to your network settings.
Then compile and upload. This is the result.
Quote
Starting ethernet...
192.168.2.2
Ready
connecting...connected
HTTP/1.1 200 OK
Date: Tue, 10 Sep 2013 18:22:07 GMT
Server: Apache
X-Powered-By: PHP/5.2.17
Content-Length: 159
Connection: close
Content-Type: text/html

[75]

<!-- Hosting24 Analytics Code -->
<script type="text/javascript" src="http://stats.hosting24.com/count.php"></script>
<!-- End Of Analytics Code -->

disconnecting.
Pass 1
It is downloading that page every 30 seconds right now.
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 147
Posts: 6040
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here it is. You must set the ip, gateway and subnet to your network settings.
Code:
/*
   Web client sketch for IDE v1.0.1 and w5100/w5200
   Uses GET method.
   Posted October 2012 by SurferTim
   Last modified August 23, 2013
*/

#include <SPI.h>
#include <Ethernet.h>

// this must be unique
byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

// change to your network settings
IPAddress ip(192,168,2,2);
IPAddress gateway(192, 168, 2, 1);
IPAddress subnet(255, 255, 255, 0);

// change to your server
IPAddress server(31,170,162,43); // your ip

//Change to your domain name for virtual servers
char serverName[] = "phpmaster.comule.com";

// If no domain name, use the ip address above
// char serverName[] = "74.125.227.16";

// change to your server's port
int serverPort = 80;

EthernetClient client;
int totalCount = 0;
int loopCount = 0;
char pageAdd[64];

void setup() {
  Serial.begin(9600);

  // disable SD SPI
  pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);

  // Start ethernet
  Serial.println(F("Starting ethernet..."));
  Ethernet.begin(mac, ip, gateway, gateway, subnet);

  // If using dhcp, comment out the line above
  // and uncomment the next 2 lines

  // if(!Ethernet.begin(mac)) Serial.println(F("failed"));
  // else Serial.println(F("ok"));
  digitalWrite(10,HIGH);

  Serial.println(Ethernet.localIP());

  delay(2000);
  Serial.println(F("Ready"));
}

void loop()
{
  if(loopCount < 30)
  {
    // if loopCount is less than 30, just delay a second
    delay(1000);
  }
  else
  {
    // every thirty seconds this runs
    loopCount = 0;

    // Modify next line to load different page
    // or pass values to server
    sprintf(pageAdd,"/",totalCount);

    // sprintf(pageAdd,"/arduino.php?test=%u",totalCount);

    if(!getPage(server,serverPort,pageAdd)) Serial.print(F("Fail "));
    else Serial.print(F("Pass "));
    totalCount++;
    Serial.println(totalCount,DEC);
  }    

  loopCount++;
}

byte getPage(IPAddress ipBuf,int thisPort, char *page)
{
  int inChar;
  char outBuf[128];

  Serial.print(F("connecting..."));

  if(client.connect(ipBuf,thisPort))
  {
    Serial.println(F("connected"));

    sprintf(outBuf,"GET %s HTTP/1.1",page);
    client.println(outBuf);
    sprintf(outBuf,"Host: %s",serverName);
    client.println(outBuf);
    client.println(F("Connection: close\r\n"));
  }
  else
  {
    Serial.println(F("failed"));
    return 0;
  }

  // connectLoop controls the hardware fail timeout
  int connectLoop = 0;

  while(client.connected())
  {
    while(client.available())
    {
      inChar = client.read();
      Serial.write(inChar);
      // set connectLoop to zero if a packet arrives
      connectLoop = 0;
    }

    connectLoop++;

    // if more than 10000 milliseconds since the last packet
    if(connectLoop > 10000)
    {
      // then close the connection from this end.
      Serial.println();
      Serial.println(F("Timeout"));
      client.stop();
    }
    // this is a delay for the connectLoop timing
    delay(1);
  }

  Serial.println();

  Serial.println(F("disconnecting."));
  // close client end
  client.stop();

  return 1;
}
It takes 30 seconds to start downloading the page. That gives you time to open the serial monitor without starting a download.
« Last Edit: September 10, 2013, 02:46:44 pm by SurferTim » Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 65
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here it is. You must set the ip, gateway and subnet to your network settings.
Code:
/*
   Web client sketch for IDE v1.0.1 and w5100/w5200
   Uses GET method.
   Posted October 2012 by SurferTim
   Last modified August 23, 2013
*/

#include <SPI.h>
#include <Ethernet.h>

// this must be unique
byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

// change to your network settings
IPAddress ip(192,168,2,2);
IPAddress gateway(192, 168, 2, 1);
IPAddress subnet(255, 255, 255, 0);

// change to your server
IPAddress server(31,170,162,43); // your ip

//Change to your domain name for virtual servers
char serverName[] = "phpmaster.comule.com";

// If no domain name, use the ip address above
// char serverName[] = "74.125.227.16";

// change to your server's port
int serverPort = 80;

EthernetClient client;
int totalCount = 0;
int loopCount = 0;
char pageAdd[64];

void setup() {
  Serial.begin(9600);

  // disable SD SPI
  pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);

  // Start ethernet
  Serial.println(F("Starting ethernet..."));
  Ethernet.begin(mac, ip, gateway, gateway, subnet);

  // If using dhcp, comment out the line above
  // and uncomment the next 2 lines

  // if(!Ethernet.begin(mac)) Serial.println(F("failed"));
  // else Serial.println(F("ok"));
  digitalWrite(10,HIGH);

  Serial.println(Ethernet.localIP());

  delay(2000);
  Serial.println(F("Ready"));
}

void loop()
{
  if(loopCount < 30)
  {
    // if loopCount is less than 30, just delay a second
    delay(1000);
  }
  else
  {
    // every thirty seconds this runs
    loopCount = 0;

    // Modify next line to load different page
    // or pass values to server
    sprintf(pageAdd,"/",totalCount);

    // sprintf(pageAdd,"/arduino.php?test=%u",totalCount);

    if(!getPage(server,serverPort,pageAdd)) Serial.print(F("Fail "));
    else Serial.print(F("Pass "));
    totalCount++;
    Serial.println(totalCount,DEC);
  }    

  loopCount++;
}

byte getPage(IPAddress ipBuf,int thisPort, char *page)
{
  int inChar;
  char outBuf[128];

  Serial.print(F("connecting..."));

  if(client.connect(ipBuf,thisPort))
  {
    Serial.println(F("connected"));

    sprintf(outBuf,"GET %s HTTP/1.1",page);
    client.println(outBuf);
    sprintf(outBuf,"Host: %s",serverName);
    client.println(outBuf);
    client.println(F("Connection: close\r\n"));
  }
  else
  {
    Serial.println(F("failed"));
    return 0;
  }

  // connectLoop controls the hardware fail timeout
  int connectLoop = 0;

  while(client.connected())
  {
    while(client.available())
    {
      inChar = client.read();
      Serial.write(inChar);
      // set connectLoop to zero if a packet arrives
      connectLoop = 0;
    }

    connectLoop++;

    // if more than 10000 milliseconds since the last packet
    if(connectLoop > 10000)
    {
      // then close the connection from this end.
      Serial.println();
      Serial.println(F("Timeout"));
      client.stop();
    }
    // this is a delay for the connectLoop timing
    delay(1);
  }

  Serial.println();

  Serial.println(F("disconnecting."));
  // close client end
  client.stop();

  return 1;
}
It takes 30 seconds to start downloading the page. That gives you time to open the serial monitor without starting a download.

Ok, so sorry for my last post for you to upload this code to the thread, I figured out what you meant. Here is my code of yours that I modified
Code:
/*
   Web client sketch for IDE v1.0.1 and w5100/w5200
   Uses GET method.
   Posted October 2012 by SurferTim
   Last modified August 23, 2013
*/

#include <SPI.h>
#include <Ethernet.h>

// this must be unique
byte mac[] = {  0xBC, 0x18, 0x54, 0x67, 0x2B, 0x7E };

// change to your network settings
IPAddress ip(192,168,1,1);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);

// change to your server
IPAddress server(31,170,160,112); // Google

//Change to your domain name for virtual servers
char serverName[] = "phpmaster.comule.com";
// If no domain name, use the ip address above
// char serverName[] = "74.125.227.16";

// change to your server's port
int serverPort = 48;

EthernetClient client;
int totalCount = 0;
int loopCount = 0;
char pageAdd[64];

void setup() {
  Serial.begin(9600);

  // disable SD SPI
  pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);

  // Start ethernet
  Serial.println(F("Starting ethernet..."));
  //Ethernet.begin(mac, ip, gateway, gateway, subnet);

  // If using dhcp, comment out the line above
  // and uncomment the next 2 lines

if(!Ethernet.begin(mac)) Serial.println(F("failed"));
  else Serial.println(F("ok"));
  digitalWrite(10,HIGH);

  Serial.println(Ethernet.localIP());

  delay(2000);
  Serial.println(F("Ready"));
}

void loop()
{
  if(loopCount < 30)
  {
    // if loopCount is less than 30, just delay a second
    delay(1000);
  }
  else
  {
    // every thirty seconds this runs
    loopCount = 0;

    // Modify next line to load different page
    // or pass values to server
    sprintf(pageAdd,"/",totalCount);

    // sprintf(pageAdd,"/arduino.php?test=%u",totalCount);

    if(!getPage(server,serverPort,pageAdd)) Serial.print(F("Fail "));
    else Serial.print(F("Pass "));
    totalCount++;
    Serial.println(totalCount,DEC);
  }   

  loopCount++;
}

byte getPage(IPAddress ipBuf,int thisPort, char *page)
{
  int inChar;
  char outBuf[128];

  Serial.print(F("connecting..."));

  if(client.connect(ipBuf,thisPort))
  {
    Serial.println(F("connected"));

    sprintf(outBuf,"GET %s HTTP/1.1",page);
    client.println(outBuf);
    sprintf(outBuf,"Host: %s",serverName);
    client.println(outBuf);
    client.println(F("Connection: close\r\n"));
  }
  else
  {
    Serial.println(F("failed"));
    return 0;
  }

  // connectLoop controls the hardware fail timeout
  int connectLoop = 0;

  while(client.connected())
  {
    while(client.available())
    {
      inChar = client.read();
      Serial.write(inChar);
      // set connectLoop to zero if a packet arrives
      connectLoop = 0;
    }

    connectLoop++;

    // if more than 10000 milliseconds since the last packet
    if(connectLoop > 10000)
    {
      // then close the connection from this end.
      Serial.println();
      Serial.println(F("Timeout"));
      client.stop();
    }
    // this is a delay for the connectLoop timing
    delay(1);
  }

  Serial.println();

  Serial.println(F("disconnecting."));
  // close client end
  client.stop();

  return 1;
}
This is the message from the serial monitor I have been getting when I run the code:
Quote
Starting ethernet...
ok
192.168.1.128
Ready
Connecting...Failed
Fail 1
Yes, I did modify the settings to my network.
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 147
Posts: 6040
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

These are not your correct network settings!
Code:
IPAddress ip(192,168,1,1);
IPAddress gateway(192, 168, 1, 1);
The ip and the gateway cannot be the same ip in this case. You should look in your router to get the settings. If you have challenges with this, maybe you should find an easier project and take a course on ip networks.
Logged

Pages: 1 [2] 3 4 ... 6   Go Up
Jump to: