Ejemplo n.º 1
0
 def post(self, request, format=None):
     log.info("User requested that we stop the current program")
     api_interface = APIInterface()
     # Turn off the heater
     api_interface.deactivate()
     # Delete the program and driver from Redis so that the backend realizes we're done
     api_interface.clear()
     log.info("Program stopped successfully")
     return Response(status=status.HTTP_200_OK)
Ejemplo n.º 2
0
 def get(self, request, format=None):
     api_interface = APIInterface()
     out = {
         "step": api_interface.current_step,
         "temp": api_interface.current_temp,
         "target": api_interface.target_temp,
         "step_time_remaining": api_interface.step_time_remaining,
         "program_time_remaining": api_interface.program_time_remaining,
         "program": api_interface.program
     }
     return Response(out, status=status.HTTP_200_OK)
Ejemplo n.º 3
0
 def post(self, request, format=None):
     api_interface = APIInterface()
     try:
         # look up the driver and program in the database
         driver = models.Driver.objects.get(id=request.data['driver'])
         program = models.Program.objects.get(id=request.data['program'])
         log.info(
             "Received request to start program: ID: {id}, NAME: {name}".
             format(id=program.id, name=program.name))
         # convert to JSON, which our Python backend is expecting
         json_driver = serializers.DriverSerializer(driver)
         json_program = serializers.ProgramSerializer(program)
         # update the selected driver and program in Redis, so that our backend can know which ones to use
         api_interface.driver = json_driver.data
         api_interface.program = json_program.data['steps']
         log.info("Program steps: {steps}".format(
             steps=str(json_program.data['steps'])))
     except Exception as e:
         log.exception("Could not start program")
         return Response(status=status.HTTP_400_BAD_REQUEST,
                         data={"error": e.message})
     else:
         # Flip the switch and the backend will start running the program once it detects the change (usually within a second)
         api_interface.activate()
     log.info("Program started.")
     return Response(status=status.HTTP_200_OK)
Ejemplo n.º 4
0
 def post(self, request, format=None):
     api_interface = APIInterface()
     try:
         # look up the driver and program in the database
         driver = models.Driver.objects.get(id=request.data['driver'])
         program = models.Program.objects.get(id=request.data['program'])
         log.info("Received request to start program: ID: {id}, NAME: {name}".format(id=program.id, name=program.name))
         # convert to JSON, which our Python backend is expecting
         json_driver = serializers.DriverSerializer(driver)
         json_program = serializers.ProgramSerializer(program)
         # update the selected driver and program in Redis, so that our backend can know which ones to use
         api_interface.driver = json_driver.data
         api_interface.program = json_program.data['steps']
         log.info("Program steps: {steps}".format(steps=str(json_program.data['steps'])))
     except Exception as e:
         log.exception("Could not start program")
         return Response(status=status.HTTP_400_BAD_REQUEST, data={"error": e.message})
     else:
         # Flip the switch and the backend will start running the program once it detects the change (usually within a second)
         api_interface.activate()
     log.info("Program started.")
     return Response(status=status.HTTP_200_OK)
Ejemplo n.º 5
0
 def post(self, request, format=None):
     log.info("User requested that we stop the current program")
     api_interface = APIInterface()
     # Turn off the heater
     api_interface.deactivate()
     # Delete the program and driver from Redis so that the backend realizes we're done
     api_interface.clear()
     log.info("Program stopped successfully")
     return Response(status=status.HTTP_200_OK)
Ejemplo n.º 6
0
from device import heater
from interface import APIInterface
from device import thermometer
import Adafruit_MAX31855.MAX31855 as MAX31855
import RPi.GPIO as GPIO

# Disable the temperature probe logger because it produces annoying and useless messages
maxlog = logging.getLogger('Adafruit_MAX31855.MAX31855')
maxlog.disabled = True

# Set up a logger for application notifications and errors
log = logging.getLogger("heater")

# We use rotating log files so that if there is a crash mid-run, we will lose the least amount possible.
# 5120 bytes is around 50 lines of log messages
handler = RotatingFileHandler('/var/log/piwarmer/heater.log',
                              maxBytes=5120,
                              backupCount=10000)
formatter = logging.Formatter(
    '%(asctime)s\t%(name)s\t%(levelname)s\t\t%(message)s')
handler.setFormatter(formatter)
log.addHandler(handler)
log.setLevel(logging.DEBUG)

if __name__ == "__main__":
    api_interface = APIInterface()
    thermometer = thermometer.Thermometer(MAX31855.MAX31855(24, 23, 18))
    heater = heater.Heater(GPIO)
    with ProgramRunner(api_interface, thermometer, heater) as program:
        program.run()
Ejemplo n.º 7
0
 def post(self, request, format=None):
     api_interface = APIInterface()
     api_interface.skip_step()
     log.info("User skipped a step")
     return Response(status=status.HTTP_200_OK)
Ejemplo n.º 8
0
 def post(self, request, format=None):
     api_interface = APIInterface()
     api_interface.skip_step()
     log.info("User skipped a step")
     return Response(status=status.HTTP_200_OK)