Forum >Xboard hang
ArduinoGeneral

Xboard hang

userHead roysoala 2012-05-26 18:25:02 9177 Views19 Replies
i bought [url=http://www.dfrobot.com/index.php?route=product/product&filter_name=xboard&product_id=494]http://www.dfrobot.com/index.php?route=product/product&filter_name=xboard&product_id=494[/url] and sketch it webclient program. after running for a long time, say 1 day or 2 days, it's stop working. the same thing happen when i sketch it a pachube program, it's stop working like crash. we have to restart it to change it back to normal.

is this always happen on "arduethernet"? because we don't have this problem when we use ethernet + ethershield with the same sketch. please help. thanks.
2012-05-30 19:14:52 i made a modification on the sketch and it seems the xboard more stable by now. here is the modification :

1. i reset the program at the end of the process:
- add this on the setup()
void setup()
{
  MCUSR=0;
}

2. create this void:
void software_Reset() // Restarts program from beginning but does not reset the peripherals and registers
{
asm volatile ("  jmp 0"); 
}

3. put software_Reset() at the end of the process after delay it 60s for pachube transmitting interval:

void disconnect_pachube(){
  Serial.println("disconnecting.\n=====\n\n");
  client.stop();
  ready_to_update = false;
  reading_pachube = false;
  request_pause = true;
  last_connect = millis();
  found_content = false;
  resetEthernetShield();
  while ((millis() - last_connect) < 60000) { // do nothing for 60s
  wdt_reset();
}
  software_Reset();
}


the program looks more stable than before, and xboard doesn't hang anymore.
userHeadPic roysoala
2012-05-30 19:14:52 i made a modification on the sketch and it seems the xboard more stable by now. here is the modification :

1. i reset the program at the end of the process:
- add this on the setup()
void setup()
{
  MCUSR=0;
}

2. create this void:
void software_Reset() // Restarts program from beginning but does not reset the peripherals and registers
{
asm volatile ("  jmp 0"); 
}

3. put software_Reset() at the end of the process after delay it 60s for pachube transmitting interval:

void disconnect_pachube(){
  Serial.println("disconnecting.\n=====\n\n");
  client.stop();
  ready_to_update = false;
  reading_pachube = false;
  request_pause = true;
  last_connect = millis();
  found_content = false;
  resetEthernetShield();
  while ((millis() - last_connect) < 60000) { // do nothing for 60s
  wdt_reset();
}
  software_Reset();
}


the program looks more stable than before, and xboard doesn't hang anymore.
userHeadPic roysoala
2012-05-29 21:18:58 [quote="Hector"]
Roy,


I will try to replicate your problem on Wednesday, I will be out of the office tomorrow.


Hopefully we can replicate your problem and come up with a solution.
[/quote]

thanks hector, can't wait to hear from you about the result.
userHeadPic roysoala
2012-05-29 21:18:58 [quote="Hector"]
Roy,


I will try to replicate your problem on Wednesday, I will be out of the office tomorrow.


Hopefully we can replicate your problem and come up with a solution.
[/quote]

thanks hector, can't wait to hear from you about the result.
userHeadPic roysoala
2012-05-29 01:02:06 Roy,


I will try to replicate your problem on Wednesday, I will be out of the office tomorrow.


Hopefully we can replicate your problem and come up with a solution.
userHeadPic Hector
2012-05-29 01:02:06 Roy,


I will try to replicate your problem on Wednesday, I will be out of the office tomorrow.


Hopefully we can replicate your problem and come up with a solution.
userHeadPic Hector
2012-05-28 23:22:18 [quote="Ricky"]
Would that be possible to post your code here?  We can try to  recreate your problem.
[/quote]


#include "EmonLib.h"            // Include Emon Library
#include <SPI.h>
#include <Ethernet.h>
#include <string.h>
#undef int() // needed by arduino 0011 to allow use of stdio
#include <stdio.h> // for function sprintf
#include <avr/wdt.h>

#define SHARE_FEED_ID              60XXX      // the Pachube feed ID that shares your sensor data
#define CONTROL_FEED_ID            60XXX      // feed ID of the Pachube controller feed
#define UPDATE_INTERVAL            60000    // if the connection is good wait 60 seconds (1 minute)  before updating again - should not be less than 5
#define RESET_INTERVAL            60000    // if connection fails/resets wait 60 seconds before trying again - should not be less than 5

#define PACHUBE_API_KEY            "MY_API_KEY" // fill in your API key



byte mac[] = {
  0xCC, 0xAC, 0xBE, 0xEF, 0xFE, 0x93 }; // make sure this is unique on your network
byte ip[] = {
  192, 168, 169, 244  };                  // no DHCP so we set our own IP address
byte gateway[] = { 192,168,169, 1 }; 
byte remoteServer[] = {
  209,40,205,190 };            // pachube.com

int digital_state[10];        // array to hold variables we grab from the controller feed
int analog_state[4];          // array to hold variables we grab from the controller feed
int analog_pins[] = {
  3, 5, 6, 9}; // array to hold analog pin numbers

EnergyMonitor emon1;            // Create an instance EMON



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

  for (int i = 0; i < 10; i++){
    pinMode(i, OUTPUT);
  }
  emon1.voltage(2, 234.26, 1.7);  // Voltage: input pin, calibration, phase_shift
  emon1.current(1, 29);      // Current: input pin, calibration.  CT SCT-013-030 ratio=1800, RL 62 Ohm. calibration const= 1800/62 = 29 
  wdt_enable(WDTO_8S); // setup Watch Dog Timer to 8 sec
}

