Thanks for the pointers.
here my solution (just that section)works but not as elegant…
int theCount =0;
server.print("{");
while (server.readPOSTparam(name, NAMELEN, value, VALUELEN)){
theCount +=1;
failedCMD=true;
itoa(theCount,theCountChar,10);
if (theCount >1) strcpy(theString,",\"");
else strcpy(theString,"\"");
strcat(theString,theCountChar);
strcat(theString,"\":{");
char *theComma = strchr(value,',');
if (theComma == NULL) {
strcat(theString,"\"badinput\":\"");
strcat(theString,name);
strcat(theString,value);
strcat(theString,"\"}");
server.print(theString);
}
else {
strcat(theString,"\"type\":\"");
if (value[0] == 'D') {
isDigital = true;
strcat(theString,"D");
}
else {
isDigital = false;
strcat(theString,"A");
}
strcat(theString,"\",\"cmd\":\"");
strcat(theString,name);
strcat(theString,"\"");
strncpy(pinNum,value+1,(int)(theComma-value-1));
strncpy(pinName,value,2);
strcpy(pinValue,theComma+1);
pinNumber = atoi(pinNum);
pinValueInt = atoi(pinValue);
strcat(theString,",\"pin\":\"");
strcat(theString,pinName);
strcat(theString,"\"");
if (strcmp( name, commandRead ) == 0 ){
if (isDigital) valRead = digitalRead(pinNumber) ;
else valRead = analogRead(pinNumber+10);
itoa(valRead,valReadChar,10);
strcat(theString,",\"value\":\"");
strcat(theString,valReadChar);
strcat(theString,"\"");
failedCMD = false;
}
if (strcmp( name, commandWrite ) == 0 ){
if (isDigital) digitalWrite(pinNumber, pinValueInt);
else analogWrite(pinNumber+10, pinValueInt);
failedCMD = false;
}
if (strcmp( name, commandSet ) == 0 ){
if (strcmp(pinValue,modeINPUT)==0){
if (isDigital) pinMode(pinNumber, INPUT);
else pinMode(pinNumber+10, INPUT);
failedCMD = false;
}
if (strcmp(pinValue,modeOUTPUT)==0){
if (isDigital) pinMode(pinNumber, OUTPUT);
else pinMode(pinNumber+10, OUTPUT);
failedCMD = false;
}
}
}
if (failedCMD) strcat(theString,",\"status\":\"failed");
else strcat(theString,",\"status\":\"OK");
strcat(theString,"\"}");
Serial.println(theString);
server.print(theString);
}
server.print("}");
and with curl -d “READ=A1,1” --max-time 5 "http://192.168.x.y/parsed.html"
and produces
{“1”:{“type”:“A”,“cmd”:“READ”,“pin”:“A1”,“value”:“4090”,“status”:“OK”}}
http return
that all works fine … but just for 30 minutes than the web server stop responding
the loop is still running.
I can reproduce that if the wifi connection gets lost() web server immediately stops and does not come back.
( )e.g.: stop wifi on router and restart wifi
Is there a way to restart the server
thx so much for your help.
everything works but its not stable!!
KW