Pages: [1]   Go Down
Author Topic: ethernet shield problem  (Read 410 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all
i have a problem with the Ethernet shield.

this is the sketch i have wrote
// ---------------------------------------------------------
void loop() {
wdt_reset ();

  EthernetClient client = server.available();
  if (client) {
     wdt_reset ();
    if (client.available() > 0) {
      char thisChar = client.read();
      Serial.write(thisChar);
      RXtext +=thisChar;
      // --------------------- this one repeat for few other strings ----
      if (RXtext.indexOf("L1_On")>=0){
        // do stuff
        RXtext = GetStat();  // get system status and replay
        server.print(RXtext);
        Serial.println(RXtext);
        RXtext = "";

     wdt_reset ();
      }
      // ---------- end of repeat -------
}
}
//-------------------------------------------------------------------------------


for some reason the arduino gets stuck after few times i connect to it
it does not resets the wtd and it gets reset and the it looses the ip and gets 255.255.255.255 ip

can someone tell me what is the peoblem?


Logged

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

Why do you need the watch dog reset?

Why are you still using the String class? It has known, well-documented, problems. Quit shooting yourself in the foot. Get rid of it.
Logged

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

Why do you need the watch dog reset?

Why are you still using the String class? It has known, well-documented, problems. Quit shooting yourself in the foot. Get rid of it.

I'm using the watch dog to make sure it's still running

what should i use instead of String?
Logged

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

Quote
I'm using the watch dog to make sure it's still running
Fixing the problems that are causing it to stop working is almost always a better idea.

Quote
what should i use instead of String?
Null-terminated arrays of chars, also known as strings. Which are not the same thing as Strings.
Logged

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

what should i use instead of String?
A character array. Here is my server code. It does not use String types, and closes the connection when finished sending packets. You may also be running out of sockets. There are only 4.
http://playground.arduino.cc/Code/WebServerST
Logged

0
Offline Offline
Tesla Member
***
Karma: 114
Posts: 8911
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Client test code you can try:

Code:
//zoomkat 9-22-12
//simple client test
//for use with IDE 1.0.1
//with DNS, DHCP, and Host
//open serial monitor and send an e to test
//for use with W5100 based ethernet shields

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

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address

char serverName[] = "web.comporium.net"; // zoomkat's test web page server
EthernetClient client;

//////////////////////

void setup(){

  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    while(true);
  }

  Serial.begin(9600);
  Serial.println("Better client test 9/22/12"); // so I can keep track of what is loaded
  Serial.println("Send an e in serial monitor to test"); // what to do to test
}

void loop(){
  // check for serial input
  if (Serial.available() > 0) //if something in serial buffer
  {
    byte inChar; // sets inChar as a byte
    inChar = Serial.read(); //gets byte from buffer
    if(inChar == 'e') // checks to see byte is an e
    {
      sendGET(); // call sendGET function below when byte is an e
    }
  } 
}

//////////////////////////

void sendGET() //client function to send/receive GET request data.
{
  if (client.connect(serverName, 80)) {  //starts client connection, checks for connection
    Serial.println("connected");
    client.println("GET /~shb/arduino.txt HTTP/1.0"); //download text
    client.println("Host: web.comporium.net");
    client.println(); //end of get request
  }
  else {
    Serial.println("connection failed"); //error message if no client connect
    Serial.println();
  }

  while(client.connected() && !client.available()) delay(1); //waits for data
  while (client.connected() || client.available()) { //connected or data available
    char c = client.read(); //gets byte from ethernet buffer
    Serial.print(c); //prints byte to serial monitor
  }

  Serial.println();
  Serial.println("disconnecting.");
  Serial.println("==================");
  Serial.println();
  client.stop(); //stop client

}

Logged

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

Pages: [1]   Go Up
Jump to: