def run_server(photos_path, static_path):
    """Create our photo cycler web thing and run the server."""
    if not os.path.isdir(photos_path):
        print('Photos directory does not exist')
        sys.exit(1)

    if not os.path.isdir(static_path):
        print('Static directory does not exist')
        sys.exit(1)

    thing = PhotoCyclerThing(photos_path, static_path)
    server = WebThingServer(
        SingleThing(thing),
        port=8888,
        additional_routes=[
            (
                r'/static/(.*)',
                tornado.web.StaticFileHandler,
                {'path': static_path},
            ),
        ]
    )

    try:
        server.start()
    except KeyboardInterrupt:
        server.stop()
Ejemplo n.º 2
0
 def run(self):
     AsyncIOMainLoop().install()
     self.ioloop = tornado.ioloop.IOLoop.current().asyncio_loop
     self.server = NoMDNSWebThingServer(SingleThing(self.thing.get_thing()),
                                        port=self.port)
     #self.server = WebThingServer(SingleThing(self.thing.get_thing()), port=self.port)
     if self.msgq is not None:
         self.ioloop.run_in_executor(None, self.thing.handle_msgs,
                                     self.msgq)
     self.server.start()
Ejemplo n.º 3
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()
Ejemplo n.º 4
0
def run_server():
    """Create our MPD Web Thing and run the server."""
    thing = MPDThing()

    server = WebThingServer(SingleThing(thing), port=8888)

    try:
        server.start()
    except KeyboardInterrupt:
        server.stop()
Ejemplo n.º 5
0
def run_server():
    thing = make_thing()
    server = WebThingServer(SingleThing(thing), port=8888)
    try:
        logging.info('starting the server')
        server.start()
    except KeyboardInterrupt:
        logging.info('stoping the server')
        server.stop()
        logging.info('done')
def run_server():
    weatherstation = weatherstationbme680.WeatherstationBME680()

    server = WebThingServer(SingleThing(weatherstation), port=8888)
    try:
        logging.info('starting the server')
        server.start()
    except KeyboardInterrupt:
        logging.info('stopping the server')
        server.stop()
        logging.info('done')
Ejemplo n.º 7
0
def run_server(port: int, gpio_number: int, name: str, description: str):
    light_sensor = LightSensor(gpio_number, name, description)
    server = WebThingServer(SingleThing(light_sensor),
                            port=port,
                            disable_host_validation=True)
    try:
        logging.info('starting the server')
        server.start()
    except KeyboardInterrupt:
        logging.info('stopping the server')
        server.stop()
        logging.info('done')
Ejemplo n.º 8
0
def run_server():
    sht = SHT20(1, 0x40)
    h, t = sht.all()
    celsius = Value(t.C)
    humidity = Value(h.RH)

    thing = Thing('urn:dev:ops:humidity-temperature-sensor', 'SHT20_Anthony',
                  ['MultiLevelSensor'])

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

    thing.add_property(
        Property(thing,
                 'temperature',
                 celsius,
                 metadata={
                     '@type': 'LevelProperty',
                     'title': 'Temperature',
                     'type': 'number',
                     'unit': '°C',
                     'readOnly': True
                 }))

    server = WebThingServer(SingleThing(thing), port=8889)

    def update():
        h, t = sht.all()
        celsius.notify_of_external_update(t.C)
        humidity.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')
Ejemplo n.º 9
0
def run_server(port: int, gpio_number: int, description: str):
    eltakows_sensor = EltakoWsSensor(gpio_number, description)
    server = WebThingServer(SingleThing(eltakows_sensor),
                            port=port,
                            disable_host_validation=True)
    try:
        logging.info('starting the server')
        server.start()
    except KeyboardInterrupt:
        logging.info('stopping the server')
        eltakows_sensor.cancel_measure_task()
        server.stop()
        logging.info('done')
Ejemplo n.º 10
0
def run_server():
    thing = SIISLight()

    # 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(SingleThing(thing), port=8888)
    try:
        logging.info('starting the server')
        server.start()
    except KeyboardInterrupt:
        logging.info('stopping the server')
        server.stop()
        logging.info('done')
Ejemplo n.º 11
0
def run_server(port=8888, poll_delay=3.0):

    sensor = LuxSensor(poll_delay=poll_delay)

    server = WebThingServer(SingleThing(sensor), port=port)
    try:
        logging.info("starting the server")
        server.start()
    except KeyboardInterrupt:
        logging.debug("cancelling the sensor update looping task")
        sensor.cancel_update_level_task()
        logging.info("stopping the server")
        server.stop()
        logging.info("done")