void loop()
{

  wdt_reset();
  pachube_in_out();
}


---


EthernetClient client;
unsigned int interval;
char buff[64];
int pointer = 0;
void setupEthernet(){
  resetEthernetShield();
//  client remoteClient(255);
  delay(500);
  interval = UPDATE_INTERVAL;
  Serial.println("setup complete");
  wdt_reset();
}

void clean_buffer() {
  pointer = 0;
  memset(buff,0,sizeof(buff));
}

void resetEthernetShield(){
  Serial.println("reset ethernet");
  Ethernet.begin(mac, ip);
  wdt_reset();
}

---

char pachube_data[70];
int value;
char sbuf[15];
char dbuf[15];

boolean found_status_200 = false;
boolean found_session_id = false;
boolean found_control_values = false;
char *found;
unsigned int successes = 0;
unsigned int failures = 0;
boolean ready_to_update = true;
boolean reading_pachube = false;

boolean request_pause = false;
boolean found_content = false;

unsigned long last_connect;

boolean found_a = false;
boolean found_d = false;

int content_length;

double Ivrms, Vrms;

void pachube_in_out(){
  wdt_reset();
  if (millis() < last_connect) last_connect = millis();

  if (request_pause){
    wdt_reset();
    if ((millis() - last_connect) > interval){
      ready_to_update = true;
      reading_pachube = false;
      request_pause = false;
      found_status_200 = false;
      found_session_id = false;
      found_control_values = false;
      found_a = false;
      found_d = false;
      Serial.print("Ready to connect: ");
      Serial.println(millis());
    }
  }

  if (ready_to_update){
    wdt_reset();
    Serial.println("Connecting...");
    if (client.connect("www.pachube.com", 80)) {

      sprintf(pachube_data,"%d,%d,%d,%d,%d,%d,%d,%d",analogRead(0),10,20,analogRead(3),analogRead(4),analogRead(5), successes + 1, failures);
      content_length = strlen(pachube_data);

      Serial.println("GET request to retrieve");

      client.print("GET /api/");
      client.print(CONTROL_FEED_ID);
      client.print(".csv HTTP/1.1\nHost: pachube.com\nX-PachubeApiKey: ");
      client.print(PACHUBE_API_KEY);
      client.print("\nUser-Agent: Arduino (Pachube controller v1.1)");
      client.println("\n");

      Serial.println("finished GET");

      client.print("PUT /api/");
      client.print(SHARE_FEED_ID);
      client.print(".csv HTTP/1.1\nHost: pachube.com\nX-PachubeApiKey: ");
      client.print(PACHUBE_API_KEY);

      client.print("\nUser-Agent: Arduino (Pachube controller v1.1)");
      client.print("\nContent-Type: text/csv\nContent-Length: ");
      client.print(content_length);
      client.print("\nConnection: close\n\n");
      client.print(pachube_data);

      client.print("\n");


      ready_to_update = false;
      reading_pachube = true;
      request_pause = false;
      interval = UPDATE_INTERVAL;

      Serial.print("finished PUT: ");
      Serial.println(millis());
      Serial.print("pachube_data=");
      Serial.println(pachube_data);

    }
    else {
      wdt_reset();
      Serial.print("connection failed!");
      Serial.print(++failures);
      found_status_200 = false;
      found_session_id = false;
      found_control_values = false;
      ready_to_update = false;
      reading_pachube = false;
      request_pause = true;
      last_connect = millis();
      interval = RESET_INTERVAL;
      setupEthernet();
    }
  }

  while (reading_pachube){
    while (client.available()) {
      checkForResponse();
    }

    if (!client.connected()) {
      disconnect_pachube();
    }
  }
}

