Pages: [1]   Go Down
Author Topic: Get request working in void setup but not in void loop  (Read 586 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I can't understand why the get request works inside the void setup, but not working inside void loop. The code is exactly the same and I have been trying different stuff but nothing works.

Any ideas?

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

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = {  0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
char serverName[] = "www.arpho.mobi";

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;

void setup() {
  // start the serial library:
  Serial.begin(9600);
  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    while(true);
  }
  // give the Ethernet shield a second to initialize:
  delay(1000);
  Serial.println("connecting...");

  // if you get a connection, report back via serial:
 
  if (client.connect(serverName, 80)) {
    Serial.println("connected void setup");
    // Make a HTTP request:
    client.println("GET /app/arduino.php?sensor1=1 HTTP/1.0");
     client.println("HOST: www.arpho.mobi");
    client.println();
  }
  else {
    // kf you didn't get a connection to the server:
    Serial.println("connection failed");
  }
}

void loop()
{
  // if there are incoming bytes available
  // from the server, read them and print them:
if (client.connect(serverName, 80)) {
    Serial.println("connected void setup");
    // Make a HTTP request:
    client.println("GET /app/arduino.php?sensor1=1 HTTP/1.0");
     client.println("HOST: www.arpho.mobi");
    client.println();
}
   else {
    // kf you didn't get a connection to the server:
    Serial.println("nothing");
    delay(00);
  }
 

  }
Logged

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

You are not getting the response from the server, and you are not closing the connection.

Search the forum for client ethernet code by zoomkat. His stuff usually works good.

Logged

Pages: [1]   Go Up
Jump to: