__author__ = 'tingxxu'

import threading
import time

from DevIoTGateway.sensor import Sensor, SAction, SSetting
from DevIoTGateway.config import config
from DevIoTGatewayPi.sensorlogic import SensorLogic
from logic.arduinopioperator import ArduinopiOperator


led = Sensor("led", "led_2", "ALed")

on_action = SAction("on")
off_action = SAction("off")

flash_action = SAction("flash")

duration_setting = SSetting("duration", 0, [2, 100], 10, True)
interval_setting = SSetting("interval", 0, [0.1, 10], 1, True)
flash_action.add_setting(duration_setting)
flash_action.add_setting(interval_setting)

led.add_action(on_action)
led.add_action(off_action)
led.add_action(flash_action)


class LedLogic(SensorLogic):

    state = 0
示例#2
0
__author__ = 'tingxxu'

from DevIoTGateway.sensor import Sensor
from DevIoTGateway.sproperty import SProperty
from DevIoTGateway.config import config
from DevIoTGatewayPi.sensorlogic import SensorLogic
from logic.arduinopioperator import ArduinopiOperator

light = Sensor("light", "light_2", "ALight")

value_property = SProperty("value", 0, [0, 100], 0)
value_property.unit = "Nit"
light.add_property(value_property)


class LightLogic(SensorLogic):
    @staticmethod
    def update(sensor, data):
        pin = config["sensors"][sensor.id]['pin']
        new_value = ArduinopiOperator.read(pin)
        if new_value is not None:
            updated_properties = {"value": new_value * 100}
            sensor.update_properties(updated_properties)
__author__ = 'tingxxu'

import sys
from DevIoTGateway.sensor import Sensor, SProperty, SSetting
from DevIoTGateway.config import config
from logic.sensorlogic import SensorLogic

floor = config["service"]["map_name"]

cmxarea = Sensor("cmxarea", "cmxarea_1", "Device Count")

count_property = SProperty("count", 0, None, 0)
count_property.description = "count of the device in target area"
cmxarea.add_property(count_property)

x1_setting = SSetting("X1", 0, None, 466, True)
x1_setting.description = "x-coordinate of area"

y1_setting = SSetting("Y1", 0, None, 710, True)
y1_setting.description = "y-coordinate of area"

x2_setting = SSetting("X2", 0, None, 640, True)
x2_setting.description = "x-coordinate of area"

y2_setting = SSetting("Y2", 0, None, 680, True)
y2_setting.description = "y-coordinate of area"

x3_setting = SSetting("X3", 0, None, 480, True)
x3_setting.description = "x-coordinate of area"

y3_setting = SSetting("Y3", 0, None, 720, True)
示例#4
0
__author__ = 'tingxxu'

import math

from DevIoTGateway.sensor import Sensor
from DevIoTGateway.sproperty import SProperty
from DevIoTGateway.config import config
from DevIoTGatewayPi.sensorlogic import SensorLogic
from logic.arduinopioperator import ArduinopiOperator

temperature = Sensor("temperature", "temperature_2", "AThermometer")

value_property = SProperty("value", 0, [0, 100], 0)
value_property.unit = "Celsius"
temperature.add_property(value_property)


class TemperatureLogic(SensorLogic):
    @staticmethod
    def update(sensor, data):
        pin = config["sensors"][sensor.id]['pin']
        raw_value = ArduinopiOperator.read(pin)
        if raw_value is not None:
            new_value = 0
            if raw_value != 0:
                b_key = 4250
                resistance = (1023 - raw_value) * 10000.0 / raw_value
                new_value = 1 / (math.log(resistance / 10000) / b_key +
                                 1 / 298.15) - 273.15 + 100
            updated_properties = {"value": new_value}
            sensor.update_properties(updated_properties)
示例#5
0
__author__ = 'tingxxu'

from DevIoTGateway.sensor import Sensor
from DevIoTGateway.sproperty import SProperty
from DevIoTGateway.config import config
from DevIoTGatewayPi.sensorlogic import SensorLogic
from logic.arduinopioperator import ArduinopiOperator

sound = Sensor("sound", "sound_2", "ASound")

value_property = SProperty("volume", 0, [0, 100], 0)
value_property.unit = "Decibel"
sound.add_property(value_property)


class SoundLogic(SensorLogic):
    @staticmethod
    def update(sensor, data):
        pin = config["sensors"][sensor.id]['pin']
        new_value = ArduinopiOperator.read(pin)
        if new_value is not None:
            updated_properties = {"volume": new_value * 100}
            sensor.update_properties(updated_properties)
    # 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")

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

    # register a complex sensor
    weather = Sensor("weather", "weatherinsh", "WeatherInShangHai")

    temperature = SProperty("temperature", 0, [-10, 50], 20)
    temperature.unit = "Celsius"

    humid = SProperty("humid", 0, [0, 100], 35)
    humid.unit = "D"

    start = SAction("start")
    end = SAction("end")
    suspend = SAction("suspend")

    weather.add_property(temperature)
    weather.add_property(humid)

    weather.add_action(start)
    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")

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

    # register a complex sensor
    weather = Sensor("weather", "weatherinsh", "WeatherInShangHai")

    temperature = SProperty("temperature", 0, [-10, 50], 20)
    temperature.unit = "Celsius"

    humid = SProperty("humid", 0, [0, 100], 35)
    humid.unit = "D"

    start = SAction("start")
    end = SAction("end")
    suspend = SAction("suspend")

    weather.add_property(temperature)
    weather.add_property(humid)

    weather.add_action(start)