void disconnect_pachube(){
  wdt_reset();
  Serial.println("disconnecting.\n=====\n\n");
  client.stop();
  ready_to_update = false;
  reading_pachube = false;
  request_pause = true;
  last_connect = millis();
  found_content = false;
  resetEthernetShield();
}



void checkForResponse(){ 
  wdt_reset();
  char c = client.read();
  Serial.print(c);
  buff[pointer] = c;
  if (pointer < 64) pointer++;
  if (c == '\n') {
    found = strstr(buff, "200 OK");
    if (found != 0){
      found_status_200 = true;
      Serial.println("Status 200 found");
    }
    buff[pointer]=0;
    found_content = true;
    clean_buffer();   
  }

  if ((found_session_id) && (!found_control_values)){
    if (!found_d) {
      found = strstr(buff, "d=");
      if (found != 0){
        char dLine[8];
        for (int i = 0; i < 8; i++){
          dLine[i] = client.read();
        }
        found_d = true;
        Serial.print("d:");   
        Serial.println(dLine);
        for (int i = 0; i < 8; i++){
        digital_state[i] = (int) (dLine[i] - 48);
        Serial.print(digital_state[i]);
        Serial.print(", ");
        }
       
      }
    }
    value= digital_state[0]*128+digital_state[1]*64+digital_state[2]*32+digital_state[3]*16+digital_state[4]*8+digital_state[5]*4+digital_state[6]*2+digital_state[7];

    found = strstr(buff, "HTTP/1.1");
    if (found != 0){
      wdt_reset();
      char csvLine[strlen(buff)-9];
      strncpy (csvLine,buff,strlen(buff)-9);
      found_control_values = true;

      Serial.print("\nsuccessful updates=");
      Serial.println(++successes);
      Serial.print("value=");
      Serial.println(value);
      writeOutput();
    }
  }

  if (found_status_200){
    found = strstr(buff, "Vary:");
    if (found != 0){
      clean_buffer();
      found_session_id = true;
    }
  }
}

void writeOutput()
{
    wdt_reset();
    digitalWrite(7, LOW);                      // Pull latch LOW to send data
    shiftOut(9, 8, MSBFIRST, value);      // Send the data 
    digitalWrite(7, HIGH);                      // Pull latch HIGH to stop sending data
 
}
userHeadPic roysoala
2012-05-28 23:22:18 [quote="Ricky"]
Would that be possible to post your code here?  We can try to  recreate your problem.
[/quote]


#include "EmonLib.h"            // Include Emon Library
#include <SPI.h>
#include <Ethernet.h>
#include <string.h>
#undef int() // needed by arduino 0011 to allow use of stdio
#include <stdio.h> // for function sprintf
#include <avr/wdt.h>

#define SHARE_FEED_ID              60XXX      // the Pachube feed ID that shares your sensor data
#define CONTROL_FEED_ID            60XXX      // feed ID of the Pachube controller feed
#define UPDATE_INTERVAL            60000    // if the connection is good wait 60 seconds (1 minute)  before updating again - should not be less than 5
#define RESET_INTERVAL            60000    // if connection fails/resets wait 60 seconds before trying again - should not be less than 5

#define PACHUBE_API_KEY            "MY_API_KEY" // fill in your API key



