Esempio n. 1
0
    serial_port = serial_port

    def __init__(self, *args, **kwargs):
        super(ArduinoNameSpace, self).__init__(*args, **kwargs)

    def on_beep(self, *args):
        print '[BEEP]'
        self.serial_port.write(BEEP)


if __name__ == '__main__':
    socket_host = 'localhost'
    if len(sys.argv) > 1:
        socket_host = sys.argv[1]
    print 'Creating socket with:', socket_host
    socket = SocketIO(socket_host, 8002, Namespace=ArduinoNameSpace)
    while 1:
        serial_input = serial_port.readline().replace('\r\n', '').split(':')
        print serial_input
        if not serial_input:
            continue
        event_type = serial_input[0]
        if event_type == 'BUTTON':
            socket.emit('buttonPush', {})
        elif event_type == 'POTENTIOMETER':
            socket.emit('potentiometerChanged', {'value': serial_input[1]})
        elif event_type == 'LIGHT_SENSOR':
            socket.emit('lightSensorChanged', {'value': serial_input[1]})
    socket.close()
Esempio n. 2
0
    
    serial_port = serial_port

    def __init__(self, *args, **kwargs):
        super(ArduinoNameSpace, self).__init__(*args, **kwargs)

    def on_beep(self, *args):
        print '[BEEP]'
        self.serial_port.write(BEEP)


if __name__ == '__main__':
    socket_host = 'localhost';
    if len(sys.argv) > 1:
        socket_host = sys.argv[1]
    print 'Creating socket with:', socket_host
    socket = SocketIO(socket_host, 8002, Namespace=ArduinoNameSpace)
    while 1:
        serial_input = serial_port.readline().replace('\r\n', '').split(':')
        print serial_input
        if not serial_input:
            continue
        event_type = serial_input[0]
        if event_type == 'BUTTON':
            socket.emit('buttonPush', {})
        elif event_type == 'POTENTIOMETER':
            socket.emit('potentiometerChanged', {'value': serial_input[1]})
        elif event_type == 'LIGHT_SENSOR':
            socket.emit('lightSensorChanged', {'value': serial_input[1]})
    socket.close()