Exemple #1
0
import IOT
import time

IOT.initService()

notifiableThings = IOT.find(IOT.All, ["light", "speaker", "sign"])

def notify(self):
	if "speaker" in self.type:
		self.speak("You have a notification!")
	elif "light" in self.type:
		onoff, red, green, blue = self.light()
		self.light() = True, 255, 0, 0
		time.sleep(1)
		self.light() = onoff, red, green, blue
		time.sleep(1)
		self.light() = True, 255, 0, 0
		time.sleep(1)
		self.light() = onoff, red, green, blue
	elif "sign" in self.type:
		sign = self.sign()
		self.sign() = "http://notify.gif"
		time.sleep(1)
		self.sign() = sign

notifiableThings._reg("notify", notify)

Exemple #2
0
__author__ = 'Jackie'
from phue import Bridge
import IOT

IOT.initializeMQTT()

SERVER_ADDRESS = "192.168.1.100"

b = Bridge(SERVER_ADDRESS)
b.connect()

def setBrightness(obj, x):
    obj.brightness = x

hue_light1 = b.lights[0]
light1 = IOT.Thing("light1")

light1._createType("light")

light1._createMethod("turn", lambda x: setBrightness(hue_light1, 255 if x else 0),{}, "turn on or off light")
light1._createMethod("light", lambda: hue_light1.brightness,{}, "get the brightness")
light1._createMethod("brightness", lambda x: setBrightness(hue_light1, x), {}, "set the brightness of the light")

hue_light2 = b.lights[1]
light2 = IOT.Thing("light2")

light2._createType("light")

light2._createMethod("turn", lambda x: setBrightness(hue_light2, 255 if x else 0),{}, "turn on or off light")
light2._createMethod("light", lambda: hue_light2.brightness,{}, "get the brightness")
light2._createMethod("brightness", lambda x: setBrightness(hue_light2, x), {}, "set the brightness of the light")
Exemple #3
0
__author__ = 'Jackie'
import time

import IOT

IOT.initialize()
time.sleep(10)
IOT.selectAll().identify()
Exemple #4
0
__author__ = 'Jackie'
import IOT
IOT.init()
thing = IOT.Thing("thing")
thing._createMethod("identify", lambda: print("hello world"), {})
thing._createMethod("print", lambda x: print(x), {"text":"string"})
anotherThing = IOT.Thing("thing")
Exemple #5
0
def adrianDis():
    return int(IOT.selectWithName("Nexus 5-A")[0]._rssi)
Exemple #6
0
def isAdrianAround():
    return len(IOT.selectWithName("Nexus 5-A")) == 1
Exemple #7
0
def notifyMe(urgent):
    if urgent:
        notify(IOT.selectAll())
    else:
        notify(IOT.selectNearest())
Exemple #8
0
import IOT
import random
import time

IOT.initialize()

def isAdrianAround():
    return len(IOT.selectWithName("Nexus 5-A")) == 1

def adrianDis():
    return int(IOT.selectWithName("Nexus 5-A")[0]._rssi)

def notify(devices):
    for device in devices:
        if "speaker" in device._type:
            device.speak("Adrian is around you!!!")
        if "lights" in device._type:
            device.setLights("true", str(random.randint(0, 255)), str(random.randint(0, 255)), str(random.randint(0, 255)))

def notifyMe(urgent):
    if urgent:
        notify(IOT.selectAll())
    else:
        notify(IOT.selectNearest())

while True:
    if isAdrianAround():
        print("Adrian is around ", adrianDis())
    if isAdrianAround() and adrianDis() > -75:
        if adrianDis() > -65:
            notifyMe(True)
Exemple #9
0
from flask import Flask, render_template, request, abort
from IOT import *

#
# constant value
#
APP = Flask(__name__)
DEFAULT_WAITING_TIME_WHOLE = 20
DEFAULT_WAITING_TIME_DISH = 10
CONSUMER_DISPLAY = 4
try:
    iot = IOT()
except:
    print('no iot')
    pass

#
# table: information of all tables in the restaurant
#       id: the id of table
#       finished: the precent of dish finished 0~100
#       dish: number of dish finished
#       time_left: time left for eating the dish
#       status: whether the table is empty, 0 = empty, 1 = occupy
#       order: how many dishes ordered
#
table = [{
    'id': 0,
    'finished': 0,
    'dish': 0,
    'time_left': 0,
    'status': 0,