Beispiel #1
0
class LightSensorController:

    GPIO_PIN = 7

    def __init__(self):
        self._log = Logger()
        self._GPIOController = GPIOController()

    def dispose(self):
        self._log.info("Disposing GPIOController...")
        self._GPIOController.cleanUp()

    def getLightLevel(self):
        lightLevel = GPIOController.readFromGPIO(self.GPIO_PIN)
        self._log.info("Lightlevel " + str(lightLevel))
        return lightLevel
def main():
    l = Logger(CFG_LOGS_DIR, CFG_LOGS_DAYS_ARCHIVE_SIZE)
    l.makeGlobal()
    l.instance.log("Starting program.")
    l.instance.log(
        "Config is: ID={0} HTTPPORT={1} UDPPORT={2} NAME={3} DEFTIME={4}".
        format(CFG_ROOM_UNIQUE_ID, CFG_HTTP_SERVER_PORT,
               CFG_UDP_DETECT_BROADCAST_PORT, CFG_ROOM_NAME, CFG_DEFAULT_TIME))
    roomname = CFG_ROOM_NAME
    roomController = MainRoomController()
    gpio = GPIOController(roomController)
    dsp = None
    try:
        i2c = busio.I2C(board.SCL, board.SDA, frequency=100000)
        dsp = AF_HT16K33_7Seg(i2c)
    except:
        print("FAILED TO LOAD I2C DISPLAY! LOADING DEBUG CONSOLE DISPLAY!")
        print("FAILED TO LOAD I2C DISPLAY! LOADING DEBUG CONSOLE DISPLAY!")
        print("FAILED TO LOAD I2C DISPLAY! LOADING DEBUG CONSOLE DISPLAY!")
        l.instance.log("ERROR: I2C display failed to initalize")
        dsp = CommandLineDisplay()
        roomname += "[!]"
    tmr = UnthreadedTimer(roomController)
    tmr.appendTickListener(dsp)
    tmr.setSeconds(CFG_DEFAULT_TIME)
    server = TimerServer(tmr, CFG_ROOM_UNIQUE_ID, roomname,
                         CFG_HTTP_SEVER_HOST, CFG_HTTP_SERVER_PORT,
                         CFG_UDP_DETECT_BROADCAST_PORT, roomController)
    roomController.initialize(server, tmr, gpio)
    server.broadcastSelf()
    server.startThreaded()
    while (True):
        tmr.onUpdate()
Beispiel #3
0
def handle(ws):
    while True:
        m = ws.wait()
        if m is None:
            log.debug("WebSocket client is disconected!")
            break
        #log.debug(m)
        jsonReq = json.loads(m)
        request = jsonReq[REQUEST]
        if request == GET_GPIO_STATE:
            response = GPIOController.getInstance().getGpioState()
            sendToWs(ws, response)
        elif request == CHANGE_GPIO_STATE:
            name = jsonReq[NAME]
            response = GPIOController.getInstance().changePinState(name)
            sendToWs(ws, response)
        elif request == CHANGE_BMZ:
            bmzNum = jsonReq[BMZ_NUMBER]
            response = GPIOController.getInstance().changeBmz(bmzNum)
            sendToWs(ws, response)
Beispiel #4
0
    def __runHandlers(self):
        gpioController = GPIOController.getInstance()
        gpioController.setName('controller')

        self.__httpIndexHandler = HttpRequestHandler()
        self.__httpIndexHandler.setName('index handler')
        self.__webSocketHandler = WebSocketHandler()
        self.__webSocketHandler.setName('websocket handler')

        gpioController.start()
        self.__httpIndexHandler.start()
        self.__webSocketHandler.start()

        gpioController.join()
        self.__httpIndexHandler.join()
        self.__webSocketHandler.join()
Beispiel #5
0
 def __init__(self):
     self._log = Logger()
     self._GPIOController = GPIOController()
Beispiel #6
0
 def getLightLevel(self):
     lightLevel = GPIOController.readFromGPIO(self.GPIO_PIN)
     self._log.info("Lightlevel " + str(lightLevel))
     return lightLevel
Beispiel #7
0
from flask import Flask, render_template, request
import json
from GPIOController import GPIOController

app = Flask(__name__)
gpio_handler = GPIOController()


@app.route('/')
def homepage():
    automaton_state = gpio_handler.read_input()
    return render_template('homepage.html', automaton_state=automaton_state)


@app.route('/api', methods=['POST'])
def control_feed_automaton():
    if request.method == "POST":
        data = request.get_json()
    gpio_handler.set_output(data['value'])
    return json.dumps({'success': True}), 200, {
        'ContentType': 'application/json'
    }


if __name__ == '__main__':
    app.debug = True
    try:
        app.run(host='0.0.0.0', port=5005)
    except KeyboardInterrupt:
        print('exit')
    finally: