Exemple #1
0
    def __init__(self, app_name, iot_address, mqtt_address, deviot_account):
        Gateway.__init__(self, app_name, iot_address, mqtt_address, deviot_account)
        self.__models__ = {}
        self.__logic__ = {}

        self.__import_sensor_model()

        self.__load_sensors()

        self.default_sensor_logic = None
    def __init__(self, app_name, iot_address, mqtt_address, deviot_account):
        Gateway.__init__(self, app_name, iot_address, mqtt_address,
                         deviot_account)
        self.__models__ = {}
        self.__logic__ = {}

        self.__import_sensor_model()

        self.__load_sensors()

        self.default_sensor_logic = None
    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 #4
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 #5
0
            value.put('D3', '1')

    if sensor_id == 'YellowLED':
        if action.name == 'off':
            value.put('D4', '0')
        else:
            value.put('D4', '1')
    lock.release()


if __name__ == '__main__':
    app_name = config.get_string("appname", "test")
    print(app_name)
    # 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()
# action name will be 'on' or 'off'
def trigger_alert_shanghai(sensor_id, action):
    print("shanghai " + action.name)


# action name will be 'on' or 'off'
def pollution_callback(sensor_id, action):
    print("action %s occur at %s " % (action.name, sensor_id))


if __name__ == '__main__':
    app_name = config.get_string("appname", "test")
    print(app_name)
    # create a gateway service instance
    # the parameters are: app name, deviot address, mq server address, deviot account
    app = Gateway("tingxin_test", "www.ciscodeviot.com",
                  "mqtt.ciscodeviot.com:1883", "")

    # register input sensors
    # the parameters are: sensor kind, sensor id, sensor display name
    app.register("PM25", "PM25Shanghai", "PM25Shanghai")
    app.register("Noise", "NoiseShanghai", "NoiseShanghai")

    # register output sensors
    # the parameters are: sensor kind, sensor id, sensor display name, action call back function
    app.register_action("Alert", "AlertToShanghai", "AlertToShanghai",
                        trigger_alert_shanghai)

    # register some output sensors
    # don't set the  action call back function for those sensors
    app.register_action("Pollution", "PollutionSuzhou", "PollutionSuzhou")
    app.register_action("Pollution", "PollutionBeijing", "PollutionBeijing")
grovepi.pinMode(led, "OUTPUT")


# turn on/off the led when receive action from DevIot
# action name will be 'on' or 'off'
def trigger_grove_led(sensor_id, action):
    print(('led get action:' + action.name))
    if action.name == 'on':
        grovepi.digitalWrite(led, 1)
    else:
        grovepi.digitalWrite(led, 0)


# create a gateway service instance
# the parameters are: app name, deviot address, mq server address, deviot account
app = Gateway("grovepi_test", "www.ciscodeviot.com",
              "mqtt.ciscodeviot.com:1883", "")

# register input sensors
# the parameters are: sensor kind, sensor id, sensor display name
app.register("light", "grovelight", "GroveLight")

# register output sensors
# the parameters are: sensor kind, sensor id, sensor display name, action call back function
app.register_action("led", "groveled", "GroveLed", trigger_grove_led)

# run service
app.run()

while True:
    try:
        # get sensor value
                exec import_sensor
                add_sensor = "load_sensor_model({0:s},{1:s})".format(sensor_name, sensor_logic)
                exec add_sensor


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)
# action name will be 'on' or 'off'
def trigger_alert_shanghai(sensor_id, action):
    print("shanghai " + action.name)


# action name will be 'on' or 'off'
def pollution_callback(sensor_id, action):
    print("action %s occur at %s " % (action.name, sensor_id))

if __name__ == '__main__':
    app_name = config.get_string("appname", "test")
    print(app_name)
    # create a gateway service instance
    # the parameters are: app name, deviot address, mq server address, deviot account
    app = Gateway("tingxin_test", "www.ciscodeviot.com", "mqtt.ciscodeviot.com:1883", "")

    # register input sensors
    # the parameters are: sensor kind, sensor id, sensor display name
    app.register("PM25", "PM25Shanghai", "PM25Shanghai")
    app.register("Noise", "NoiseShanghai", "NoiseShanghai")

    # register output sensors
    # the parameters are: sensor kind, sensor id, sensor display name, action call back function
    app.register_action("Alert", "AlertToShanghai", "AlertToShanghai", trigger_alert_shanghai)

    # register some output sensors
    # don't set the  action call back function for those sensors
    app.register_action("Pollution", "PollutionSuzhou", "PollutionSuzhou")
    app.register_action("Pollution", "PollutionBeijing", "PollutionBeijing")
Exemple #10
0
import time
import os
import psutil
from DevIoTGateway.gateway import Gateway

account = raw_input(
    "--Please enter DevIot email account([email protected]):\n")
gatewayname = account + "_gateway"
prefix = raw_input("--Please enter a Prefix for Sensor names:\n")
app = Gateway("gatewayname", "52.38.220.120:9000", "iot.eclipse.org:1883",
              account)

# register input sensors
# the parameters are: sensor kind, sensor id, sensor display name
app.register("cpu", "cpu", prefix + "-CPU")

# register output sensors
# the parameters are: sensor kind, sensor id, sensor display name, action call back function
#app.register_action("led", "groveled", prefix+"-Led", trigger_grove_led)

# run service
app.run()

pid = os.getpid()
print pid
p = psutil.Process(pid)
print p.get_cpu_percent(interval=1.0)
print p.get_memory_percent()
print p.get_memory_info()
print p.get_cpu_times()
print p.get_open_files()
grovepi.pinMode(led, "OUTPUT")


# turn on/off the led when receive action from DevIot
# action name will be 'on' or 'off'
def trigger_grove_led(sensor_id, action):
    print('led get action:' + action.name)
    if action.name == 'on':
        grovepi.digitalWrite(led, 1)
    else:
        grovepi.digitalWrite(led, 0)


# create a gateway service instance
# the parameters are: app name, deviot address, mq server address, deviot account
app = Gateway("grovepi_test", "www.ciscodeviot.com", "mqtt.ciscodeviot.com:1883", "")

# register input sensors
# the parameters are: sensor kind, sensor id, sensor display name
app.register("light", "grovelight", "GroveLight")

# register output sensors
# the parameters are: sensor kind, sensor id, sensor display name, action call back function
app.register_action("led", "groveled", "GroveLed", trigger_grove_led)

# run service
app.run()
    
while True:
    try:
        # get sensor value