diff --git a/brewery/brewing/brewery.py b/brewery/brewing/brewery.py index 9c5f7bf..78156b8 100644 --- a/brewery/brewing/brewery.py +++ b/brewery/brewing/brewery.py @@ -40,6 +40,7 @@ def __init__(self): self.dataStreamer.register('systemEnergy') self.dataStreamer.register('systemEnergyCost') self.dataStreamer.register('state__id','state') + self.dataStreamer.register('timer') #state machine initialization self.state = stateMachine(self) @@ -68,8 +69,8 @@ def __init__(self): self.boilTemperature = 217. self.coolTemperature = 70. self.mashTemperatureProfile = [ - [0.0, 152.0], #start at 152 - [45.0,155.0], #at 45min step up to 155 + [45.*60., 152.0], #start at 152 + [15.*60.,155.0], #at 45min step up to 155 ] self.systemEnergy = 0. @@ -87,6 +88,7 @@ def __init__(self): #schedule task 1 execution self.tm1Rate = 1. #seconds self.tm1_tz1 = time.time() + self.timer = None self.task00() a = ioloop.PeriodicCallback(self.task00,self.tm1Rate*1000) @@ -119,15 +121,6 @@ def task00(self): #schedule next task 1 event self.tm1_tz1 = self.wtime -# self.scheduler.enter(self.tm1Rate, 1, self.task00, ()) - -# @gen.coroutine -# def connect(self): -# logger.debug('lets try {}'.format("ws:" + host + "/live/timeseries/socket/")) -# self.conn = yield websocket_connect("ws:" + host + "/live/timeseries/socket/") -# logger.debug('here {}'.format(self.conn)) -# print('bs') -# self.conn.write_message({'subscribe':True}) def statePrestart(breweryInstance): @@ -137,6 +130,8 @@ def statePrestart(breweryInstance): ''' logger.debug('In statePrestart') + breweryInstance.timer = None + breweryInstance.mainPump.turnOff() breweryInstance.boilKettle.turnOff() breweryInstance.mashTun.turnOff() @@ -153,6 +148,8 @@ def statePremash(breweryInstance): ''' logger.debug('In statePremash') + breweryInstance.timer = None + breweryInstance.mainPump.turnOff() breweryInstance.boilKettle.turnOn() breweryInstance.mashTun.turnOff() @@ -170,6 +167,9 @@ def statePremash(breweryInstance): def stateStrike(breweryInstance): logger.debug('In stateStrike') + breweryInstance.timer = None + + breweryInstance.mainPump.turnOn() breweryInstance.boilKettle.turnOn() breweryInstance.mashTun.turnOff() @@ -189,6 +189,8 @@ def statePostStrike(breweryInstance): ''' logger.debug('In statePostStrike') + breweryInstance.timer = None + breweryInstance.mainPump.turnOff() breweryInstance.boilKettle.turnOn() breweryInstance.mashTun.turnOff() @@ -209,6 +211,8 @@ def stateMash(breweryInstance): ''' logger.debug('In stateMash') + breweryInstance.timer = (breweryInstance.state_t0 + breweryInstance.mashTun.temperature_profile_length) - breweryInstance.wtime + breweryInstance.mainPump.turnOn() breweryInstance.boilKettle.turnOn() breweryInstance.mashTun.turnOn() @@ -216,7 +220,7 @@ def stateMash(breweryInstance): breweryInstance.mashTun.setTemperatureProfile(breweryInstance.state_t0) breweryInstance.timeT0 = time.time() - if breweryInstance.wtime > breweryInstance.timeT0 + breweryInstance.mashTun.temperature_profile_length: + if breweryInstance.timer <= 0.: breweryInstance.state.changeState('stateMashout') def stateMashout(breweryInstance): @@ -226,6 +230,8 @@ def stateMashout(breweryInstance): ''' logger.debug('In stateMashout') + breweryInstance.timer = None + breweryInstance.mainPump.turnOn() breweryInstance.boilKettle.turnOn() breweryInstance.mashTun.turnOn() @@ -245,13 +251,14 @@ def stateMashout2(breweryInstance): ''' logger.debug('In stateMashout2') + breweryInstance.timer = (breweryInstance.state_t0 + breweryInstance.mashoutTime) - breweryInstance.wtime + breweryInstance.mainPump.turnOn() breweryInstance.boilKettle.turnOn() breweryInstance.mashTun.turnOff() breweryInstance.mashTun.setTemperature(breweryInstance.mashoutTemperature) - breweryInstance.timeT0 = time.time() - if breweryInstance.wtime > breweryInstance.timeT0 + breweryInstance.mashoutTime: + if breweryInstance.timer <= 0.: if breweryInstance.grantPermission: breweryInstance.grantPermission = False breweryInstance.state.changeState('stateSpargePrep') @@ -262,6 +269,8 @@ def stateSpargePrep(breweryInstance): ''' logger.debug('In stateSpargePrep') + breweryInstance.timer = None + breweryInstance.mainPump.turnOff() breweryInstance.boilKettle.turnOff() breweryInstance.mashTun.turnOff() @@ -283,6 +292,8 @@ def stateSparge(breweryInstance): breweryInstance.boilKettle.turnOff() breweryInstance.mashTun.turnOff() + breweryInstance.timer = None + if breweryInstance.grantPermission: breweryInstance.grantPermission = False breweryInstance.state.changeState('statePreBoil') @@ -300,6 +311,8 @@ def statePreBoil(breweryInstance): breweryInstance.boilKettle.turnOff() breweryInstance.mashTun.turnOff() + breweryInstance.timer = None + if breweryInstance.grantPermission: breweryInstance.grantPermission = False breweryInstance.state.changeState('stateMashToBoil') @@ -313,6 +326,8 @@ def stateMashToBoil(breweryInstance): ''' logger.debug('In stateMashToBoil') + breweryInstance.timer = None + breweryInstance.mainPump.turnOn() breweryInstance.boilKettle.turnOff() breweryInstance.mashTun.turnOff() @@ -330,6 +345,8 @@ def stateBoilPreheat(breweryInstance): ''' logger.debug('In stateBoilPreheat') + breweryInstance.timer = None + breweryInstance.mainPump.turnOff() breweryInstance.boilKettle.turnOn() breweryInstance.mashTun.turnOff() @@ -349,11 +366,13 @@ def stateBoil(breweryInstance): breweryInstance.mainPump.turnOff() breweryInstance.boilKettle.turnOn() breweryInstance.mashTun.turnOff() + + breweryInstance.timer = (breweryInstance.state_t0 + breweryInstance.BOILTIME) - breweryInstance.wtime breweryInstance.boilKettle.setTemperature(breweryInstance.boilTemperature) breweryInstance.timeT0 = time.time() - if breweryInstance.wtime > breweryInstance.timeT0 + breweryInstance.BOILTIME: + if breweryInstance.timer <= 0.: if breweryInstance.grantPermission: breweryInstance.grantPermission = False breweryInstance.state.changeState('stateCool') @@ -366,6 +385,8 @@ def stateCool(breweryInstance): ''' logger.debug('In stateCool') + breweryInstance.timer = None + breweryInstance.mainPump.turnOff() breweryInstance.boilKettle.turnOff() breweryInstance.mashTun.turnOff() @@ -383,6 +404,8 @@ def statePumpout(breweryInstance): ''' logger.debug('In statePumpout') + breweryInstance.timer = None + breweryInstance.mainPump.turnOn() breweryInstance.boilKettle.turnOff() breweryInstance.mashTun.turnOff() diff --git a/utils.py b/utils.py index 41d2e4a..a106f8a 100644 --- a/utils.py +++ b/utils.py @@ -172,9 +172,11 @@ def postData(self): #send the data try: + value = rgetattr(self.streamingClass,sensor['attr']) r = requests.post(self.dataPostService, data={'time':sampleTime,'recipe_instance':self.recipeInstance, - 'value':rgetattr(self.streamingClass,sensor['attr']),'sensor':sensor['id'] + 'value': value if value is not None else 0., #TODO: make server accept None + 'sensor':sensor['id'] } ) r.raise_for_status()