Exemplo n.º 1
0
def run_server():
    # Create a thing that represents a humidity sensor
    # tempsensor1 = FakeTempSensor("A1")
    # humidsensor1 = FakeHumidSensor("A1")
    # tempsensor2 = FakeTempSensor("A2")
    # humidsensor2 = FakeHumidSensor("A2")
    tempsensor10 = FakeTempSensor("A10")
    humidsensor10 = FakeHumidSensor("A10")

    # If adding more than one thing, use MultipleThings() with a name.
    # In the single thing case, the thing's name will be broadcast.
    server = WebThingServer(MultipleThings([tempsensor10, humidsensor10],
                                           'TempandHumidDevice'),
                            port=8888)
    try:
        logging.info('starting the server')
        server.start()
    except KeyboardInterrupt:
        logging.debug('canceling the sensor update looping task')
        # tempsensor1.cancel_update_level_task()
        # humidsensor1.cancel_update_level_task()
        # tempsensor2.cancel_update_level_task()
        # humidsensor2.cancel_update_level_task()
        tempsensor10.cancel_update_level_task()
        humidsensor10.cancel_update_level_task()
        logging.info('stopping the server')
        server.stop()
        logging.info('done')
 def start(self, devices):
     print("Initliazing and Starting Server")
     self.server = WebThingServer(MultipleThings(devices, 'UnityDevices'), port=8888)
     self.x = threading.Thread(target=self.server.start)
     self.x.daemon = True
     self.x.start()
     self.started = True
Exemplo n.º 3
0
def run_server():
    location = 'og-vorraum'
    w1_device_id_list = get_w1_devices()
    main_loop = tornado.ioloop.IOLoop.current()
    node_functions = VorraumNode(location, w1_device_id_list)
    node_functions.get_sensors()
    led_strip = LedStrip(
        location,
        main_loop,
    )
    motion_sensor = MotionSensor(
        location,
        main_loop,
        led_strip,
    )

    server = WebThingServer(MultipleThings([
        node_functions,
        led_strip,
        motion_sensor,
    ], 'LightAndTempDevice'),
                            port=8888)
    try:
        logging.info('starting the server')
        print('running')
        server.start()
    except KeyboardInterrupt:
        logging.info('stopping async tasks')
        print('interrupted')
        node_functions.cancel_node_async_tasks()
        led_strip.cancel_led_strip_async_tasks()
        motion_sensor.cancel_motion_sensor_async_tasks()
        logging.info('stopping the server')
        server.stop()
        logging.info('done \n')
Exemplo n.º 4
0
    def __init__(self, config, things, name=None, port=80, ssl_options=None):
        self.config = config

        if len(things) == 1:
            things = SingleThing(things[0])
        else:
            things = MultipleThings(things, name)

        super(WoTServer, self).__init__(things, port, ssl_options)
        self._set_of_all_thing_tasks = set()
def run_server():
    light = SenseHatThingLight()
    sensor = SenseHatThingSensor()
    server = WebThingServer(MultipleThings([light, sensor], 'SenseHat'),
                            port=8888)
    try:
        logging.info('starting the server')
        server.start()
    except KeyboardInterrupt:
        logging.info('stopping the server')
        server.stop()
        logging.info('done')
def run_server(config):
    things = make_things(config)

    port = 8888
    server = WebThingServer(MultipleThings(things, 'OpenWebNet'), port=port)
    try:
        print('starting the server on port %d'%(port,))
        server.start()
    except KeyboardInterrupt:
        logging.info('stopping the server')
        server.stop()
        logging.info('done')
def run_server():
    SensorHumidity = HumiditySensor()
    server = WebThingServer(MultipleThings([SensorHumidity],
                                           'Humidity Device'),
                            port=9999)

    try:
        logging.info('starting the sever')
        server.start()
    except KeyboardInterrupt:
        logging.debug('canceling sesor update looping task')
        SensorHumidity.cancel_update_level_task()
        logging.info('stopping the server')
        server.stop()
        logging.info('done')
def run_multiple_things_server():
    hue_lamp = make_hue_lamp_thing()
    blinds1 = make_blinds1_thing()
    blinds2 = make_blinds2_thing()
    things = [hue_lamp, blinds1, blinds2]

    server = WebThingServer(MultipleThings(things, 'AI-MAS LAB'), port=8888)

    try:
        logger.info('starting the server')
        server.start()

    except KeyboardInterrupt:
        logger.info('stopping the server')
        server.stop()
        logger.info('done')
Exemplo n.º 9
0
def run_server():

    #client = roslibpy.Ros(host='192.168.0.158', port=9090)
    client = roslibpy.Ros(host='localhost', port=9090)

    hue_light = make_hue_light(client)
    blinds1 = make_blinds1(client)
    things = [hue_light, blinds1]

    server = SensorNode(MultipleThings(things, "Nume"), client, port=8888)
    try:
        logging.info('starting the server')
        server.start()
    except KeyboardInterrupt:
        logging.info('stopping the server')
        server.stop()
        logging.info('done')