byte mac[] = {
  0xCC, 0xAC, 0xBE, 0xEF, 0xFE, 0x93 }; // make sure this is unique on your network
byte ip[] = {
  192, 168, 169, 244  };                  // no DHCP so we set our own IP address
byte gateway[] = { 192,168,169, 1 }; 
byte remoteServer[] = {
  209,40,205,190 };            // pachube.com

int digital_state[10];        // array to hold variables we grab from the controller feed
int analog_state[4];          // array to hold variables we grab from the controller feed
int analog_pins[] = {
  3, 5, 6, 9}; // array to hold analog pin numbers

EnergyMonitor emon1;            // Create an instance EMON



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

  for (int i = 0; i < 10; i++){
    pinMode(i, OUTPUT);
  }
  emon1.voltage(2, 234.26, 1.7);  // Voltage: input pin, calibration, phase_shift
  emon1.current(1, 29);      // Current: input pin, calibration.  CT SCT-013-030 ratio=1800, RL 62 Ohm. calibration const= 1800/62 = 29 
  wdt_enable(WDTO_8S); // setup Watch Dog Timer to 8 sec
}

void loop()
{

  wdt_reset();
  pachube_in_out();
}


---


EthernetClient client;
unsigned int interval;
char buff[64];
int pointer = 0;
void setupEthernet(){
  resetEthernetShield();
//  client remoteClient(255);
  delay(500);
  interval = UPDATE_INTERVAL;
  Serial.println("setup complete");
  wdt_reset();
}

void clean_buffer() {
  pointer = 0;
  memset(buff,0,sizeof(buff));
}

void resetEthernetShield(){
  Serial.println("reset ethernet");
  Ethernet.begin(mac, ip);
  wdt_reset();
}

---

char pachube_data[70];
int value;
char sbuf[15];
char dbuf[15];

boolean found_status_200 = false;
boolean found_session_id = false;
boolean found_control_values = false;
char *found;
unsigned int successes = 0;
unsigned int failures = 0;
boolean ready_to_update = true;
boolean reading_pachube = false;

boolean request_pause = false;
boolean found_content = false;

unsigned long last_connect;

boolean found_a = false;
boolean found_d = false;

int content_length;

double Ivrms, Vrms;

void pachube_in_out(){
  wdt_reset();
  if (millis() < last_connect) last_connect = millis();

  if (request_pause){
    wdt_reset();
    if ((millis() - last_connect) > interval){
      ready_to_update = true;
      reading_pachube = false;
      request_pause = false;
      found_status_200 = false;
      found_session_id = false;
      found_control_values = false;
      found_a = false;
      found_d = false;
      Serial.print("Ready to connect: ");
      Serial.println(millis());
    }
  }

  if (ready_to_update){
    wdt_reset();
    Serial.println("Connecting...");
    if (client.connect("www.pachube.com", 80)) {

      sprintf(pachube_data,"%d,%d,%d,%d,%d,%d,%d,%d",analogRead(0),10,20,analogRead(3),analogRead(4),analogRead(5), successes + 1, failures);
      content_length = strlen(pachube_data);

      Serial.println("GET request to retrieve");

      client.print("GET /api/");
      client.print(CONTROL_FEED_ID);
      client.print(".csv HTTP/1.1\nHost: pachube.com\nX-PachubeApiKey: ");
      client.print(PACHUBE_API_KEY);
      client.print("\nUser-Agent: Arduino (Pachube controller v1.1)");
      client.println("\n");

      Serial.println("finished GET");

      client.print("PUT /api/");
      client.print(SHARE_FEED_ID);
      client.print(".csv HTTP/1.1\nHost: pachube.com\nX-PachubeApiKey: ");
      client.print(PACHUBE_API_KEY);

      client.print("\nUser-Agent: Arduino (Pachube controller v1.1)");
      client.print("\nContent-Type: text/csv\nContent-Length: ");
      client.print(content_length);
      client.print("\nConnection: close\n\n");
      client.print(pachube_data);

      client.print("\n");


      ready_to_update = false;
      reading_pachube = true;
      request_pause = false;
      interval = UPDATE_INTERVAL;

      Serial.print("finished PUT: ");
      Serial.println(millis());
      Serial.print("pachube_data=");
      Serial.println(pachube_data);

    }
    else {
      wdt_reset();
      Serial.print("connection failed!");
      Serial.print(++failures);
      found_status_200 = false;
      found_session_id = false;
      found_control_values = false;
      ready_to_update = false;
      reading_pachube = false;
      request_pause = true;
      last_connect = millis();
      interval = RESET_INTERVAL;
      setupEthernet();
    }
  }

  while (reading_pachube){
    while (client.available()) {
      checkForResponse();
    }

    if (!client.connected()) {
      disconnect_pachube();
    }
  }
}

