def log(request, batch_id): batch = Batch.objects.get(id=batch_id) logs = MashLog.objects.filter(batch=batch) if logs.count() > 0: is_started = True first_log = logs[:1].get() last_log = logs.latest('id') seconds_running = last_log.created - first_log.created seconds_running = seconds_running.seconds else: is_started = False seconds_running = None if get_variable('active_mashingprocess_batch_id', 'None') == str(batch.id): mashing_process_is_running = True else: mashing_process_is_running = False return render_to_response('mashing.html',{ 'batch' : batch, 'is_started': is_started, 'is_running': mashing_process_is_running, 'seconds_running': seconds_running }, context_instance=RequestContext(request))
def init_mashing(batch): # (Re)set defaults for batch set_batch_defaults(batch) set_variable('active_mashingprocess_batch_id', str(batch.id)) # Initialize Arduino with Nanpy if not settings.ARDUINO_SIMULATION: sensor = DallasTemperature(ARDUINO_TEMPERATURE_PIN) addr = sensor.getAddress(ARDUINO_TEMPERATURE_PIN) Arduino.pinMode(ARDUINO_HEAT_PIN, Arduino.OUTPUT) Arduino.pinMode(ARDUINO_COOL_PIN, Arduino.OUTPUT) Arduino.pinMode(ARDUINO_STATUS_PIN, Arduino.OUTPUT) Arduino.digitalWrite(ARDUINO_HEAT_PIN, Arduino.LOW) Arduino.digitalWrite(ARDUINO_COOL_PIN, Arduino.LOW) Arduino.digitalWrite(ARDUINO_STATUS_PIN, Arduino.HIGH) else: # Set initial dummy temperature batch.temperature = 20 # Testing purpose only batch.save() batch = Batch.objects.get(id=batch.id) # Run Mashing proces while get_variable('active_mashingprocess_batch_id', 'None') == str(batch.id): # Measure data measured_data = {} if settings.ARDUINO_SIMULATION: measured_data['temp'] = get_dummy_temperature(batch) else: sensor.requestTemperatures() measured_data['temp'] = sensor.getTempC(addr) # Define actions depending on measured data batch = process_measured_data(batch.id, measured_data) # Send updates to arduino if not settings.ARDUINO_SIMULATION: send_updates_to_arduino(batch) # Send to logging department handle_logging(batch) # Delay sleep(DELAY_BETWEEN_MEASUREMENTS) Arduino.digitalWrite(ARDUINO_STATUS_PIN, Arduino.LOW) Arduino.digitalWrite(ARDUINO_COOL_PIN, Arduino.LOW) Arduino.digitalWrite(ARDUINO_HEAT_PIN, Arduino.LOW) return 'Mashing proces ended'