Data Transmission Stops - Reset needed?

Hi there,

Ive got a freetronics EtherTen module, and its transmitting data to a Exosite Portal.

What ive found is that intermittantly, the data drops off. When I restart the EtherTen the data pumps through and updates.

What I want to know is how to add a script that will restart the module every 3 hours, just a script reset, the physical stuff attached are not needing to be reset. I thought about programming up a “flash” LED, and swapping the LED for a 5v relay, with a capacitor and breaking the physical power to the device, but I thought there must be a cleaner way.

Could I just use the LED output, along with a resistor and a capacitor to trigger the reset pin?

Ive read about the Watchdog timer, but heard that it can put the panel into a loop and then you cant upload new sketches to it?

Heres a copy of the programming at the moment. Im not even really sure if ive done the LED right, but it seems to work ok.

Thanks heaps for any input :slight_smile:

#include <SPI.h>
#include <Ethernet.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Exosite.h>

 
// User defined variables for Exosite reporting period and averaging samples
#define REPORT_TIMEOUT 120000 //milliseconds period for reporting to Exosite.com
#define SENSOR_READ_TIMEOUT 30000 //milliseconds period for reading sensors in loop
// Pin use
#define ONEWIRE 1 //pin to use for One Wire interface
int led = 13;
 
// Set up which Arduino pin will be used for the 1-wire interface to the sensor
OneWire oneWire(ONEWIRE);
DallasTemperature sensors(&oneWire);
 
//global variables
byte macData[] = { "PUTYOURMACHERE"  }; // <-- Fill in your MAC here! (e.g. {0x90, 0xA2, 0xDA, 0x00, 0x22, 0x33})
String cikData = "5f9ee530514e9a74eefd653944f6e65030248c3f";      // <-- Fill in your CIK here! (https://portals.exosite.com -> Add Device)
Exosite exosite(&Ethernet, macData, cikData);
 
 
//
// The 'setup()' function is the first function that runs on the Arduino.
// It runs completely and when complete jumps to 'loop()'
//
void setup() {

  Serial.begin(9600);
 
  // Start up the OneWire Sensors library
  sensors.begin();
  delay(1000);
  Serial.println("Starting Exosite Temp Monitor");
  Serial.println();
   
  exosite.init();
  delay(2000);
  
  // initialize the digital pin as an output.   
  pinMode(led, OUTPUT);
  
}
 
//
// The 'loop()' function is the 'main' function for Arduino
// and is essentially a constant while loop.
//
void loop() {
  
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  Serial.println();
  Serial.print("LED on");
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  Serial.println();
  Serial.print("LED off");
  delay(30000);               // wait for a second
  

  static unsigned long sendPrevTime = 0;
  static unsigned long sensorPrevTime = 0;
  static float tempF;
   
  Serial.print("."); // print to show running
 
 // Read sensor every defined timeout period
  if (millis() - sensorPrevTime > SENSOR_READ_TIMEOUT)
  {
    Serial.println();
    Serial.print("Requesting temperature...Temp: ");
    sensors.requestTemperatures(); // Send the command to get temperatures
    float tempC = sensors.getTempCByIndex(0);
    tempF = DallasTemperature::toFahrenheit(tempC);
    Serial.print(tempF);
    Serial.println(" F ..........DONE");
     
    sensorPrevTime = millis();
  }
 
  // Send to Exosite every defined timeout period
  if (millis() - sendPrevTime > REPORT_TIMEOUT)
  {
    Serial.println(); //start fresh debug line
    Serial.println("Sending data to Exosite...");
     
    exosite.sendToCloud("temp",tempF);
 
    sendPrevTime = millis(); //reset report period timer
    Serial.println("done sending.");
  }
  
}

Rather than resetting the Arduino, you should address the issue.

String cikData = "5f9ee530514e9a74eefd653944f6e65030248c3f";

Using the String class here is a waste. This won't change while the program is running. If the Exosite really requires a String instance for the third argument, you would be better off finding a better library. One that doesn't think it's running a PC with 4 terabytes of memory.

  Serial.println("Starting Exosite Temp Monitor");

Surely a shorter string would convey the same info, and use less space in SRAM. Or, you could use the F() macro and keep the long string out of SRAM altogether.

There are other strings, too, that should be kept out of SRAM.

  delay(1000);               // wait for a second
  delay(30000);               // wait for a second

If you are going to have useless comments, they should at least be correct useless comments.

It would be possible to add external hardware to intercept the power supply or activate the reset line for a defined period, but I agree with PaulS that is not a good way to tackle the problem. Better to fix the underlying cause. You don't say what the serial output tells you, but I assume that the sketch is still collecting temperature readings and attempting to publish them at regular intervals.

The symptoms suggest that exosite.sendToCloud() is failing. I'm not familiar with that library - does it provide any status information to let you determine whether it's failing, and any guidance on how to recover if it fails?

Allright guys, thanks heaps for your prompt replys :smiley:

I didnt realise how big the scripts were, or what my limit was, Ill chalk it up to experience.

