View Single Post
Old 01-03-16, 03:30 PM   #26
Acuario
Apprentice EcoRenovator
 
Join Date: May 2011
Location: Tortosa, Spain
Posts: 218
Thanks: 2
Thanked 75 Times in 44 Posts
Default

12. Ethernet.ino (part 4)

// send the XML file with status
void XML_response(EthernetClient cl)
{
char buf[20];

cl.print(F("<?xml version = \"1.0\" ?>"));
cl.print(F("<inputs>"));
cl.print(F("<systemTime>"));
sprintf(buf, "%02d:%02d:%02d %02d/%02d", tm.Hour, tm.Minute, tm.Second, tm.Day, tm.Month);
cl.print(buf);
cl.print(F("</systemTime>"));
cl.print(F("<bacSetTemp>"));
cl.print(bacSetTemp);
cl.print(F("</bacSetTemp>"));
cl.print(F("<maxWaterTemp>"));
cl.print(maxWaterTemp);
cl.print(F("</maxWaterTemp>"));
cl.print(F("<roomTemp>"));
cl.print(bacRoomTemp);
cl.print(F("</roomTemp>"));
cl.print(F("<compressor>"));
cl.print(tempCompressor);
cl.print(F("</compressor>"));
cl.print(F("<flow>"));
cl.print(flowTemp);
cl.print(F("</flow>"));
cl.print(F("<return>"));
cl.print(returnTemp);
cl.print(F("</return>"));
cl.print(F("<evaporator>"));
cl.print(tempEvaporator);
cl.print(F("</evaporator>"));
cl.print(F("<humidity>"));
cl.print(humidity);
cl.print(F("</humidity>"));
cl.print(F("<dewpoint>"));
cl.print(dewPointTemp);
cl.print(F("</dewpoint>"));
cl.print(F("<bacPowerState>"));
sprintf(buf, "%s", powerStateBAC == FALSE ? sOff : sOn);
cl.print(buf);
cl.print(F("</bacPowerState>"));
cl.print(F("<bacMode>"));
sprintf(buf, "%s", mode[operatingModeBAC]);
cl.print(buf);
cl.print(F("</bacMode>"));
cl.print(F("<defrost>"));
sprintf(buf, "%s", defrostFlag == TRUE ? "YES" : "NO");
cl.print(buf);
cl.print(F("</defrost>"));

cl.print(F("<defrostStep>"));
cl.print(defStep);
cl.print(F("</defrostStep>"));
cl.print(F("<hysterisis>"));
cl.print(hysterisis);
cl.print(F("</hysterisis>"));
cl.print(F("<defCycle>"));
cl.print(timeBetweenDefrost);
cl.print(F("</defCycle>"));
cl.print(F("<state>"));
cl.print(systemState);
cl.print(F("</state>"));
cl.print(F("<ambient>"));
cl.print(ambientTemp);
cl.print(F("</ambient>"));
cl.print(F("<s4>"));
cl.print(ambientTemp);
cl.print(F("</s4>"));

cl.print(F("<compStat>"));
sprintf(buf, "%s", compStat == OFF ? sOff : sOn);
cl.print(buf);
cl.print(F("</compStat>"));
cl.print(F("<fanLow>"));
sprintf(buf, "%s", fanLow == OFF ? sOff : sOn);
cl.print(buf);
cl.print(F("</fanLow>"));
cl.print(F("<fanHigh>"));
sprintf(buf, "%s", fanHigh == OFF ? sOff : sOn);
cl.print(buf);
cl.print(F("</fanHigh>"));
cl.print(F("<valve>"));
sprintf(buf, "%s", valve == OFF ? sOff : sOn);
cl.print(buf);
cl.print(F("</valve>"));
cl.print(F("<pump>"));
sprintf(buf, "%s", pump == OFF ? sOff : sOn);
cl.print(buf);
cl.print(F("</pump>"));

cl.println(F("</inputs>"));
}


// 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;
}
}

// searches for the string sfind in the string str
// returns 1 if string found
// returns 0 if string not found
char StrContains(char *str, char *sfind)
{
char found = 0;
char index = 0;
char len;

len = strlen(str);

if (strlen(sfind) > len) {
return 0;
}
while (index < len) {
if (str[index] == sfind[found]) {
found++;
if (strlen(sfind) == found) {
return 1;
}
}
else {
found = 0;
}
index++;
}
return 0;
}
Acuario is offline   Reply With Quote