OpenSprinkler Forums OpenSprinkler Unified Firmware api question for disable/enable existing programs

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #38671

    Frank
    Participant

    Hi,

    What are the http commands to disable/enable existing OpenSprinkler programs ? (examples)

    Regards, F.

    #38678

    Samer
    Keymaster
    #43902

    Stril
    Participant

    Hi!

    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,
    Stril

    #43910

    Ray
    Keymaster

    I 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.

    #43916

    Stril
    Participant

    Hi!

    I wrote a script that:
    – Reads the programs
    – Changes the “activation-flag”
    – Writes the program with the changed flag

    Now, I can enable/disable the programs via API.

    Regards,
    Stril

    #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

    #43944

    Stril
    Participant

    Hi!

    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,
    Stril

    #43952

    cremeikas
    Participant

    Not 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.

    #44036

    Ray
    Keymaster

    @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.

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.

OpenSprinkler Forums OpenSprinkler Unified Firmware api question for disable/enable existing programs