Skip to main content
deleted 709 characters in body
Source Link

Update, usingnow converting the solutiontype to char before calling the PrintXML function resolves my initial issue. If I use the code below, it seems to work forchew up a whilelot of memory, but after a few loops the program seems to stop responding. Ifis there anythingsomething obviously wrong with the code below? If I comment out this, As a workaround I'm just printing the rest ofXML tags using cl.print and the application runs fine, no hangupsmemory usage is stable.

void PrintXMLTag(EthernetClient cl, char* tag,  char* val) 
{
  char tmp [100];
  StrClear(tmp,100);
  sprintf(tmp,"<%s>%s</%s>\n",tag,val,tag);
  cl.print(tmp);
}
void XML_response(EthernetClient cl)
{
  
  cl.println(F("<?xml version = \"1.0\" ?>"));
  cl.println(F("<IO>"));

  char z [2]; 
  sprintf(z,"%d",digitalRead(FanSwitchPIN));
  PrintXMLTag(cl,"fan",z);  
  PrintXMLTag(cl,"pingtime",PingTime); 
  PrintXMLTag(cl,"PingText",PingText); 
  
  char x [100]; 
  dtostrf(humidity, 8, 1, x); 
  PrintXMLTag(cl,"humidity",x);  
  dtostrf(tempcelcius, 8, 1, x); 
  PrintXMLTag(cl,"tempcelcius",x);    
  cl.println(F("</IO>"));
}

// sets every element of str to 0 (clears array)
void StrClear(char *strtmp, char length)
{
    for (int i = 0; i < length; i++100) {
        str[i] = 0;
    };
}

Update, using the solution below, it seems to work for a while, but after a few loops the program seems to stop responding. If there anything obviously wrong with the code below? If I comment out this, the rest of the application runs fine, no hangups.

void PrintXMLTag(EthernetClient cl, char* tag,  char* val) 
{
  char tmp [100];
  StrClear(tmp,100);
  sprintf(tmp,"<%s>%s</%s>\n",tag,val,tag);
  cl.print(tmp);
}
void XML_response(EthernetClient cl)
{
  
  cl.println(F("<?xml version = \"1.0\" ?>"));
  cl.println(F("<IO>"));

  char z [2]; 
  sprintf(z,"%d",digitalRead(FanSwitchPIN));
  PrintXMLTag(cl,"fan",z);  
  PrintXMLTag(cl,"pingtime",PingTime); 
  PrintXMLTag(cl,"PingText",PingText); 
  
  char x [100]; 
  dtostrf(humidity, 8, 1, x); 
  PrintXMLTag(cl,"humidity",x);  
  dtostrf(tempcelcius, 8, 1, x); 
  PrintXMLTag(cl,"tempcelcius",x);    
  cl.println(F("</IO>"));
}

// sets every element of str to 0 (clears array)
void StrClear(char *str, char length)
{
    for (int i = 0; i < length; i++) {
        str[i] = 0;
    }
}

Update, now converting the type to char before calling the PrintXML function resolves my initial issue. If I use the code below it seems to chew up a lot of memory, is there something obviously wrong? As a workaround I'm just printing the XML tags using cl.print and the memory usage is stable.

void PrintXMLTag(EthernetClient cl, char* tag,  char* val) 
{
  char tmp [100];
  sprintf(tmp,"<%s>%s</%s>\n",tag,val,tag);
  cl.print(tmp);
  StrClear(tmp,100);
}
Updated code seems to hang
Source Link

Update, using the solution below, it seems to work for a while, but after a few loops the program seems to stop responding. If there anything obviously wrong with the code below? If I comment out this, the rest of the application runs fine, no hangups.

void PrintXMLTag(EthernetClient cl, char* tag,  char* val) 
{
  char tmp [100];
  StrClear(tmp,100);
  sprintf(tmp,"<%s>%s</%s>\n",tag,val,tag);
  cl.print(tmp);
}
void XML_response(EthernetClient cl)
{
  
  cl.println(F("<?xml version = \"1.0\" ?>"));
  cl.println(F("<IO>"));

  char z [2]; 
  sprintf(z,"%d",digitalRead(FanSwitchPIN));
  PrintXMLTag(cl,"fan",z);  
  PrintXMLTag(cl,"pingtime",PingTime); 
  PrintXMLTag(cl,"PingText",PingText); 
  
  char x [100]; 
  dtostrf(humidity, 8, 1, x); 
  PrintXMLTag(cl,"humidity",x);  
  dtostrf(tempcelcius, 8, 1, x); 
  PrintXMLTag(cl,"tempcelcius",x);    
  cl.println(F("</IO>"));
}

// sets every element of str to 0 (clears array)
void StrClear(char *str, char length)
{
    for (int i = 0; i < length; i++) {
        str[i] = 0;
    }
}

Update, using the solution below, it seems to work for a while, but after a few loops the program seems to stop responding. If there anything obviously wrong with the code below? If I comment out this, the rest of the application runs fine, no hangups.

void PrintXMLTag(EthernetClient cl, char* tag,  char* val) 
{
  char tmp [100];
  StrClear(tmp,100);
  sprintf(tmp,"<%s>%s</%s>\n",tag,val,tag);
  cl.print(tmp);
}
void XML_response(EthernetClient cl)
{
  
  cl.println(F("<?xml version = \"1.0\" ?>"));
  cl.println(F("<IO>"));

  char z [2]; 
  sprintf(z,"%d",digitalRead(FanSwitchPIN));
  PrintXMLTag(cl,"fan",z);  
  PrintXMLTag(cl,"pingtime",PingTime); 
  PrintXMLTag(cl,"PingText",PingText); 
  
  char x [100]; 
  dtostrf(humidity, 8, 1, x); 
  PrintXMLTag(cl,"humidity",x);  
  dtostrf(tempcelcius, 8, 1, x); 
  PrintXMLTag(cl,"tempcelcius",x);    
  cl.println(F("</IO>"));
}

// sets every element of str to 0 (clears array)
void StrClear(char *str, char length)
{
    for (int i = 0; i < length; i++) {
        str[i] = 0;
    }
}

Help with a function that accepts different paramaterparameter types

Source Link
Loading