Exemplo n.º 10
0
def run_server():
    t_sensor = TemperatureSensor('28-031997791364')
    ht_sensor = HumidityTemperatureSensor(1, 0x40)

    server = WebThingServer(MultipleThings([t_sensor, ht_sensor],
                                           'Multi-sensor Device'),
                            port=8888)
    try:
        logging.info('starting the server')
        server.start()
    except KeyboardInterrupt:
        logging.debug('canceling the sensor update looping task')
        t_sensor.cancel_update_task()
        ht_sensor.cancel_update_task()
        logging.info('stopping the server')
        server.stop()
        logging.info('done')
Exemplo n.º 11
0
def run_server():
    # Create a thing that represents a humidity sensor
    sensor = CPUTempSensor()

    # If adding more than one thing, use MultipleThings() with a name.
    # In the single thing case, the thing's name will be broadcast.
    server = WebThingServer(MultipleThings([sensor], 'CPUTempSensor'),
                            port=8886)
    try:
        logging.info('starting the server')
        server.start()
    except KeyboardInterrupt:
        logging.debug('canceling the sensor update looping task')
        sensor.cancel_update_level_task()
        logging.info('stopping the server')
        server.stop()
        logging.info('done')
Exemplo n.º 12
0
def run_server():
    webthings = generate_webthings("webthings-mapping.yaml")
    things = [thing for thing, _ in webthings]
    update_tasks = [
        execute_async(task()) for _, task in webthings if task is not None
    ]

    # TODO don't use docker hostname for production
    server = WebThingServer(things=MultipleThings(things, name="home"),
                            port=8888,
                            hostname="host.docker.internal")
    try:
        logging.info("starting the server")
        server.start()
    except KeyboardInterrupt:
        logging.info("stopping background tasks")
        for task in update_tasks:
            task.cancel()
        logging.info("stopping the server")
        server.stop()
Exemplo n.º 13
0
def run_server():
    # Create a thing that represents a dimmable light
    thermometer = SIISThermometer()
    barometer = SIISBarometer()
    hygrometer = SIISHygrometer()

    # If adding more than one thing, use MultipleThings() with a name.
    # In the single thing case, the thing's name will be broadcast.
    server = WebThingServer(MultipleThings(
        [thermometer, barometer, hygrometer], 'WeatherStation'),
                            port=8888)
    try:
        logging.info('starting the server')
        server.start()
    except KeyboardInterrupt:
        logging.debug('canceling the sensor update looping task')
        thermometer.cancel_update_level_task()
        logging.info('stopping the server')
        server.stop()
        logging.info('done')
Exemplo n.º 14
0
def run_server():

    # Define webthing server, add the two predefined nodes
    server = WebThingServer(MultipleThings(
        [node270043001951343334363036, node4e0022000251353337353037],
        'senviroWeb'),
                            port=5000)
    # Start RabbitMQ thread
    mq_recieve_thread.start()

    try:
        # Start WebThing server
        print('starting the server')
        server.start()
    except KeyboardInterrupt:
        logging.debug('canceling the sensor update looping task')
        # node270043001951343334363036.cancel_update_level_task()
        print('stopping the server')
        server.stop()
        print('done')
Exemplo n.º 15
0
def run_server():
    # Create a thing that represents a dimmable light
    light = ExampleDimmableLight()

    # Create a thing that represents a humidity sensor
    sensor = FakeGpioHumiditySensor()

    # If adding more than one thing, use MultipleThings() with a name.
    # In the single thing case, the thing's name will be broadcast.
    server = WebThingServer(MultipleThings([light, sensor],
                                           'LightAndTempDevice'),
                            port=8888)
    try:
        logging.info('starting the server')
        server.start()
    except KeyboardInterrupt:
        logging.debug('canceling the sensor update looping task')
        sensor.cancel_update_level_task()
        logging.info('stopping the server')
        server.stop()
        logging.info('done')
Exemplo n.º 16
0
def run_server(queue=None):
    things = [AmbientWeather(), Yocto(), Acorn()]
    # If adding more than one thing, use MultipleThings() with a name.
    # In the single thing case, the thing's name will be broadcast.
    server = WebThingServer(MultipleThings(things, 'IoTSensors'),
                            port=8088,
                            hostname="iot.rymurr.com")
    try:
        logging.info('starting the server')

        executor = ThreadPoolExecutor(max_workers=1)
        IOLoop.current().run_in_executor(executor, consumer, queue, {
            'ambientweather': things[0],
            'yocto': things[1],
            'acorn': things[2]
        }, IOLoop.current())
        #       executor.submit(consumer, queue, {'ambientweather': things[0]})
        print("starting things server")
        server.start()
    except KeyboardInterrupt:
        logging.info('stopping the server')
        server.stop()
        logging.info('done')
