zoomkat:
no i do not. i thought that when a function is ended, any local variables used within the function were cleared.
From what others have discussed, that is the premis of Strings issue, that the last String memory location used in the function is not automatically cleared as expected, resulting in that memory location no longer being available for use. May or may not help.
i have read that as well.
i have added to my code the lines to set all used strings to "" before the function ends. so far the arduino has 14 hours of up time.
i am in the process of trying to remove all uses of strings within my code. the main area strings are used is in processing of the data submitted by a web-page form in the function "sendPage"
void sendPage(EthernetClient & client, int nUriIndex, BUFFER & requestContent, char * global_pUri)
{
if (nUriIndex < NUM_PAGES){
wdt_reset();
String datastring = "";
//page was received, need to determine if the page returned ay form data
//if form data was was received we need to process it on a per page process
//page 1 does not have any form data
//page 2 have 17 form entries for different temperature settings. these settings need to be extracted from the requestcontent
//variable. once the data is extracted it needs to be saved to the correct variables and then to EEPROM so the setting take effect
//between power outages
/***************************************************************
//PAGE 2 DATA PROCESSING
***************************************************************/
if (nUriIndex == 1){//page 2
//convert the request content variable from an array into a string
for (byte x=0; x < 129; x++){
datastring.concat(requestContent[x]);
}
if (datastring.substring(0,2)=="1="){ //tests if the page has had a form submitted with data or not
for (byte x = 1; x<18; x++){ //page 2 contains 17 data entry text boxes, so we want to run through all of them
String temp1 = ""; //initilize temp variables to clear any previous data
String temp2 = "";
//the format for the submitetd form data is:
//1=entry1&2=entry2&3=entry3 ect...
//we want to use the sub string command, so we need to know the index locations for where the desired data entry index is
//along with the data entry index of the next entry.
temp1.concat(x);
temp1.concat("=");
temp2.concat(x+1);
temp2.concat("=");
//we need to see if the current entry is below 10. if the entry is below 10, we only need to skip 2 entries, one for the entry number
//and another for the equals sign. however if the entry is above 10, we need to skip 3 entries becuase of the two digits for the entry
//and another entry for the equals sign
if (x<10){
char valueArray[datastring.substring(datastring.indexOf(temp1) + 2,datastring.indexOf(temp2) -1).length() + 1];
datastring.substring(datastring.indexOf(temp1) + 2,datastring.indexOf(temp2) -1).toCharArray(valueArray, sizeof(valueArray));
if (x == 1){ //if the currently processing entry is entry 1
if (atoi(valueArray)>= min_temp_setting && atoi(valueArray) <= max_temp_setting){ //is the entred entry within the allowable bounds?
INCSGDTON = atoi(valueArray); //converts the string value of the entred data into a interger
if (EEPROM.read(INCSGDTONEEPROMADDR)!=INCSGDTON){ //if the user has not changed the entry from what is already in memory, then we do not want to save to EEPROM again as the EEPROM has a shorter life time
EEPROM.write(INCSGDTONEEPROMADDR, INCSGDTON); //since the user has entered a new number, we now need to save this to memory
INCSGDTON_incorrect = false; //because a valid entry was entered, we do not want the web-page to display "Invalid Entry!"
}
}else{
INCSGDTON_incorrect = true;//if the user did enter an invalid value then we want the web-page to display "invalid entry!" when the substitution function runs
}
}else if (x == 2){
if (atoi(valueArray)>= min_temp_setting && atoi(valueArray) <= max_temp_setting){
CSGDTOFF = atoi(valueArray);
if (EEPROM.read(CSGDTOFFEEPROMADDR)!=CSGDTOFF){
EEPROM.write(CSGDTOFFEEPROMADDR, CSGDTOFF);
CSGDTOFF_incorrect = false;
}
}else{
CSGDTOFF_incorrect = true;
}
}else if (x == 3){
if (atoi(valueArray)>= min_temp_setting && atoi(valueArray) <= max_temp_setting){
MSGDTON = atoi(valueArray);
if (EEPROM.read(MSGDTONEEPROMADDR)!=MSGDTON){
EEPROM.write(MSGDTONEEPROMADDR, MSGDTON);
MSGDTON_incorrect = false;
}
}else{
MSGDTON_incorrect = true;
}
}else if (x == 4){
if (atoi(valueArray)>= min_temp_setting && atoi(valueArray) <= max_temp_setting){
MSGDTOFF = atoi(valueArray);
if (EEPROM.read(MSGDTOFFEEPROMADDR)!=MSGDTOFF){
EEPROM.write(MSGDTOFFEEPROMADDR, MSGDTOFF);
MSGDTOFF_incorrect = false;
}
}else{
MSGDTOFF_incorrect = true;
}
}else if (x == 5){
ect....
i turn the submitted data into a string so i can use this code
char valueArray[datastring.substring(datastring.indexOf(temp1) + 2,datastring.indexOf(temp2) -1).length() + 1];
datastring.substring(datastring.indexOf(temp1) + 2,datastring.indexOf(temp2) -1).toCharArray(valueArray, sizeof(valueArray));
to extract the different entry values
i have not tested it yet, but i am going to try using the following demonstration code instead
#include <.h>
void setup()
{
// start serial port at 9600 bps:
Serial.begin(9600);
}
void loop()
{
//incomming string of data. string is actually 128 characters long, but this is the only section we care ot process. The "=%" indicates the end of the part of the strign we care about
char str[] = "1=80&2=82&3=83&4=84&5=85&6=86&7=87&8=88&9=89&10=90&11=91&12=92&13=93&14=94&15=95&16=96&17=97&18=%";
Serial.print("The string of submitted data is: ");
Serial.println(str);
for (byte x = 1;x<=17;x++){
char ValueArray={NULL};
PROCESSREQUESTCONTENT(x, str, &ValueArray);
Serial.print("The value of entry # ");
Serial.print(x);
Serial.print(" is equal to: ");
Serial.println(atoi((char *)ValueArray));
}
}
void PROCESSREQUESTCONTENT(byte index, char * str, char * output){
int pch=0;
byte beginning=0;
byte ending=0;
byte counter=0;
//locate where "%" is located so we know where to stop
pch=atoi(strchr(str,'%'));
//"pch-4" is required because pch indicates where the "%" sign is with the first character starting at 1. however the char array starts at 0. in addition we do not care about the "&17=" part of the ending.
//the length of the "5" itself is removed because of the offset from starting point 1 to starting point 0
//the "-4" is so the code ignores the "&18=" characters
for (byte x=0;x<= pch-4;x++){
if (strncmp((char *)str[x],"=",1)==0){
beginning = x+1; //starting character position of actual data entry
}else if (strncmp((char *)str[x],"&",1)==0){
ending=x-1;//ending character position of actual data entry
counter++;//increment counter so we can see if this is the data entry we care about
}
if (counter==index){//have we found the data antry we care about?
counter = 0;
for (byte i=0; i<=(ending-beginning);i++){//copy the data entry so we can use it
output[i] = str[beginning + i];
break;
}
}
}
}
wish me luck