示例#8
0
__author__ = 'tingxxu'

from DevIoTGateway.sensor import Sensor, SProperty
from DevIoTGateway.config import config
from DevIoTGatewayPi.sensorlogic import SensorLogic
from logic.arduinopioperator import ArduinopiOperator

button = Sensor("button", "button_a", "AButton")

value_property = SProperty("pressed", 0, None, 0)

button.add_property(value_property)


class ButtonLogic(SensorLogic):
    @staticmethod
    def update(sensor, data):
        pin = config["sensors"][sensor.id]['pin']
        new_value = ArduinopiOperator.read(pin)
        if new_value is not None:
            if new_value == 0:
                updated_properties = {"pressed": 0}
            else:
                updated_properties = {"pressed": 1}
            sensor.update_properties(updated_properties)
import sys

from DevIoTGateway.sensor import Sensor, SProperty, SSetting
from DevIoTGateway.config import config

from logic.sensorlogic import SensorLogic

floor = config["service"]["map_name"]

default_location = {"location": "others"}
areas = []
for area in config["areas"]:
    areas.append(area)

cmxdevice = Sensor("cmxdevice", "cmxdevice_1", "Personal Device")

location_property = SProperty("location", 1, [], areas[0]["name"])
location_property.description = "location of the device in %s" % floor
cmxdevice.add_property(location_property)
for area in areas:
    location_property.range.append(area["name"])

x_property = SProperty("x", 0, None, 0)
x_property.description = "x-coordinate of the device in %s" % floor
cmxdevice.add_property(x_property)

y_property = SProperty("y", 0, None, 0)
y_property.description = "y-coordinate of the device in %s" % floor
cmxdevice.add_property(y_property)
__author__ = 'tingxxu'

import math

from DevIoTGateway.sensor import Sensor
from DevIoTGateway.sproperty import SProperty
from DevIoTGateway.config import config
from DevIoTGatewayPi.sensorlogic import SensorLogic
from logic.arduinopioperator import ArduinopiOperator


temperature = Sensor("temperature", "temperature_2", "AThermometer")

value_property = SProperty("value", 0, [0, 100], 0)
value_property.unit = "Celsius"
temperature.add_property(value_property)


class TemperatureLogic(SensorLogic):

    @staticmethod
    def update(sensor, data):
        pin = config["sensors"][sensor.id]['pin']
        raw_value = ArduinopiOperator.read(pin)
        if raw_value is not None:
            new_value = 0
            if raw_value != 0:
                b_key = 4250
                resistance = (1023 - raw_value) * 10000.0 / raw_value
                new_value = 1/(math.log(resistance/10000)/b_key+1/298.15)-273.15 + 100
            updated_properties = {"value": new_value}
示例#11
0
__author__ = 'tingxxu'

import threading
import time

from DevIoTGateway.sensor import Sensor, SAction, SSetting
from DevIoTGateway.config import config
from DevIoTGatewayPi.sensorlogic import SensorLogic
from logic.arduinopioperator import ArduinopiOperator

buzzer = Sensor("buzzer", "buzzer_2", "ABuzzer")

on_action = SAction("on")
off_action = SAction("off")

duration_setting = SSetting("duration", 0, [2, 100], 10, True)
interval_setting = SSetting("interval", 0, [0.1, 10], 1, True)
on_action.add_setting(duration_setting)
on_action.add_setting(interval_setting)

buzzer.add_action(on_action)
buzzer.add_action(off_action)


class BuzzerLogic(SensorLogic):

    state = 0
    duration = 10
    interval = 1
    t = None
__author__ = 'tingxxu'

from DevIoTGateway.sensor import Sensor, SProperty
from DevIoTGateway.config import config
from DevIoTGatewayPi.sensorlogic import SensorLogic
from logic.arduinopioperator import ArduinopiOperator

button = Sensor("button", "button_a", "AButton")

value_property = SProperty("pressed", 0, None, 0)

button.add_property(value_property)


class ButtonLogic(SensorLogic):

    @staticmethod
    def update(sensor, data):
        pin = config["sensors"][sensor.id]['pin']
        new_value = ArduinopiOperator.read(pin)
        if new_value is not None:
            if new_value == 0:
                updated_properties = {"pressed": 0}
            else:
                updated_properties = {"pressed": 1}
            sensor.update_properties(updated_properties)
__author__ = 'tingxxu'

import threading
import time

from DevIoTGateway.sensor import Sensor, SAction, SSetting
from DevIoTGateway.config import config
from DevIoTGatewayPi.sensorlogic import SensorLogic
from logic.arduinopioperator import ArduinopiOperator


buzzer = Sensor("buzzer", "buzzer_2", "ABuzzer")

on_action = SAction("on")
off_action = SAction("off")


duration_setting = SSetting("duration", 0, [2, 100], 10, True)
interval_setting = SSetting("interval", 0, [0.1, 10], 1, True)
on_action.add_setting(duration_setting)
on_action.add_setting(interval_setting)

buzzer.add_action(on_action)
buzzer.add_action(off_action)


class BuzzerLogic(SensorLogic):

    state = 0
    duration = 10
    interval = 1