Ejemplo n.º 12
0
def run_server(port: int, name: str, i2c_expander: str, i2c_address: int,
               description: str):
    lcd = createI2C(i2c_expander, i2c_address)
    display_webthing = DisplayWebThing(name, description, lcd)
    server = WebThingServer(SingleThing(display_webthing),
                            port=port,
                            disable_host_validation=True)
    try:
        logging.info('starting the server')
        server.start()
    except KeyboardInterrupt:
        logging.info('stopping the server')
        server.stop()
        logging.info('done')
Ejemplo n.º 13
0
def run_server():
    thing = make_thing()
    flag = 0
    server = WebThingServer(SingleThing(thing), port=8888)
    try:
        th = threading.Thread(target=run_neo, args=(thing, ))
        th.deamon = True
        th.start()
        logging.info('starting the server')
        server.start()
    except KeyboardInterrupt:
        logging.info('stopping the server')
        server.stop()
        logging.info('done')
Ejemplo n.º 14
0
def run_server():
    """ Start http server with REST api """
    logging.info("controller: connect: %s %s" % (MAC, NAME))
    controller.connect()
    logging.info("controller: model: %s" % controller.getModelNumber())
    thing = make_thing()
    server = WebThingServer(SingleThing(thing), port=PORT)
    try:
        logging.info('starting the server')
        server.start()
    except KeyboardInterrupt:
        logging.info('stopping the server')
        server.stop()
        logging.info('done')
