Skip to content

Commit

Permalink
Merge branch 'feature/addTimer' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
William Schmitt authored and William Schmitt committed Jun 8, 2016
2 parents df7b467 + 7c4766e commit 0f475c1
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 16 deletions.
53 changes: 38 additions & 15 deletions brewery/brewing/brewery.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand All @@ -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)
Expand Down Expand Up @@ -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):
Expand All @@ -137,6 +130,8 @@ def statePrestart(breweryInstance):
'''
logger.debug('In statePrestart')

breweryInstance.timer = None

breweryInstance.mainPump.turnOff()
breweryInstance.boilKettle.turnOff()
breweryInstance.mashTun.turnOff()
Expand All @@ -153,6 +148,8 @@ def statePremash(breweryInstance):
'''
logger.debug('In statePremash')

breweryInstance.timer = None

breweryInstance.mainPump.turnOff()
breweryInstance.boilKettle.turnOn()
breweryInstance.mashTun.turnOff()
Expand All @@ -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()
Expand All @@ -189,6 +189,8 @@ def statePostStrike(breweryInstance):
'''
logger.debug('In statePostStrike')

breweryInstance.timer = None

breweryInstance.mainPump.turnOff()
breweryInstance.boilKettle.turnOn()
breweryInstance.mashTun.turnOff()
Expand All @@ -209,14 +211,16 @@ 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()

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):
Expand All @@ -226,6 +230,8 @@ def stateMashout(breweryInstance):
'''
logger.debug('In stateMashout')

breweryInstance.timer = None

breweryInstance.mainPump.turnOn()
breweryInstance.boilKettle.turnOn()
breweryInstance.mashTun.turnOn()
Expand All @@ -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')
Expand All @@ -262,6 +269,8 @@ def stateSpargePrep(breweryInstance):
'''
logger.debug('In stateSpargePrep')

breweryInstance.timer = None

breweryInstance.mainPump.turnOff()
breweryInstance.boilKettle.turnOff()
breweryInstance.mashTun.turnOff()
Expand All @@ -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')
Expand All @@ -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')
Expand All @@ -313,6 +326,8 @@ def stateMashToBoil(breweryInstance):
'''
logger.debug('In stateMashToBoil')

breweryInstance.timer = None

breweryInstance.mainPump.turnOn()
breweryInstance.boilKettle.turnOff()
breweryInstance.mashTun.turnOff()
Expand All @@ -330,6 +345,8 @@ def stateBoilPreheat(breweryInstance):
'''
logger.debug('In stateBoilPreheat')

breweryInstance.timer = None

breweryInstance.mainPump.turnOff()
breweryInstance.boilKettle.turnOn()
breweryInstance.mashTun.turnOff()
Expand All @@ -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')
Expand All @@ -366,6 +385,8 @@ def stateCool(breweryInstance):
'''
logger.debug('In stateCool')

breweryInstance.timer = None

breweryInstance.mainPump.turnOff()
breweryInstance.boilKettle.turnOff()
breweryInstance.mashTun.turnOff()
Expand All @@ -383,6 +404,8 @@ def statePumpout(breweryInstance):
'''
logger.debug('In statePumpout')

breweryInstance.timer = None

breweryInstance.mainPump.turnOn()
breweryInstance.boilKettle.turnOff()
breweryInstance.mashTun.turnOff()
Expand Down
4 changes: 3 additions & 1 deletion utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 0f475c1

Please sign in to comment.