Hi,
I use a scheduller - say turn on device at 1pm to 2pm is there anyway to 'interupt' that and change via code at all?
Hey Andrew,
you can edit the schedule.wpi and then run runScript.sh to update the schedule.
I do check the config for changes and update this from Phyton with the following code:
import os import subprocess import log def loadWPI(file): if not os.path.isfile(file): log.warning("WPI File not Found: " + file) return False with open(file, 'r') as f: content = f.read() return content def schedule(conf): wpi = loadWPI('wittypi/schedule.wpi') if conf.witty: if not conf.witty.schedule and wpi: os.remove('wittypi/schedule.wpi') elif conf.witty.schedule and conf.witty.schedule != wpi: with open('wittypi/schedule.wpi', 'w', encoding='utf-8') as f: f.writelines(conf.witty.schedule) log.info("schedule.wpi updated.") else: return witty_runScript() elif not conf.witty and wpi: os.remove('wittypi/schedule.wpi') log.info("schedule.wpi removed.") witty_runScript() def witty_runScript(): env = os.environ.copy() env['PATH'] = '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' env['SHELL'] = '/bin/bash' subprocess.Popen("bash " + "wittypi/runScript.sh", shell=True, stdin=False, stdout=False, stderr=False, env=env)
Just make sure to run runScript.sh in bash!
I noticed, is not really interrupting the schedule, as scheduled startup/shutdown are not reset after deleting the schedule.wpi.
To solve it I've opened a Pull-Request for the wittyPi Software to introduce a RESET keyword. So putting RESET in the schedule.wpi, it unsets the timers too.
You could actually use it already by changing the files according to my pull-request (runScript.sh, utilities.sh, wittyPi.sh).
With this change my resulting python code looks like this:
import os import subprocess import log def loadWPI(file): if not os.path.isfile(file): log.warning("WPI File not Found: " + file) return False with open(file, 'r') as f: content = f.read() return content def schedule(conf): wpi = loadWPI('wittypi/schedule.wpi') if conf.witty: if not conf.witty.schedule and wpi: with open('wittypi/schedule.wpi', 'w', encoding='utf-8') as f: f.writelines("RESET") log.info("schedule.wpi RESET.") elif conf.witty.schedule and conf.witty.schedule != wpi: with open('wittypi/schedule.wpi', 'w', encoding='utf-8') as f: f.writelines(conf.witty.schedule) log.info("schedule.wpi updated.") else: return witty_runScript() elif not conf.witty and wpi: with open('wittypi/schedule.wpi', 'w', encoding='utf-8') as f: f.writelines("RESET") log.info("schedule.wpi RESET.") witty_runScript() def witty_runScript(): env = os.environ.copy() env['PATH'] = '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' env['SHELL'] = '/bin/bash' subprocess.Popen("bash " + "wittypi/runScript.sh", shell=True, stdin=False, stdout=False, stderr=False, env=env)
Hi
Sorry for the late reply was away and could not contact you.
Thanks for the scripts.
Not sure if this will help me?I will try and explain better 🙂
Suppose I set a schdeuler to run once a day for an hour. But, for some reason I want to cancel this. My user will not have access to manually do anything. Their only interface is on a web page that I have provided them access to. this web page is a web server running on the Rpi. But it seems to me the only way they can cancel or amend the scheduler is to wait until the RPi starts on the hour of that day and press 'cancel scheduler' on my web app.
Is that correct?
Thanks
@andrew-simpson17 it is correct, unless you have implemented another approach to force Witty Pi to wake up the Pi immediately.
Working Sunday? Impressed 🙂
OK, it is what I thought. Thanks