Pages: [1]   Go Down
Author Topic: Problem with resetting: ArduinoEthernet & Uno+ wifly  (Read 893 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 37
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi there,

My project requires uploading sensor data to pachube.  I'm using an arduino ethernet for one solution and also trying an Uno with the wifly shield.

Both solutions are up and running, the problem I have is that they both stop working after a while and need to be fully turned off and back on again in order to work.
I have read several posts about this issue, however nothing short of physically pulling the power out and putting it back in again actually does the trick. 

The solution at the bottom of the following page has helped it last more than 30 mins, but still needs turning off and on again after about 20 hours:
http://www.forums.adafruit.com/viewtopic.php?f=8&t=15435

It's really bizarre and very frustrating as everything seems to work fine, even for 20 hours and then suddenly - connection failed - and pressing the reset button does nothing.

Any help would be great.  I'de love to do a definitive tutorial on all the problems i've come across with this setup.

Thanks, Matt
Logged

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

Quote
Both solutions are up and running, the problem I have is that they both stop working after a while and need to be fully turned off and back on again in order to work.

That is not very precise. Do the boards start smoking and spitting plastic when they "stop working"? It is how they fail, not that they fail, that is important.

Maybe if you posted your code...  smiley

BTW, mine used to do that. It would go many hours, then lock up. It ended up being the SD reader SPI interface that was interfering with the w5100 SPI.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 37
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Fair enough.  I will upload my code when I get home.

It seems that the Arduino ethernet sheild starts getting "400 bad request"  from the pachube server.

The wifly connects to the server and then immediately disconnects before sending a POST.

Again, both work great for a while, then suddenly stop.

Logged

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

That was the symptom on mine also. I had access to the logs on the server (mine), so I could see the requests were being buggered up. Disabling the SD SPI interface stopped that "scrambled up" request stuff.

Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 37
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@surferTim - Thanks for the suggestion, I've tried setting pin4 high and 10 low to disable the SD SPI - no luck smiley-sad

Ok Here's the code on the UnoR3 + wifly  shield.
This has so far worked for a max of 2 hours and then failed to receive any response from the server.
Also, interestingly this is all I get in the console:
connecting...
connected
HTTP/1.1 200 OK
Date: Mon, 12 Mar 2012 20:02:48 GMT
Content-Ty
disconnecting.
disconnected.


Code:
#include "WiFly.h"

#include "Credentials.h"


//byte server[] = { 173,203,98,29 };

WiFlyClient client("api.pachube.com", 80);

void setup() {
  
  //pinMode(8,OUTPUT);
  //digitalWrite(8,HIGH);
  // lots of time for the WiFly to start up and also in case I need to stop the transmit
  delay(10000);
  
  Serial.begin(9600);

  
  Serial.println("Wifly begin");
  WiFly.begin();  
  
  Serial.println("Wifly join");
  //if (!WiFly.join(ssid, passphrase, WEP_MODE)) {
    if (!WiFly.join(ssid, passphrase)) {
    Serial.println("Association failed.");
    while (1) {
      // Hang on failure.
    }
  }  

}

uint32_t timeLastUpdated;
int i;
char buff[64];

void loop() {
  if (millis() - timeLastUpdated > TIMETOUPDATE)
  {  // time for the next update
    timeLastUpdated = millis();

    int thisData = random(100);

    Serial.println("connecting...");
    if (client.connect()) {
      Serial.println("connected");
      client.print("PUT /v2/feeds/");  // APIV2
      client.print(PACHUBEFEED);
      client.print(".csv HTTP/1.1\r\n");
      client.print("Host: api.pachube.com\r\n");
      client.print("X-PachubeApiKey:");
      client.println(APIKEY);
      client.print("Content-Type: text/csv\nContent-Length: ");
      
      int thisLength = getLength(thisData)+4;
      client.println(thisLength, DEC);
      client.println("Connection: close\n");
      
      client.print(1,DEC);
      client.print(",");
      client.println(thisData,DEC);
  
    } else {
      Serial.println("connection failed");
    }

    delay(2000);
    while (client.available()) {
     Serial.write(client.read());  
    }
    Serial.println();
  
    if (client.connected()) {
      Serial.println("disconnecting.");
      client.stop();
      Serial.println("disconnected.");
    }
  }
}


int getLength(int someValue) {
  // there's at least one byte:
  int digits = 1;
  // continually divide the value by ten,
  // adding one to the digit count for each
  // time you divide, until you're at 0:
  int dividend = someValue /10;
  while (dividend > 0) {
    dividend = dividend /10;
    digits++;
  }
  // return the number of digits:
  return digits;
}


I'll start with this one as it is my main concern.  I know getting to the root of the problem is the best thing to do but I'd also like to explore the idea of an automated power reset with maybe a 555 and relay?

Thanks, Matt
« Last Edit: March 12, 2012, 03:15:26 pm by matto » Logged

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

This may not wait for the entire response. It may only get the first packet. That will leave the connection open. Then you will eventually run out of sockets.
Code:
while (client.available()) {
     Serial.write(client.read()); 
    }
    Serial.println();
   
    if (client.connected()) {
      Serial.println("disconnecting.");
      client.stop();
      Serial.println("disconnected.");
    }

Use something like this:
Code:
   Serial.println("Getting response");
   while(client.connected())
   {
      // wait for server to close the connection
      // that is the signal it is finished sending

      while (client.available()) {
         // the server will not close the connection until it has sent the final packet
         // and this buffer is empty
         Serial.write(client.read()); 
       }
   }
   // close your end after the server closes its end
   client.stop();
   Serial.println("disconnected.");
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 37
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

oooh ok, thanks surferTim!

I'll try this out later.  Annoyingly, I have to wait around 24 hours to see if any solution works!!
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 37
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok, I have tried your solution, surferTim.
My code is now as before but with the part you specified replaced with your code.

Unfortunately, now I am not getting one successful post.  Here is what comes up in the serial monitor on two separate attemps:

Code:
Wifly begin
Wifly join
connecting...
connected
Getting response
HTTP/1.1 200 OK
Date: Tue, 13 Mar 2012 19:31:23 GMT
Content-Ty


Code:
Wifly begin
Wifly join
connecting...
connected
Getting response
PUT /v2/feeds/51584.csv HTTP/1.1

ERR: ?-Cmd
<2.21>
Host: api

It seems now that the server doesn't close the connection and therefore it just hangs.
I'm really stuck at this point... again, any help would be great.
« Last Edit: March 13, 2012, 02:40:34 pm by matto » Logged

Pages: [1]   Go Up
Jump to: