OpenSprinkler › Forums › OpenSprinkler Unified Firmware › api question for disable/enable existing programs
- This topic has 8 replies, 5 voices, and was last updated 8 years, 3 months ago by Ray.
-
AuthorPosts
-
June 24, 2015 at 1:26 pm #38671
FrankParticipantHi,
What are the http commands to disable/enable existing OpenSprinkler programs ? (examples)
Regards, F.
June 24, 2015 at 5:28 pm #38678
SamerKeymasterAugust 25, 2016 at 2:52 am #43902
StrilParticipantHi!
Is the only possibility to disable a program on sending the whole configuration of that program? I could not find a posibility to only disable or re-enable an existing program.
Thank you for your help
Regards,
StrilAugust 25, 2016 at 12:21 pm #43910
RayKeymasterI see what you mean. Unfortunately there is no API currently to only set the disable / enable bit of an existing program — you have to use /cp and pass the entire program data to enable / disable the program.
However, you can modify the firmware by adding an additional API command, say, call it ep to stand for ‘enable program’, and use this command to set the ‘enable / disable’ bit of an existing program. It’s pretty easy to follow the existing code (in server.cpp) to add an additional command.
August 26, 2016 at 1:11 am #43916
StrilParticipantHi!
I wrote a script that:
– Reads the programs
– Changes the “activation-flag”
– Writes the program with the changed flagNow, I can enable/disable the programs via API.
Regards,
StrilAugust 26, 2016 at 10:32 am #43921
cremeikasParticipantI 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
August 29, 2016 at 1:05 am #43944
StrilParticipantHi!
Wow, thats great, to see that feature that fast!
As I am new to Opensprinkler: How can I add that patch to my installation? Is there any “standard-workflow”?
Regards,
StrilAugust 29, 2016 at 9:33 am #43952
cremeikasParticipantNot too sure about that, in it’s current form you’d have to manually add it to the code by hand and recompile. I can help if you run into some problems attempting it
My workflow so far has been almost a complete fork of the project as I’m kind of doing it as a learn experience.
September 12, 2016 at 10:43 am #44036
RayKeymaster@cremeikas: thank you very much for providing the implementation.
@Stril: depending on what version of hardware you have: if you have OSPi, it’s very easy to modify the code, and then just run the ./build.sh to re-compile the firmware after modification.If you have the microcontroller-base OpenSprinkler (either AC or DC version), here are the instructions on how to compile:
https://opensprinkler.freshdesk.com/solution/articles/5000165132-how-to-compile-opensprinkler-firmware
I admit it’s quite technical, but just follow the instructions closely, and you should be able to get it to work. -
AuthorPosts
- You must be logged in to reply to this topic.
OpenSprinkler › Forums › OpenSprinkler Unified Firmware › api question for disable/enable existing programs