Exemplo n.º 1
0
def handle_control():
    wsock = get_websocket_from_request()
    log.info("websocket (control) opened")
    while True:
        try:
            message = wsock.receive()
            log.info(f"Received (control): {message:s}")
            msgdict = json.loads(message)
            if msgdict.get("cmd") == "RUN":
                log.info("RUN command received")
                profile_obj = msgdict.get('profile')
                if profile_obj:
                    profile_json = json.dumps(profile_obj)
                    profile = Profile(profile_json)
                oven.run_profile(profile)
                ovenWatcher.record(profile)
            elif msgdict.get("cmd") == "SIMULATE":
                log.info("SIMULATE command received")
                profile_obj = msgdict.get('profile')
                if profile_obj:
                    profile_json = json.dumps(profile_obj)
                    profile = Profile(profile_json)
                simulated_oven = Oven(simulate=True, time_step=0.05)
                simulation_watcher = OvenWatcher(simulated_oven)
                simulation_watcher.add_observer(wsock)
                simulated_oven.run_profile(profile)
                simulation_watcher.record(profile)
            elif msgdict.get("cmd") == "STOP":
                log.info("Stop command received")
                oven.abort_run()
        except WebSocketError:
            break
    log.info("websocket (control) closed")
Exemplo n.º 2
0
    exit(1)

logging.basicConfig(level=config.log_level, format=config.log_format)
log = logging.getLogger("kiln-controller")
log.info("Starting kiln controller")

script_dir = os.path.dirname(os.path.realpath(__file__))
sys.path.insert(0, script_dir + '/lib/')
profile_path = os.path.join(script_dir, "storage", "profiles")

from oven import Oven
from profile import Profile
from ovenWatcher import OvenWatcher

app = bottle.Bottle()
oven = Oven()
ovenWatcher = OvenWatcher(oven)

@app.route('/')
def index():
    return bottle.redirect('/picoreflow/index.html')

@app.post('/api')
def handle_api():
    log.info("/api is alive")
    log.info("bottle request")
    log.info(bottle.request.json)

    # run a kiln schedule
    if bottle.request.json['cmd'] == 'run':
        wanted = bottle.request.json['profile']
Exemplo n.º 3
0
from TV import TV
from heater import Heater
from oven import Oven


class Kitchen():
    def __init__(self, size):
        self.size = size
        self.tv = None
        self.heater = None
        self.oven = None


jakub_tv = TV(40, 50, True)
jakub_heater = Heater("small", "1.6kw")
jakub_oven = Oven(150, 200, 56, "electronic", "black")

jakub_kitchen = Kitchen("large")

jakub_kitchen.tv = jakub_tv
jakub_kitchen.heater = jakub_heater

print(jakub_kitchen.tv)
print(jakub_heater)
print(jakub_oven)