Go Down

Topic: Client/Server Questions Using Ethernet Shield (Read 547 times) previous topic - next topic

Mavromatis

Aug 03, 2010, 07:46 am Last Edit: Aug 03, 2010, 07:48 am by Mavromatis Reason: 1
What are you guys using as the best Ethernet Library for W5100 based ethernet shields?  

There is Ethernet2, Updated Client (http://code.rancidbacon.com/LearningAboutArduinoEthernet) and a bunch of other fixes posted on this forum.   I'm using v18 so I'm not sure what has been built in vs tweaks I need to still make?

My problem now is that I have a server which works very good.  Problem is that my client only works once.    What I'm trying to accomplish is that I get hit via HTTP get command with some data.

I occasionally need to make an outgoing HTTP request (client) every hour to notify a server I'm still listening.   The problem starts when I create the client and use it once.  It works... after that it always fails.

Code looks something like this:

Code: [Select]

void setup() {
 
 
    // setup the Ehternet library to talk to the Wiznet board
    Ethernet.begin(mac, ip);  
     
    delay(1000);
   
    // subscribe to transport notifictions
    subscribe(false);
   
   
}


void loop(){  // main loop

  server.begin(); // based on forum post
 
  if (isSubscribed){
   unsigned long currentMillis = millis();

     if(currentMillis - previousMillis > interval) {
       previousMillis = currentMillis;
       currentTime += 1;
     }
     
     if (currentTime >= (subscriptionTimeout - 300)){
       currentTime = 0;
       // send a renew subscription message
       subscribe(true);
     }
     
 } // isSubscribed
 
 
  // server code
  Client webclient = server.available();
 
 if (webclient) {
   
   while (webclient.connected()) {
     if (webclient.available()) {
       
       // process incoming web request
                           
     } // end of available
   } // end of while loop
  } // end of webclient

}

void subscribe(boolean renew)
{
 
 Client subClient(subIP, 1400);

 if (subClient.connect()) {
 
   // send something to server...
   
    delay(1);
    Serial.println("sub sent");
    subClient.flush();
    subClient.stop();
     while(subClient.status() != 0) { // ADDED Aug 2 (http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1235991468)
            delay(5);
         }
    Serial.println("disconnecting.");
   
   
   
 } else {
   if (debug) {
     Serial.println("fail");
   }
   
   
    // if we fail, resubscribe!
    isSubscribed = false;
    delay(1000);
    subscribe(false);
    delay(1000);
   
 }
 

 
}



What is happening is that the first subscribe works perfect... every one after fails... any idea why?

Go Up