void disconnect_pachube(){
  wdt_reset();
  Serial.println("disconnecting.\n=====\n\n");
  client.stop();
  ready_to_update = false;
  reading_pachube = false;
  request_pause = true;
  last_connect = millis();
  found_content = false;
  resetEthernetShield();
}



void checkForResponse(){ 
  wdt_reset();
  char c = client.read();
  Serial.print(c);
  buff[pointer] = c;
  if (pointer < 64) pointer++;
  if (c == '\n') {
    found = strstr(buff, "200 OK");
    if (found != 0){
      found_status_200 = true;
      Serial.println("Status 200 found");
    }
    buff[pointer]=0;
    found_content = true;
    clean_buffer();   
  }

  if ((found_session_id) && (!found_control_values)){
    if (!found_d) {
      found = strstr(buff, "d=");
      if (found != 0){
        char dLine[8];
        for (int i = 0; i < 8; i++){
          dLine[i] = client.read();
        }
        found_d = true;
        Serial.print("d:");   
        Serial.println(dLine);
        for (int i = 0; i < 8; i++){
        digital_state[i] = (int) (dLine[i] - 48);
        Serial.print(digital_state[i]);
        Serial.print(", ");
        }
       
      }
    }
    value= digital_state[0]*128+digital_state[1]*64+digital_state[2]*32+digital_state[3]*16+digital_state[4]*8+digital_state[5]*4+digital_state[6]*2+digital_state[7];

    found = strstr(buff, "HTTP/1.1");
    if (found != 0){
      wdt_reset();
      char csvLine[strlen(buff)-9];
      strncpy (csvLine,buff,strlen(buff)-9);
      found_control_values = true;

      Serial.print("\nsuccessful updates=");
      Serial.println(++successes);
      Serial.print("value=");
      Serial.println(value);
      writeOutput();
    }
  }

  if (found_status_200){
    found = strstr(buff, "Vary:");
    if (found != 0){
      clean_buffer();
      found_session_id = true;
    }
  }
}

void writeOutput()
{
    wdt_reset();
    digitalWrite(7, LOW);                      // Pull latch LOW to send data
    shiftOut(9, 8, MSBFIRST, value);      // Send the data 
    digitalWrite(7, HIGH);                      // Pull latch HIGH to stop sending data
 
}
userHeadPic roysoala
2012-05-28 21:21:53 Would that be possible to post your code here?  We can try to  recreate your problem. userHeadPic R2D2C3PO
2012-05-28 21:21:53 Would that be possible to post your code here?  We can try to  recreate your problem. userHeadPic R2D2C3PO
2012-05-28 00:22:32 [quote="synekvl"]
Hi,