def run_server(name):
    asyncio.set_event_loop(asyncio.new_event_loop())
    # Create a thing that represents a opencv motion sensor
    sensor = OpenCvMotionSensor()

    server = WebThingServer(SingleThing(sensor), 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')
def run_server():
    thing = VirtualRPiThing()
    thing.name = 'Virtual PLAIN HTTP RPi Thing'

    server = WebThingServer(things=SingleThing(thing), port=PLAIN_HTTP_RS_PORT)

    try:
        logging.info('Starting the server.')
        logging.info('at PORT: ' + str(PLAIN_HTTP_RS_PORT))
        server.start()

    except KeyboardInterrupt:
        logging.info('Stopping the server.')
        server.stop()
        logging.info('Done.')
Ejemplo n.º 17
0
def run_server():
    tet = Tetrahedron()
    tet.start()

    thing = TetrahedronThing(tet)
    server = WebThingServer(SingleThing(thing), port=8888)
    try:
        logging.info('starting the server')
        server.start()
    except KeyboardInterrupt:
        logging.info('stopping the server')
        server.stop()
        logging.info('stopping tetrahedron')
        tet.end()
        tet.join()
        logging.info('done')
Ejemplo n.º 18
0
def run_server():

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

    # 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(SingleThing(sensor), 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')
Ejemplo n.º 19
0
def run_server():
    """
    If adding more than one Thing use MultipleThings() and supply a `name`.
    In the case of a SingleThing the SingleThing's `name` will be set as `name`.
    To change the Thing hosted by this Server edit `parameters.py`.
    """
    thing = VirtualRPiThing()
    thing.name = 'Virtual ACE HTTP RPi Thing'

    server = AceWebThingServer(things=SingleThing(thing),
                               port=ACE_HTTP_RS_PORT)
    try:
        logging.info('Starting the server at PORT: ' + str(ACE_HTTP_RS_PORT))
        server.start()
    except KeyboardInterrupt:
        logging.info('Stopping the server . . .')
        server.stop()
        logging.info('done.')
    except Exception as e:
        print(e)
def run_server():
    # Sensor settings
    SENSOR_ID = "light-sensor-01"
    SENSOR_DESCRIPTION = "Garden Light Sensor"
    DATA_TO_MEASURE = "Light"
    MEASURES_TICK = 10000
    # Create a thing that represents a humidity sensor
    fake_sensor = FakeSensor(SENSOR_ID, SENSOR_DESCRIPTION, DATA_TO_MEASURE,
                             MEASURES_TICK)
    # Add sensor to server
    server = WebThingServer(SingleThing(fake_sensor), port=8888)
    # Starts the server and stay in server loop
    try:
        logging.info('Starting the WebThing server')
        server.start()
    except KeyboardInterrupt:
        logging.debug('Canceling the sensor update looping task')
        fake_sensor.cancel_update_level_task()
        logging.info('Stopping the WebThing server')
        server.stop()
        logging.info('Exit!')
def run_server():
    """
    If adding more than one Thing use MultipleThings() and supply a `name`.
    In the case of a SingleThing the SingleThing's `name` will be set as `name`.
    To change the Thing hosted by this Server edit `parameters.py`.
    """
    thing = VirtualRPiThing()
    thing.name = 'Virtual ACE CoAP RPi Thing'

    server = CoapWebThingServer(things=SingleThing(thing),
                                port=RS_PORT,
                                hostname=HOST)
    try:
        logging.info('Starting a CoapWebThingServer at [ ' + RS_URL + ' ].')
        server.start()
    except KeyboardInterrupt:
        logging.info('Stopping the server.')
        server.stop()
        logging.info('Done.')
    except Exception as e:
        print(e)
Ejemplo n.º 22
0
def run_server():
    ds18 = DS18B20('28-011458c437aa')
    celsius = Value(ds18.temperature().C)

    thing = Thing(
        'urn:dev:ops:temperature-sensor',
        'DS18B20_Anthony',
        ['TemperatureSensor'])

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

    server = WebThingServer(SingleThing(thing), port=8888)

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

    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')
Ejemplo n.º 23
0
def run_server():
    syslog.syslog('Looking for a Thunderboard ...')
    while (True):
        tbsense = getThunderboard()
        if tbsense is not None:
            break
        syslog.syslog('Not found, retrying after 5sec ...')
        time.sleep(5)

    sensors = ExtEnvironSensor(tbsense)

    # If adding more than one thing here, be sure to set the `name`
    # parameter to some string, which will be broadcast via mDNS.
    # In the single thing case, the thing's name will be broadcast.
    server = WebThingServer(SingleThing(sensors), port=8899)
    try:
        syslog.syslog('Starting the Webthing server on: ' + str(server.hosts))
        server.start()
    except KeyboardInterrupt:
        sensors.cancel_tasks()
        server.stop()
        syslog.syslog('Thundeboard Webthing stopped')
Ejemplo n.º 24
0
    def _load_runners(self):
        trigger = RandomTrigger(tests_per_day=self._tests_per_day,
                                immediate=self._immediate)

        # Load test runners
        for entry_point in pkg_resources.iter_entry_points("murakami.runners"):
            logging.debug("Loading test runner %s", entry_point.name)
            if "tests" not in self._config:
                self._config["tests"] = {}
            if entry_point.name not in self._config["tests"]:
                self._config["tests"][entry_point.name] = {"enabled": False}
            self._runners[entry_point.name] = entry_point.load()(
                config=self._config["tests"][entry_point.name],
                data_cb=self._call_exporters,
                location=self._location,
                network_type=self._network_type,
                connection_type=self._connection_type,
                device_id=self._device_id,
            )

        # Start webthings server if enabled
        if self._webthings:
            self._server = WebThingServer(
                SingleThing(MurakamiThing(self._runners.values())),
                port=self._port,
                hostname=self._hostname,
                ssl_options=self._ssl_options,
                additional_routes=self._additional_routes,
                base_path=self._base_path,
            )

        # Start test scheduler if enabled
        if self._tests_per_day > 0:
            self._scheduler = TornadoScheduler()
            self._scheduler.add_job(self._call_runners,
                                    id="runners",
                                    name="Test Runners",
                                    trigger=trigger)
Ejemplo n.º 25
0
    async def create(self):
        await self.add_property(
            Property(
                self,
                "sentiments",
                Value(1),
                metadata={
                    "@type": "SentimentsProperty",
                    "title": "Sentiments",
                    "type": "number",
                    "minimum": 0,
                    "maximum": 1,
                    "description": "Latest sentiments response from NLP",
                },
            )
        )

        await self.add_property(
            Property(
                self,
                "words",
                Value([]),
                metadata={
                    "@type": "WordsProperty",
                    "title": "Words",
                    "type": "array",
                    "items": {"type": "string"},
                    "description": "Latest words response from NLP",
                },
            )
        )

        await self.add_property(
            Property(
                self,
                "keywords",
                Value([]),
                metadata={
                    "@type": "KeyWordsProperty",
                    "title": "KeyWords",
                    "type": "array",
                    "items": {"type": "string"},
                    "description": "Latest keywords response from NLP",
                },
            )
        )

        await self.add_property(
            Property(
                self,
                "summary",
                Value([]),
                metadata={
                    "@type": "SummaryProperty",
                    "title": "Summary",
                    "type": "array",
                    "items": {"type": "string"},
                    "description": "Latest summary response from NLP",
                },
            )
        )

        await self.add_available_action(
            "sentiment_analysis",
            {
                "title": "情绪分析",
                "description": "向 NLP Thing 发送文本并判断文本的情绪",
                "input": {
                    "type": "object",
                    "required": ["text"],
                    "properties": {"text": {"type": "string"}},
                },
            },
            SentimentAnalysisAction,
        )

        await self.add_available_action(
            "word_tokenize",
            {
                "title": "分词",
                "description": "向 NLP Thing 发送文本并返回词组",
                "input": {
                    "type": "object",
                    "required": ["text"],
                    "properties": {"text": {"type": "string"}},
                },
            },
            WordTokenizeAction,
        )

        await self.add_available_action(
            "keywords_extraction",
            {
                "title": "关键词提取",
                "description": "向 NLP Thing 发送文本并提取关键词",
                "input": {
                    "type": "object",
                    "required": ["text", "limit"],
                    "properties": {
                        "text": {"type": "string"},
                        "limit": {"type": "integer"},
                    },
                },
            },
            KeywordExtractionAction,
        )

        await self.add_available_action(
            "summary_extraction",
            {
                "title": "摘要提取",
                "description": "向 NLP Thing 发送文本并提取摘要",
                "input": {
                    "type": "object",
                    "required": ["text", "limit"],
                    "properties": {
                        "text": {"type": "string"},
                        "limit": {"type": "integer"},
                    },
                },
            },
            SummarizationExtractionAction,
        )

        return SingleThing(self)  # MultipleThings({self.id: self}, "nlp thing")
Ejemplo n.º 26
0
        self.volume = str(value)

    def setSensitivity(self, value):
        logging.info("Sensitivity has been changed: " + str(value))
        os.system("amixer set Capture " + str(value) + "% > /dev/null")
        self.sensitivity = str(value)

    def pauseListener(self, bool):
        if bool:
            os.system("amixer set Capture cap > /dev/null")
        else:
            os.system("amixer set Capture nocap > /dev/null")


if __name__ == '__main__':
    logging.basicConfig(
        level=10,
        format="%(asctime)s %(filename)s:%(lineno)s %(levelname)s %(message)s")
    thing = VoiceAssistant()
    thing.setSensitivity(thing.sensitivity)
    thing.setVolume(thing.volume)
    thing.setListen(thing.listening)
    server = WebThingServer(SingleThing(thing), port=9999)
    try:
        logging.info('Starting the server..')
        server.start()
    except KeyboardInterrupt:
        logging.info('Stopping the server..')
        server.stop()
        logging.info('..done.')
Ejemplo n.º 27
0
 def run(self):
     self.ioloop = tornado.ioloop.IOLoop.instance()
     self.server = WebThingServer(SingleThing(self.thing.get_thing()), port=self.port)
     self.server.start()
     self.pid = os.getpid()
Ejemplo n.º 28
0
from webthing import SingleThing, WebThingServer

from examples.global_parameters import GlobalParameters
from things.virtual_temperature import VirtualTemperature
import logging

param = GlobalParameters()

logging.basicConfig(
    level=10,
    format="%(asctime)s %(filename)s:%(lineno)s %(levelname)s %(message)s")

virtual_temperature_container = SingleThing(VirtualTemperature())

server = WebThingServer(things=virtual_temperature_container,
                        port=param.RS_PORT,
                        hostname=param.RS_HOST)

try:
    logging.info('Starting the server.')
    server.start()
except KeyboardInterrupt:
    logging.info('Stopping the server.')
    server.stop()
    logging.info('Done.')
Ejemplo n.º 29
0
        except:
            syslog.syslog('Error setting up recording!')
        while not self.terminated:
            self.picam.wait_recording(2)
        self.picam.stop_recording()
        output.close()


global _loop, new_frame

if __name__ == '__main__':

    _loop = get_event_loop()
    new_frame = Event()

    picamera_web_thing = PiCameraThing()
    server = WebThingServer(SingleThing(picamera_web_thing),
                            port=8900,
                            additional_routes=[
                                (r'/media/stream', StreamHandler),
                                (r'/media/snapshot', SnapshotHandler)
                            ])
    try:
        syslog.syslog('Starting the Webthing server on: ' + str(server.hosts))
        server.start()
    except KeyboardInterrupt:
        picamera_web_thing.terminated = True
        picamera_web_thing.cam_thr.join()
    finally:
        pass
Ejemplo n.º 30
0
            callback_time=30000,
        )
        self.timer.start()

    def update_level(self):
        data = get('http://garage.home.internal/').json()
        if data.get('is_open') != self.is_open.get():
            self.is_open.notify_of_external_update(
                value=data.get('is_open'),
            )


if __name__ == '__main__':
    parser = ArgumentParser()
    parser.add_argument(
        '--port',
        dest='port',
        type=int,
        default=8888,
    )
    args = parser.parse_args()
    garage_door = GarageDoor()
    server = WebThingServer(
        things=SingleThing(garage_door),
        port=args.port,
    )
    try:
        server.start()
    except KeyboardInterrupt:
        server.stop()