Ive removed most of the name that “prints” - its not necessary when the device is running, so when im testing I just add them back in.
Ive also removed most of the // comments, I again didnt realise how much space they took up, or that that could be the cause for the device to stop/freeze.

Ive removed the LED side of things, and instead added in a temp/humidity sensor, and that too is uploading to the Exosite Portal, link here if anyones interested https://portals.exosite.com/views/4096279265/2848971562

Hopefully the code all looks ok to everyone, id be very thankful for any feedback. Also here in New Zealand we measure in Celcius, but this script, no matter how much I play with it, seems to only want to send in Farenheit, I believe it is the line:

tempF = DallasTemperature::toFahrenheit(tempC);

but for the life of me I cannot get it to send in Celcius, the closest ive gotten is removing that line, converting all the appropriate tags to have a C instead of an F, and when running the Serial Monitor, it displays fine, but it doesnt send anything other than a 0 through to Exosite.

At the moment ive got the Exosite Portal doing all the work converting it from F to C, maybe thats best.

As for removing the CIK string, thats what is needed to be sent each time to the Exosite website, so that it can identify my portal as opposed to someone elses I guess. Unfortunately it needs to be there… Although if I can find another site, thats free, that allows me to do what Im doing, preferably with a Iphone App, then id be happy to change!

Future plans involve adding a pH, and salinity probe to the mix, now its just a matter of tracking the probes down and doing some more coding!

Thanks again for your input and advice :slight_smile:

Heres the full code:

#include <SPI.h>
#include <Ethernet.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Exosite.h>
#include <DHT.h>

 
#define REPORT_TIMEOUT 120000
#define SENSOR_READ_TIMEOUT 30000
// Pin use
#define ONEWIRE 8 //pin to use for One Wire interface
#define DHTPIN 9 //pin to use for DHT22 
#define DHTTYPE DHT22
OneWire oneWire(ONEWIRE);
DallasTemperature sensors(&oneWire);
 
//global variables
byte macData[] = { "PUTYOURMACHERE"  }; // <-- Fill in your MAC here! (e.g. {0x90, 0xA2, 0xDA, 0x00, 0x22, 0x33})
String cikData = "5f9ee530514e9a74eefd653944f6e65030248c3f";      // <-- Fill in your CIK here! (https://portals.exosite.com -> Add Device)
Exosite exosite(&Ethernet, macData, cikData);
DHT dht(DHTPIN, DHTTYPE);

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

  sensors.begin();
  delay(1000);
  Serial.println("Temp Monitor");
  Serial.println();
   
  exosite.init();
  delay(2000);
  
  dht.begin();
 
}
 
void loop() {
  
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  
  static unsigned long sendPrevTime = 0;
  static unsigned long sensorPrevTime = 0;
  static float tempF;
  
  Serial.print(".");
 

  if (millis() - sensorPrevTime > SENSOR_READ_TIMEOUT)
  {
    Serial.println();
    Serial.print("Requesting temperature...Temp: ");
    sensors.requestTemperatures();
    float tempC = sensors.getTempCByIndex(0);
    tempF = DallasTemperature::toFahrenheit(tempC);
    Serial.print(tempF);
    Serial.println(" F ..........DONE");  
    sensorPrevTime = millis();
    
    if (isnan(t) || isnan(h)) {
    Serial.println("Failed to read from DHT");
  } else {
    Serial.print("Humidity: "); 
    Serial.print(h);
    Serial.print(" %\t");
    Serial.print("Temperature: "); 
    Serial.print(t);
    Serial.println(" *C");
  }
  }
 
  // Send to Exosite every defined timeout period
  if (millis() - sendPrevTime > REPORT_TIMEOUT)
  {
    Serial.println(); //start fresh debug line
    Serial.println("Sending data to Exosite...");
     
    exosite.sendToCloud("temp",tempF);
    exosite.sendToCloud("hum",h);
    exosite.sendToCloud("temp2",t);
    
    sendPrevTime = millis(); //reset report period timer
    Serial.println("done sending.");
  }
  delay(5000);
}

Ive also removed most of the // comments, I again didnt realise how much space they took up, or that that could be the cause for the device to stop/freeze.

Comments are notes for you. The compiler deletes them. They take no code space and no SRAM on the Arduino.

Also here in New Zealand we measure in Celcius, but this script, no matter how much I play with it, seems to only want to send in Farenheit, I believe it is the line

That line converts the value in tempC to the equivalent value in tempF. Using tempC after that, instead of tempF, will cause the temperature in Celsius to be posted.

how to change

My ethernet sketches don't lock up, so they don't need to be restarted. They have timeouts in the code that prevent a broken connection from crashing the sketch. Maybe there is something you can use from them in your Exosite code. I don't use Exosite. I have my own servers. http://playground.arduino.cc/Code/WebClient http://playground.arduino.cc/Code/WebServerST

On Exosite displayed in Fahrenheit I would need it in Celsius can you help me

You have two variables - one containing the temperature in F and one containing the temperature in C. USE THE OTHER ONE!