I can confirm the same also happened time to time to me with this [url=https://www.dfrobot.com/forum/index.php?topic=428.0]https://www.dfrobot.com/forum/index.php?topic=428.0[/url] project. As far I coudn't recognize whether it is hardware or SW (Pachube library or connection to server) issue I applied the watchdog routine in order to reset the board ...

BTW I'm feeding the data to Pachube/Cosm for more than one year with Mega2560 and official Ethernet shield and I already had few times to reset the board manually because it was not responding. I modified a little bit the sketch code, it is running for a very long time now, but I'm still not sure it is solved.

I'm interesting to hear from another X-Board users whether they also got it not responding.

Cheers
Vladimir
[/quote]

i also modified the sketch and applied watchdog timer to restart the program whenever it crash, but it didn't help. i upgraded the xboard firmware with the optiboot version to make sure the wdt work well. but still no luck, the xboard still hang if it run in long time and haven't found the reason why.
userHeadPic roysoala
2012-05-28 00:22:32 [quote="synekvl"]
Hi,

I can confirm the same also happened time to time to me with this [url=https://www.dfrobot.com/forum/index.php?topic=428.0]https://www.dfrobot.com/forum/index.php?topic=428.0[/url] project. As far I coudn't recognize whether it is hardware or SW (Pachube library or connection to server) issue I applied the watchdog routine in order to reset the board ...

BTW I'm feeding the data to Pachube/Cosm for more than one year with Mega2560 and official Ethernet shield and I already had few times to reset the board manually because it was not responding. I modified a little bit the sketch code, it is running for a very long time now, but I'm still not sure it is solved.

I'm interesting to hear from another X-Board users whether they also got it not responding.

Cheers
Vladimir
[/quote]

i also modified the sketch and applied watchdog timer to restart the program whenever it crash, but it didn't help. i upgraded the xboard firmware with the optiboot version to make sure the wdt work well. but still no luck, the xboard still hang if it run in long time and haven't found the reason why.
userHeadPic roysoala
2012-05-28 00:17:45 [quote="Ricky"]
It may be out of memory. As mega as more memory than atmega328. Double check the memory usage.
[/quote]

if that the case, it should be the same happened on the arduino+ ethernet shield. but as i mentioned, it never happen on the arduino+ethershield, though it's the similar sketch.
userHeadPic roysoala
2012-05-28 00:17:45 [quote="Ricky"]
It may be out of memory. As mega as more memory than atmega328. Double check the memory usage.
[/quote]

if that the case, it should be the same happened on the arduino+ ethernet shield. but as i mentioned, it never happen on the arduino+ethershield, though it's the similar sketch.
userHeadPic roysoala
2012-05-27 23:28:09 It may be out of memory. As mega as more memory than atmega328. Double check the memory usage. userHeadPic R2D2C3PO
2012-05-27 23:28:09 It may be out of memory. As mega as more memory than atmega328. Double check the memory usage. userHeadPic R2D2C3PO
2012-05-26 23:51:32 Hi,

I can confirm the same also happened time to time to me with this [url=https://www.dfrobot.com/forum/index.php?topic=428.0]https://www.dfrobot.com/forum/index.php?topic=428.0[/url] project. As far I coudn't recognize whether it is hardware or SW (Pachube library or connection to server) issue I applied the watchdog routine in order to reset the board ...

BTW I'm feeding the data to Pachube/Cosm for more than one year with Mega2560 and official Ethernet shield and I already had few times to reset the board manually because it was not responding. I modified a little bit the sketch code, it is running for a very long time now, but I'm still not sure it is solved.

I'm interesting to hear from another X-Board users whether they also got it not responding.

Cheers
Vladimir
userHeadPic synekvl
2012-05-26 23:51:32 Hi,

I can confirm the same also happened time to time to me with this [url=https://www.dfrobot.com/forum/index.php?topic=428.0]https://www.dfrobot.com/forum/index.php?topic=428.0[/url] project. As far I coudn't recognize whether it is hardware or SW (Pachube library or connection to server) issue I applied the watchdog routine in order to reset the board ...

BTW I'm feeding the data to Pachube/Cosm for more than one year with Mega2560 and official Ethernet shield and I already had few times to reset the board manually because it was not responding. I modified a little bit the sketch code, it is running for a very long time now, but I'm still not sure it is solved.

I'm interesting to hear from another X-Board users whether they also got it not responding.

Cheers
Vladimir
userHeadPic synekvl
2012-05-26 18:25:02 i bought [url=https://www.dfrobot.com/index.php?route=product/product&filter_name=xboard&product_id=494]https://www.dfrobot.com/index.php?route=product/product&filter_name=xboard&product_id=494[/url] and sketch it webclient program. after running for a long time, say 1 day or 2 days, it's stop working. the same thing happen when i sketch it a pachube program, it's stop working like crash. we have to restart it to change it back to normal.

is this always happen on "arduethernet"? because we don't have this problem when we use ethernet + ethershield  with the same sketch. please help. thanks.
userHeadPic roysoala