def run(self):
        Gateway.run(self)

        sensors = self.get_sensors()
        while True:
            for sensor_id, sensor in sensors.items():
                try:
                    if sensor.kind in self.__logic__:
                        self.__logic__[sensor.kind].update(sensor, None)
                    elif self.default_sensor_logic is not None:
                        self.default_sensor_logic.update(sensor, None)
                except:
                    pass
                time.sleep(0.2)
Exemple #2
0
    def run(self):
        Gateway.run(self)

        sensors = self.get_sensors()
        while True:
            for sensor_id, sensor in sensors.iteritems():
                try:
                    if sensor.kind in self.__logic__:
                        self.__logic__[sensor.kind].update(sensor, None)
                    elif self.default_sensor_logic is not None:
                        self.default_sensor_logic.update(sensor, None)
                except:
                    pass
                time.sleep(0.2)
Exemple #3
0
    # create a gateway service instance
    # the parameters are: app name, deviot address, mq server address, deviot account
    app = Gateway("Slider_test", "52.38.220.120:9000", "52.38.220.120:1883",
                  "account@devIoT")

    # register input sensors
    # the parameters are: sensor kind, sensor id, sensor display name
    app.register("Slider", "myslider", "Slider")

    # register some output sensors
    # don't set the  action call back function for those sensors
    app.register_action("led", "BlueLED", "BlueLED")
    app.register_action("led", "YellowLED", "YellowLED")

    # set callback for all sensors which kind is 'Pollution'
    app.register_callback_for_kind("led", LED_callback)

    # run service
    app.run()

    while True:
        # use random value to update the sensor
        # the parameters are: sensor id, new sensor value

        lock.acquire()
        PinI2State = int(float(value.get('I2')) * 20)
        print(PinI2State)
        app.set_value("myslider", PinI2State)
        lock.release()

        time.sleep(0.5)
if __name__ == '__main__':

    import_sensor_model()

    devIot_address = config.get_string("address", "10.140.92.25:9000")
    mqtt_address = config.get_string("mqtthost", "10.140.92.25:1883")
    app_name = config.get_string("appname", "IndoorLocation")
    devIot_account = config.get_info("account", "")

    app = Gateway(app_name, devIot_address, mqtt_address, devIot_account)
    app.is_virtual = True

    for key in models:
        app.register_custom_sensor(models[key])

    app.run()

    while True:
        time.sleep(1.5)
        devices = ServiceHelper.get_all_clients()
        if devices is not None:
            sensors = app.get_sensors()
            for key in sensors:
                sensor = sensors[key]
                all_logic[sensor.kind].update(sensor, devices)