Exemplo n.º 17
0
def run_server():
    
    # Initialisation des ports GPIO
    logging.info('Initialisation des arroseurs.')
    GPIO.setmode(GPIO.BCM)
    GPIO.setwarnings(False)

    pins = [4,17,27,22,18,23,24,25]
    for pin in pins:
        GPIO.setup(pin,GPIO.OUT)
        GPIO.output(pin,1)

    # Create a thing that represents a l'arroseur sur le GPIO 04
    arroseur17 = ArroseurGPIO(17,'urn:dev:ops:arroseurs-gpio-17', 'Relais 17', 'Arroseur 17')
    arroseur27 = ArroseurGPIO(27,'urn:dev:ops:arroseurs-gpio-27', 'Relais 27', 'Arroseur 27')
    arroseur22 = ArroseurGPIO(22,'urn:dev:ops:arroseurs-gpio-22', 'Relais 22', 'Arroseur 22')
    arroseur18 = ArroseurGPIO(18,'urn:dev:ops:arroseurs-gpio-18', 'Relais 18', 'Arroseur 18')
    arroseur23 = ArroseurGPIO(23,'urn:dev:ops:arroseurs-gpio-23', 'Relais 23', 'Arroseur 23')
    arroseur24 = ArroseurGPIO(24,'urn:dev:ops:arroseurs-gpio-24', 'Relais 24', 'Arroseur 24')

    arroseur04 = ArroseurTournantGPIO( 4,'urn:dev:ops:arroseurs-gpio-04', 'Relais 04', 'Arroseur 04')
    arroseur25 = ArroseurTournantGPIO(25,'urn:dev:ops:arroseurs-gpio-25', 'Relais 25', 'Arroseur 25')

    # If adding more than one thing, use MultipleThings() with a name.
    # In the single thing case, the thing's name will be broadcast.
    server = WebThingServer(MultipleThings([arroseur04, arroseur17, arroseur27, arroseur22, arroseur18, arroseur23, arroseur24, arroseur25],
                            'ArroseursDevice'),
                            port=8888)
    try:
        logging.info('starting the server')
        server.start()
    except KeyboardInterrupt:
        # logging.debug('canceling the sensor update looping task')
        # sensor.cancel_update_level_task()
        logging.info('stopping the server')
        server.stop()
        logging.info('done')
Exemplo n.º 18
0
def run_server(port: int, filename: str, switch_pin_forward: int,
               switch_pin_backward: int, description: str):

    while True:
        awnings = [Awning(motor) for motor in load_tb6612fng(filename)]
        awning_webthings = [
            AnwingWebThing(description, anwing) for anwing in awnings
        ]
        server = WebThingServer(MultipleThings(awning_webthings, 'Awnings'),
                                port=port,
                                disable_host_validation=True)
        if switch_pin_forward > 0 and switch_pin_backward > 0:
            Switch(switch_pin_forward, switch_pin_backward, awnings=awnings)
        try:
            logging.info('starting the server')
            server.start()
        except KeyboardInterrupt:
            logging.info('stopping the server')
            server.stop()
            logging.info('done')
            return
        except Exception as e:
            logging.error(e)
            sleep(3)
Exemplo n.º 19
0
def run_server():
    ds18 = DS18B20('28-03199779f5a1')
    ds18_celsius = Value(ds18.temperature().C)

    ds18_thing = Thing('urn:dev:ops:temperature-sensor', 'Temperature Sensor',
                       ['TemperatureSensor'])

    ds18_thing.add_property(
        Property(ds18_thing,
                 'celsius',
                 ds18_celsius,
                 metadata={
                     '@type': 'TemperatureProperty',
                     'title': 'Celsius',
                     'type': 'number',
                     'unit': '°C',
                     'readOnly': True
                 }))

    sht = SHT20(1, 0x40)
    h, t = sht.all()
    sht_celsius = Value(t.C)
    sht_rh = Value(h.RH)

    sht_thing = Thing('urn:dev:ops:humidity-temperature-sensor',
                      'Humidity and Temperature Sensor',
                      ['MultiLevelSensor', 'TemperatureSensor'])

    # If you want icon to show humidity:
    #   - remove type `TemperatureSensor`, and
    #   - change temperature metadata @type to `LevelProperty`

    sht_thing.add_property(
        Property(sht_thing,
                 'humidity',
                 sht_rh,
                 metadata={
                     '@type': 'LevelProperty',
                     'title': 'Relative humidity',
                     'type': 'number',
                     'unit': 'percent',
                     'readOnly': True
                 }))

    sht_thing.add_property(
        Property(sht_thing,
                 'temperature',
                 sht_celsius,
                 metadata={
                     '@type': 'TemperatureProperty',
                     'title': 'Celsius',
                     'type': 'number',
                     'unit': '°C',
                     'readOnly': True
                 }))

    server = WebThingServer(MultipleThings([ds18_thing, sht_thing],
                                           'Multi-sensor Device'),
                            port=8888)

    def update():
        t = ds18.temperature()
        ds18_celsius.notify_of_external_update(t.C)

        h, t = sht.all()
        sht_celsius.notify_of_external_update(t.C)
        sht_rh.notify_of_external_update(h.RH)

    timer = tornado.ioloop.PeriodicCallback(update, 3000)
    timer.start()

    try:
        logging.info('starting the server')
        server.start()
    except KeyboardInterrupt:
        logging.debug('stopping update task')
        timer.stop()
        logging.info('stopping the server')
        server.stop()
        logging.info('done')