OpenSprinkler › Forums › OpenSprinkler Unified Firmware › api question for disable/enable existing programs › Reply To: api question for disable/enable existing programs
August 26, 2016 at 10:32 am
#43921
cremeikas
Participant
I took Rays advice and extended the API to do this if you are interested Stril
/**
* Enable or Disable a program
* Command: /ep?pw=xxx&pid=x&en=x
*
* pw: password
* pid: program index
* en: 0 for disabled, 1 for enable
*/
byte server_enable_program(char *p) {
byte i;
ProgramStruct prog;
// parse program index
if (!findKeyVal(p, tmp_buffer, TMP_BUFFER_SIZE, PSTR("pid"), true)) {
return HTML_DATA_MISSING;
}
int pid=atoi(tmp_buffer);
if (!(pid>=-1 && pid< pd.nprograms)) return HTML_DATA_OUTOFBOUND;
// Read the program
pd.read(pid,&prog);
// read the enable bit
byte en=0;
if (findKeyVal(p, tmp_buffer, TMP_BUFFER_SIZE, PSTR("en"), true)) {
en=atoi(tmp_buffer);
} else {
return HTML_DATA_MISSING;
}
// Set enabled
prog.enabled = en;
// Write it back in
if(!pd.modify(pid, &prog))
return HTML_DATA_OUTOFBOUND;
return HTML_SUCCESS;
}
I’ve only tested it in the demo mode, but in theory I think that is correct. Or at least a starting point if someone else has use for it.
Edit: Also don’t forget to add the ‘ep’ command to the urls / _url_keys structure at the bottom of server.cpp