def config16(mode): if mode == 'auto': ## read the configuration file myconfs = readconf() ## update the crontable addtocron(myconfs[myconfs.ch == '16'].irow(0),'/home/pi/Sites/WaterMaster0.3/cronlog.txt') ## update the states and the confs states.runmode[states.ch == '16'] = 'auto' confs.mins[confs.ch == '16'] = myconfs.mins[myconfs.ch == '16'].irow(0) confs.hours[confs.ch == '16'] = myconfs.hours[myconfs.ch == '16'].irow(0) confs.on[confs.ch == '16'] = myconfs.on[myconfs.ch == '16'].irow(0) else: removefromcron('16') ##update the states and the confs states.runmode[states.ch == '16'] = 'manual' confs.mins[confs.ch == '16'] = '' confs.hours[confs.ch == '16'] = '' confs.on[confs.ch == '16'] = '' templateData = { 'conf16': confs[confs.ch == '16'].irow(0).to_dict(), 'conf18': confs[confs.ch == '18'].irow(0).to_dict(), 'state16': states[states.ch == '16'].irow(0).to_dict(), 'state18': states[states.ch == '18'].irow(0).to_dict() } return render_template('auto.html', **templateData)
## <--------------------------- The main application ---------------------- > ## If this script was run directly from the command line ## Have the server listen on port 80 and report any errors. if __name__ == "__main__": ## Manage the inputoutput of the board # to use Raspberry Pi board pin numbers GPIO.setmode(GPIO.BOARD) GPIO.setup(16, GPIO.OUT) ## set up GPIO output channel GPIO.output(16,GPIO.LOW) ## Put the ralay1 in off mode GPIO.setup(18, GPIO.OUT) ## set up GPIO output channel GPIO.output(18,GPIO.LOW) ## Put the ralay2 in off mode ## read the watering schedule cfg = readconf() R1prog = 'Start '+cfg['start'][0]+' - On(min): '+str(cfg['on'][0])+' - Cycle(hrs): '+str(cfg['delta'][0]) R2prog = 'Start '+cfg['start'][1]+' - On(min): '+str(cfg['on'][1])+' - Cycle(hrs): '+str(cfg['delta'][1]) ## here we start the multiprocessing engine ## the things we want in the "shared" data space are: ## - the state of the two relays ## - the next scheduled watering for both relays (this will be calculated by the ## watering daemon after each watering cycle) manager = Manager() nextwat1 = manager.Value(ctypes.c_char_p, ' ') nextwat2 = manager.Value(ctypes.c_char_p, ' ') runmode = manager.Array('i',[0,0]) ## runmode 0 will be only manual ... relaystate = manager.Array('i',[0,0]) ## here we run the two watering daemons q = Process(target = autoWaterR1, args=(cfg,nextwat1,relaystate,runmode,))