Esempio n. 1
0
def on_message(id, value):
    global nextVal
    if id.endswith(str(Out1Id)) == True:			
        print("value received: " + value)		  # the value that we receive from the cloud is a string
        IOT.send(value, Out1Id)                #provide feedback to the cloud that the operation was successful, the value is still a string, so we can simply send it back to the cloud.
        nextVal = int(value)					# convert the received data, which is a string, into an integer
    else:
        print("unknown actuator: " + id)
Esempio n. 2
0
def SwitchLightsOff():
    '''Switch the lights off'''
    global LightRelaisState
    try:
        LightRelaisState = False
        GPIO.output(LightsRelaisPin, True)  #pin is reversed value
        if IsConnected:  # no need to try and send the state if not yet connected, will be updated when connection is successfull
            IOT.send('false', LightsRelaisPin)
    except:
        logging.exception('failed to switch lights off')
Esempio n. 3
0
def TurnWaterOn():
    global WaterRelaisState
    '''Turn the water on'''
    try:
        GPIO.output(WaterRelaisPin, False)  # pin takes reversed value.
        WaterRelaisState = True
        if IsConnected:  # no need to try and send the state if not yet connected, will be updated when connection is successfull
            IOT.send("true", WaterRelaisPin)
    except:
        logging.exception('failed to turn water on')
Esempio n. 4
0
def on_message(id, value):
    if id.endswith(str(Led)) == True:
        value = value.lower()                           #make certain that the value is in lower case, for 'True' vs 'true'
        if value == "true":
            grovepi.digitalWrite(Led, 1)
            IOT.send("true", Led)                #provide feedback to the cloud that the operation was succesful
        elif value == "false":
            grovepi.digitalWrite(Led, 0)
            IOT.send("false", Led)               #provide feedback to the cloud that the operation was succesful
        else:
            print("unknown value: " + value)
Esempio n. 5
0
def TurnWaterOff():
    '''Turn the water off'''
    global WaterRelaisState
    try:
        if WaterRelaisState == True:
            GPIO.output(WaterRelaisPin, True)  # pin takes reversed value
            WaterRelaisState = False
            if IsConnected:  # no need to try and send the state if not yet connected, will be updated when connection is successfull
                IOT.send("false", WaterRelaisPin)
    except:
        logging.exception('failed to turn water off')
Esempio n. 6
0
def on_message(id, value):
    if id.endswith(str(Led)) == True:
        value = value.lower()                           #make certain that the value is in lower case, for 'True' vs 'true'
        if value == "true":
            grovepi.digitalWrite(Led, 1)
            IOT.send("true", Led)                #provide feedback to the cloud that the operation was succesful
        elif value == "false":
            grovepi.digitalWrite(Led, 0)
            IOT.send("false", Led)               #provide feedback to the cloud that the operation was succesful
        else:
            print("unknown value: " + value)
Esempio n. 7
0
def setBacklight(value):
    '''turn on/off the backlight
       value: string ('true' or 'false')
       returns: true when input was succesfully processed, otherwise false
    '''
    if value == "true":
        GPIO.output(LISIPAROIPin, GPIO.HIGH)
    elif value == "false":
        GPIO.output(LISIPAROIPin, GPIO.LOW)
    else:
        print("unknown value: " + value)
    IOT.send(value, ToggleLISIPAROIId)                #provide feedback to the cloud that the operation was succesful
Esempio n. 8
0
def SwitchLightsOff():
    """Switch the lights off"""
    global LightRelaisState
    try:
        LightRelaisState = False
        GPIO.output(LightsRelaisPin, True)  # pin is reversed value
        if (
            IsConnected
        ):  # no need to try and send the state if not yet connected, will be updated when connection is successfull
            IOT.send("false", LightsRelaisPin)
    except:
        logging.exception("failed to switch lights off")
Esempio n. 9
0
def TurnWaterOn():
    global WaterRelaisState
    """Turn the water on"""
    try:
        GPIO.output(WaterRelaisPin, False)  # pin takes reversed value.
        WaterRelaisState = True
        if (
            IsConnected
        ):  # no need to try and send the state if not yet connected, will be updated when connection is successfull
            IOT.send("true", WaterRelaisPin)
    except:
        logging.exception("failed to turn water on")
Esempio n. 10
0
def setRecord(value):
    if _isPreview: 
        print("preview not allowed during recording, shutting down preview.")
        setPreview(False)
    if value == "true":
        camera.resolution = (1920, 1080)              #set to max resulotion for record
        camera.start_recording('video' + datetime.date.today().strftime("%d_%b_%Y_%H_%M%_S") + '.h264')
    elif value == "false":
        camera.stop_recording()
        camera.resolution = (640, 480)              #reset resulotion for preview
    else:
        print("unknown value: " + value)
    IOT.send(value, RecordId)                #provide feedback to the cloud that the operation was succesful
Esempio n. 11
0
def setPreview(value):
    if _isRecording:
        print("recording not allowed during preview, shutting down recording.")
        setRecord(False)
    if value == "true":
        _isPreview = True
        streamer.start_preview()
    elif value == "false":
        _isPreview = False
        streamer.stop_preview()
    else:
        print("unknown value: " + value)
    IOT.send(value, PreviewId)                #provide feedback to the cloud that the operation was succesful
def setBacklight(value):
    '''turn on/off the backlight
       value: string ('true' or 'false')
       returns: true when input was succesfully processed, otherwise false
    '''
    if value == "true":
        GPIO.output(LISIPAROIPin, GPIO.HIGH)
    elif value == "false":
        GPIO.output(LISIPAROIPin, GPIO.LOW)
    else:
        print("unknown value: " + value)
    IOT.send(value, ToggleLISIPAROIId
             )  #provide feedback to the cloud that the operation was succesful
Esempio n. 13
0
def TurnWaterOff():
    """Turn the water off"""
    global WaterRelaisState
    try:
        if WaterRelaisState == True:
            GPIO.output(WaterRelaisPin, True)  # pin takes reversed value
            WaterRelaisState = False
            if (
                IsConnected
            ):  # no need to try and send the state if not yet connected, will be updated when connection is successfull
                IOT.send("false", WaterRelaisPin)
    except:
        logging.exception("failed to turn water off")
Esempio n. 14
0
def on_message(id, value):
    if id.endswith(Out1Id) == True:
        value = value.lower()                        #make certain that the value is in lower case, for 'True' vs 'true'
        if value == "true":
            print("true on " + Out1Name)
            IOT.send("true", Out1Id)                #provide feedback to the cloud that the operation was succesful
        elif value == "false":
            print("false on " + Out1Name)
            IOT.send("false", Out1Id)                #provide feedback to the cloud that the operation was succesful
        else:
            print("unknown value: " + value)
    else:
        print("unknown actuator: " + id)
def on_message(actuatorId, value):
    if actuatorId.endswith(actuatorId) == True:
        value = value.lower()                        #make certain that the value is in lower case, for 'True' vs 'true'
        if value == "true":
            GPIO.output(ActuatorPin, True)
            IOT.send("true", ActuatorId)                #provide feedback to the cloud that the operation was succesful
        elif value == "false":
            GPIO.output(ActuatorPin, False)
            IOT.send("false", ActuatorId)                #provide feedback to the cloud that the operation was succesful
        else:
            print("unknown value: " + value)
    else:
        print("unknown actuator: " + actuatorId)
Esempio n. 16
0
def on_message(id, value):
    if id.endswith(str(ActuatorPin)) == True:
        value = value.lower()                        #make certain that the value is in lower case, for 'True' vs 'true'
        if value == "true":
            GPIO.output(ActuatorPin, True)
            IOT.send("true", ActuatorPin)                #provide feedback to the cloud that the operation was succesful
        elif value == "false":
            GPIO.output(ActuatorPin, False)
            IOT.send("false", ActuatorPin)                #provide feedback to the cloud that the operation was succesful
        else:
            print("unknown value: " + value)
    else:
        print("unknown actuator: " + id)
def setPreview(value):
    if _isRecording:
        print("recording not allowed during preview, shutting down recording.")
        setRecord(False)
    if value == "true":
        _isPreview = True
        streamer.start_preview()
    elif value == "false":
        _isPreview = False
        streamer.stop_preview()
    else:
        print("unknown value: " + value)
    IOT.send(value, PreviewId
             )  #provide feedback to the cloud that the operation was succesful
def setRecord(value):
    if _isPreview:
        print("preview not allowed during recording, shutting down preview.")
        setPreview(False)
    if value == "true":
        camera.resolution = (1920, 1080)  #set to max resulotion for record
        camera.start_recording(
            'video' + datetime.date.today().strftime("%d_%b_%Y_%H_%M%_S") +
            '.h264')
    elif value == "false":
        camera.stop_recording()
        camera.resolution = (640, 480)  #reset resulotion for preview
    else:
        print("unknown value: " + value)
    IOT.send(value, RecordId
             )  #provide feedback to the cloud that the operation was succesful
Esempio n. 19
0
def tryConnect():
    global IsConnected
    try:
        networkCheckCount = 0
        while (
            Network.isConnected() == False and networkCheckCount < 5
        ):  # we check a number of times to give the network more time to start up.
            networkCheckCount = networkCheckCount + 1
            sleep(2)
        if Network.isConnected() == False:
            logging.error("failed to set up network connection")
        else:
            # make certain that the device & it's features are defined in the cloudapp
            IOT.connect()
            # IOT.addAsset(TempSensorPin, TempSensorName, "temperature", False, "number", "Secondary")
            # IOT.addAsset(WaterLevelSensorPin, WaterLevelSensorName, "Water level", False, "number", "Secondary")
            IOT.addAsset(LightsRelaisPin, LightsRelaisName, "Turn the lights on/off", True, "boolean", "Primary")
            IOT.addAsset(WaterRelaisPin, WaterRelaisName, "Turn the water flow on/off", True, "boolean", "Primary")
            IOT.addAsset(
                ConfigSeasonId,
                ConfigSeasonName,
                "Configure the season",
                True,
                "{'type': 'string','enum': ['grow', 'flower']}",
                "Config",
            )
            try:
                season = IOT.getAssetState(ConfigSeasonId)
            except:
                logging.exception("failed to get asset state")
            LoadConfig(
                season
            )  # load the cloud settings into the appbefore closing the http connection. otherwise this call fails.
            IOT.subscribe()  # starts the bi-directional communication
            sleep(
                2
            )  # wait 2 seconds until the subscription has succeeded (bit of a hack, better would be to use the callback)
            IsConnected = True
            IOT.send(
                str(LightRelaisState).lower(), LightsRelaisPin
            )  # provide feedback to the platform of the current state of the light (after startup), this failed while loading config, cause mqtt is not yet set up.
            IOT.send(str(WaterRelaisState).lower(), WaterRelaisPin)
    except:
        logging.exception("failed to set up the connection with the cloud")
        IsConnected = False
Esempio n. 20
0
def on_message(id, value):
    if id.endswith(str(ToggleLISIPAROIId)) == True:
        value = value.lower()                        #make certain that the value is in lower case, for 'True' vs 'true'
        setBacklight(value)
    elif id.endswith(str(PreviewId)) == True:
        value = value.lower()                        #make certain that the value is in lower case, for 'True' vs 'true'
        setPreview(value)
    elif id.endswith(str(RecordId)) == True:
        value = value.lower()                        #make certain that the value is in lower case, for 'True' vs 'true'
        setRecord(value)
    elif id.endswith(str(StreamServerId)) == True:
        streamer.streamServerIp = value
        IOT.send(value, StreamServerId)                #provide feedback to the cloud that the operation was succesful
    elif id.endswith(str(PictureId)) == True:
        if value.lower() == "true":
            takePicture()
    else:
        print("unknown actuator: " + id)
Esempio n. 21
0
def setConfigSeason(value):
    try:
        global scheduler
        IOT.send(
            value, ConfigSeasonId
        )  # first return value, in case something went wrong, the config is first stored, so upon restart, the correct config is retrieved.
        configs = ConfigParser()  # save the configuration
        configs.set("general", "season", value)
        with open(ConfigFile, "w") as f:
            configs.write(f)
        if scheduler:
            scheduler.shutdown(
                wait=False
            )  # stop any pending jobs so we can recreate them with the new config later on.
            scheduler = None
        SetClock(value.lower())
        StartScheduler()
    except:
        logging.exception("failed to store new season config")
Esempio n. 22
0
def setConfigSeason(value):
    try:
        global scheduler
        IOT.send(
            value, ConfigSeasonId
        )  #first return value, in case something went wrong, the config is first stored, so upon restart, the correct config is retrieved.
        configs = ConfigParser()  # save the configuration
        configs.set('general', 'season', value)
        with open(ConfigFile, 'w') as f:
            configs.write(f)
        if scheduler:
            scheduler.shutdown(
                wait=False
            )  # stop any pending jobs so we can recreate them with the new config later on.
            scheduler = None
        SetClock(value.lower())
        StartScheduler()
    except:
        logging.exception('failed to store new season config')
Esempio n. 23
0
def tryConnect():
    global IsConnected
    try:
        networkCheckCount = 0
        while Network.isConnected(
        ) == False and networkCheckCount < 5:  # we check a number of times to give the network more time to start up.
            networkCheckCount = networkCheckCount + 1
            sleep(2)
        if Network.isConnected() == False:
            logging.error("failed to set up network connection")
        else:
            #make certain that the device & it's features are defined in the cloudapp
            IOT.connect()
            #IOT.addAsset(TempSensorPin, TempSensorName, "temperature", False, "number", "Secondary")
            #IOT.addAsset(WaterLevelSensorPin, WaterLevelSensorName, "Water level", False, "number", "Secondary")
            IOT.addAsset(LightsRelaisPin, LightsRelaisName,
                         "Turn the lights on/off", True, "boolean", "Primary")
            IOT.addAsset(WaterRelaisPin, WaterRelaisName,
                         "Turn the water flow on/off", True, "boolean",
                         "Primary")
            IOT.addAsset(ConfigSeasonId, ConfigSeasonName,
                         "Configure the season", True,
                         "{'type': 'string','enum': ['grow', 'flower']}",
                         'Config')
            try:
                season = IOT.getAssetState(ConfigSeasonId)
            except:
                logging.exception('failed to get asset state')
            LoadConfig(
                season
            )  # load the cloud settings into the appbefore closing the http connection. otherwise this call fails.
            IOT.subscribe()  #starts the bi-directional communication
            sleep(
                2
            )  # wait 2 seconds until the subscription has succeeded (bit of a hack, better would be to use the callback)
            IsConnected = True
            IOT.send(
                str(LightRelaisState).lower(), LightsRelaisPin
            )  # provide feedback to the platform of the current state of the light (after startup), this failed while loading config, cause mqtt is not yet set up.
            IOT.send(str(WaterRelaisState).lower(), WaterRelaisPin)
    except:
        logging.exception("failed to set up the connection with the cloud")
        IsConnected = False
def setupCloud():
    IOT.on_message = on_message
    #make certain that the device & it's features are defined in the cloudapp
    IOT.connect()
    if hasLISIPAROI:
        IOT.addAsset(ToggleLISIPAROIId, "LISIPAROI",
                     "Control the light on the camera", False, "boolean")
    IOT.addAsset(
        PreviewId, "Preview",
        "Show/close a preview on the monitor that is connected to the RPI",
        True, "boolean")
    IOT.addAsset(RecordId, "Record",
                 "Start/stop recording the video stream on sd-card", True,
                 "boolean")
    IOT.addAsset(PictureId, "Picture",
                 "take a picture (max resoution) and store on sd-card", True,
                 "boolean")
    IOT.addAsset(StreamServerId, "Stream server",
                 "set the ip address of the server that manages the video",
                 True, "string")

    # get any previously defined settings
    streamer.streamServerIp = IOT.getAssetState(StreamServerId)
    if streamer.streamServerIp:
        streamer.streamServerIp = streamer.streamServerIp['state']['value']
        logging.info("sending stream to: " + streamer.streamServerIp)
    else:
        logging.info("no stream endpoint defined")

    IOT.subscribe()  #starts the bi-directional communication
    # set current state of the device
    IOT.send("false", ToggleLISIPAROIId)
    IOT.send("false", PreviewId)
    IOT.send("false", RecordId)
def on_message(id, value):
    if id.endswith(str(ToggleLISIPAROIId)) == True:
        value = value.lower(
        )  #make certain that the value is in lower case, for 'True' vs 'true'
        setBacklight(value)
    elif id.endswith(str(PreviewId)) == True:
        value = value.lower(
        )  #make certain that the value is in lower case, for 'True' vs 'true'
        setPreview(value)
    elif id.endswith(str(RecordId)) == True:
        value = value.lower(
        )  #make certain that the value is in lower case, for 'True' vs 'true'
        setRecord(value)
    elif id.endswith(str(StreamServerId)) == True:
        streamer.streamServerIp = value
        IOT.send(
            value, StreamServerId
        )  #provide feedback to the cloud that the operation was succesful
    elif id.endswith(str(PictureId)) == True:
        if value.lower() == "true":
            takePicture()
    else:
        print("unknown actuator: " + id)
Esempio n. 26
0
def setupCloud():
    IOT.on_message = on_message
    #make certain that the device & it's features are defined in the cloudapp
    IOT.connect()
    if hasLISIPAROI:
        IOT.addAsset(ToggleLISIPAROIId, "LISIPAROI", "Control the light on the camera", False, "boolean")
    IOT.addAsset(PreviewId, "Preview", "Show/close a preview on the monitor that is connected to the RPI", True, "boolean")
    IOT.addAsset(RecordId, "Record", "Start/stop recording the video stream on sd-card", True, "boolean")
    IOT.addAsset(PictureId, "Picture", "take a picture (max resoution) and store on sd-card", True, "boolean")
    IOT.addAsset(StreamServerId, "Stream server", "set the ip address of the server that manages the video", True, "string")

    # get any previously defined settings
    streamer.streamServerIp = IOT.getAssetState(StreamServerId)
    if streamer.streamServerIp:
        streamer.streamServerIp = streamer.streamServerIp['state']['value']
        logging.info("sending stream to: " + streamer.streamServerIp)
    else:
        logging.info("no stream endpoint defined")

    IOT.subscribe()              							#starts the bi-directional communication
    # set current state of the device
    IOT.send("false", ToggleLISIPAROIId)
    IOT.send("false", PreviewId)
    IOT.send("false", RecordId)
Esempio n. 27
0
        value = value.lower()

        if value == "true":
            print "ON"
            grovepi.digitalWrite( LED, 1 )

        if value == "false":
            print "OFF"
            grovepi.digitalWrite( LED, 0 )

    # ignore unkown ids and values                                                                                                                                               

#make certain that the device & it's features are defined in the cloudapp
IOT.on_message = on_message
IOT.connect()
IOT.addAsset(lightSensor, "lightSensor", "Light Sensor", False, "integer")
IOT.addAsset( LED, "LED", "Light Emitting Diode", True, "boolean" )
IOT.subscribe()              							#starts the bi-directional communication

#main loop: run as long as the device is turned on
while True:
    try:
        lightValue =  grovepi.analogRead(lightSensor)
        print( "LightSensor = " + str(lightValue))
        IOT.send(lightValue, lightSensor)
        sleep(5)

    except IOError:
        print ""
Esempio n. 28
0
import ATT_IOT as IOT 							   #provide cloud support
from time import sleep                             #pause the app

#set up the SmartLiving IoT platform
IOT.DeviceId = ""
IOT.ClientId = ""
IOT.ClientKey = ""

lightSensor = 0                                  #the PIN number of the lichtsensor, also used to construct a Unique assetID (DeviceID+nr)

#set up the pins
grovepi.pinMode(lightSensor,"INPUT")

#callback: handles values sent from the cloudapp to the device

#make certain that the device & it's features are defined in the cloudapp
IOT.connect()
IOT.addAsset(lightSensor, "lightSensor", "Light Sensor", False, "integer")
IOT.subscribe()              							#starts the bi-directional communication

#main loop: run as long as the device is turned on
while True:
    try:
        lightValue =  grovepi.analogRead(lightSensor)
        print( "LightSensor = " + str(lightValue))
        IOT.send(lightValue, lightSensor)
        sleep(5)

    except IOError:
        print ""
Esempio n. 29
0
        if value == "true":
            GPIO.output(ActuatorPin, True)
            IOT.send("true", ActuatorPin)                #provide feedback to the cloud that the operation was succesful
        elif value == "false":
            GPIO.output(ActuatorPin, False)
            IOT.send("false", ActuatorPin)                #provide feedback to the cloud that the operation was succesful
        else:
            print("unknown value: " + value)
    else:
        print("unknown actuator: " + id)
IOT.on_message = on_message

#make certain that the device & it's features are defined in the cloudapp
IOT.connect()
IOT.addAsset(SensorPin, SensorName, "Push button", False, "boolean")
IOT.addAsset(ActuatorPin, ActuatorName, "Light Emitting Diode", True, "boolean")
IOT.subscribe()              							#starts the bi-directional communication

#main loop: run as long as the device is turned on
while True:
    if GPIO.input(SensorPin) == 0:                        #for PUD_DOWN, == 1
        if SensorPrev == False:
            print(SensorName + " activated")
            IOT.send("true", SensorPin)
            SensorPrev = True
    elif SensorPrev == True:
        print(SensorName + " deactivated")
        IOT.send("false", SensorPin)
        SensorPrev = False
    sleep(1)
        if value == "true":
            grovepi.digitalWrite(actuatorPin, 1)
            IOT.send("true", actuatorId)                #provide feedback to the cloud that the operation was succesful
        elif value == "false":
            grovepi.digitalWrite(actuatorPin, 0)
            IOT.send("false", actuatorId)               #provide feedback to the cloud that the operation was succesful
        else:
            print("unknown value: " + value)
    else:
        print("unknown actuator: " + id)
IOT.on_message = on_message

#make certain that the device & it's features are defined in the cloudapp
IOT.connect()
IOT.addAsset(sensorId, sensorName, "Push button", False, "bool")
IOT.addAsset(actuatorId, actuatorName, "Light Emitting Diode", True, "bool")
IOT.subscribe()              							#starts the bi-directional communication

#main loop: run as long as the device is turned on
while True:
    if grovepi.digitalRead(sensorPin) == 1:
        if sensorPrev == False:
            print(sensorName + " activated")
            IOT.send("true", sensorId)
            sensorPrev = True
    elif sensorPrev == True:
        print(sensorName + " deactivated")
        IOT.send("false", sensorId)
        sensorPrev = False
    sleep(.3)
Esempio n. 31
0
doorBell = 2						# The Pin number of the Shield, also used to construct the AssetID



#set up the pins
grovepi.pinMode(doorBell,"INPUT")

#callback: handles values sent from the cloudapp to the device

#make certain that the device & it's features are defined in the cloudapp
IOT.connect()
IOT.addAsset(doorBell, "DoorBell", "DoorBell", False, "boolean")
IOT.subscribe()                                                                 #starts the bi-directional communication

#main loop: run as long as the device is turned on
while True:
    try:
        if grovepi.digitalRead(doorBell) == 1:
            if sensorPrev == False:
                print("DoorBell  activated")
                IOT.send("true", doorBell)
                sensorPrev = True
        elif sensorPrev == True:
            print("DoorBell  deactivated")
            IOT.send("false", doorBell)
            sensorPrev = False
        sleep(.3)

    except IOError:
        print ""
            )  #provide feedback to the cloud that the operation was succesful
        else:
            print("unknown value: " + value)
    else:
        print("unknown actuator: " + id)


IOT.on_message = on_message

#make certain that the device & it's features are defined in the cloudapp
IOT.connect()
IOT.addAsset(sensorPin, sensorName, "Push button", False, "bool")
IOT.addAsset(actuatorPin, actuatorName, "Light Emitting Diode", True, "bool")
IOT.subscribe()  #starts the bi-directional communication

#main loop: run as long as the device is turned on
while True:
    try:
        if grovepi.digitalRead(sensorPin) == 1:
            if sensorPrev == False:
                print(sensorName + " activated")
                IOT.send("true", sensorPin)
                sensorPrev = True
        elif sensorPrev == True:
            print(sensorName + " deactivated")
            IOT.send("false", sensorPin)
            sensorPrev = False
        sleep(.3)

    except IOError:
        print ""
Esempio n. 33
0
            print "h-ON"
            grovepi.digitalWrite( heaterRELAY, 1 )
        if value == "false":
            print "h-OFF"
            grovepi.digitalWrite( heaterRELAY, 0 )

    # ignore unkown ids and values                                                                                                                                               

#make certain that the device & it's features are defined in the cloudapp
IOT.on_message = on_message
IOT.connect()
IOT.addAsset(tempSENSOR, "tempSENSOR", "Temperature Sensor", False, "float")
IOT.addAsset(humSENSOR, "humSENSOR", "Humidity Sensor", False, "float")
IOT.addAsset( lightRELAY, "lightRELAY", "Light Switch", True, "boolean" )
IOT.addAsset( heaterRELAY, "heaterRELAY", "Heater Switch", True, "boolean" )
IOT.subscribe()              							#starts the bi-directional communication

#main loop: run as long as the device is turned on
while True:
    try:
        [temp, hum]=grovepi.dht(tempSENSOR,0)
        print( "t=",temp," h=",hum)
        IOT.send(temp, tempSENSOR)
        IOT.send(hum, humSENSOR)
        sleep(1)

    except IOError:
        print ""
    except TypeError:
        print ""
Esempio n. 34
0
        elif value == "false":
            print("false on " + Out1Name)
            IOT.send(
                "false", Out1Id
            )  #provide feedback to the cloud that the operation was succesful
        else:
            print("unknown value: " + value)
    else:
        print("unknown actuator: " + id)


IOT.on_message = on_message

#make certain that the device & it's features are defined in the cloudapp
IOT.connect()
IOT.addAsset(In1Id, In1Name, "put your description here", False, "boolean")
IOT.addAsset(Out1Id, Out1Name, "put your description here", True, "boolean")
IOT.subscribe()  #starts the bi-directional communication

nextVal = True
#main loop: run as long as the device is turned on
while True:
    if nextVal == True:
        print(In1Name + " activated")
        IOT.send("true", In1Id)
        nextVal = False
    else:
        print(In1Name + " deactivated")
        IOT.send("false", In1Id)
        nextVal = True
    sleep(5)
Esempio n. 35
0
            grovepi.digitalWrite(heaterRELAY, 1)
        if value == "false":
            print "h-OFF"
            grovepi.digitalWrite(heaterRELAY, 0)

    # ignore unkown ids and values


#make certain that the device & it's features are defined in the cloudapp
IOT.on_message = on_message
IOT.connect()
IOT.addAsset(tempSENSOR, "tempSENSOR", "Temperature Sensor", False, "float")
IOT.addAsset(humSENSOR, "humSENSOR", "Humidity Sensor", False, "float")
IOT.addAsset(lightRELAY, "lightRELAY", "Light Switch", True, "boolean")
IOT.addAsset(heaterRELAY, "heaterRELAY", "Heater Switch", True, "boolean")
IOT.subscribe()  #starts the bi-directional communication

#main loop: run as long as the device is turned on
while True:
    try:
        [temp, hum] = grovepi.dht(tempSENSOR, 0)
        print("t=", temp, " h=", hum)
        IOT.send(temp, tempSENSOR)
        IOT.send(hum, humSENSOR)
        sleep(1)

    except IOError:
        print ""
    except TypeError:
        print ""
Esempio n. 36
0
            IOT.send("false", Out1Id)                #provide feedback to the cloud that the operation was succesful
        else:
            print("unknown value: " + value)
    else:
        print("unknown actuator: " + id)

#set up the ATT internet of things platform
IOT.on_message = on_message
IOT.ClientId = "put your client id here"
IOT.ClientKey = "put your client key here"
IOT.DeviceId = "put your device id here"
IOT.BrokerUserId = "put your username for the broker here"

#make certain that the device & it's features are defined in the cloudapp
IOT.connect()
IOT.addAsset(In1Id, In1Name, "put your description here", False, "bool")
IOT.addAsset(Out1Id, Out1Name, "put your description here", True, "bool")
IOT.subscribe()                                        		#starts the bi-directional communication

nextVal = True;
#main loop: run as long as the device is turned on
while True:
    if nextVal == True:
        print(In1Name + " activated")
        IOT.send("true", In1Id)
        nextVal = False
    else:
        print(In1Name + " deactivated")
        IOT.send("false", In1Id)
        nextVal = True
    sleep(5)
#Define each asset below. provide a Name and Pin. The Pin number is used to define the Pin number on your raspberry Pi shield
#and to create a unique assetId which is a combination of deviceID+Pin number. The Pin number can be any value between (0 - 2^63)

sensorName = "Button"            		    #name of the sensor
sensorPin = 2
sensorPrev = False                                  #previous value of the sensor (only send a value when a change occured)


#set up the pins

#callback: handles values sent from the cloudapp to the device
def on_message(id, value):
    print("unknown actuator: " + id)

IOT.on_message = on_message

#make certain that the device & it's features are defined in the cloudapp
IOT.connect()
IOT.addAsset(sensorPin, sensorName, "location info", False, "{\"type\": \"object\",\"properties\": {\"latitude\": { \"type\": \"number\" },\"longitude\": { \"type\": \"number\" }}}")
IOT.subscribe()              							#starts the bi-directional communication

#main loop: run as long as the device is turned on
while True:
    try:
        value = {'latitude': 1, 'longitude': 2}
        IOT.send(value, sensorPin)
        sleep(2)

    except IOError:
        print ""
Esempio n. 38
0
            IOT.send("false", Led)               #provide feedback to the cloud that the operation was succesful
        else:
            print("unknown value: " + value)
    else:
        print("unknown actuator: " + id)
IOT.on_message = on_message

#make certain that the device & it's features are defined in the cloudapp
IOT.connect()
IOT.addAsset(Pir, "PIR", "PIR SENSOR", False, "boolean")
IOT.addAsset(Led, "LED", "Light Emitting Diode", True, "boolean")
IOT.subscribe()                                                                 #starts the bi-directional communication

#main loop: run as long as the device is turned on
while True:
    try:
        if grovepi.digitalRead(Pir) == 1:
            if Pir_Prev == False:
                print("PIR activated")
                IOT.send("true", Pir)
                Pir_Prev = True
        elif Pir_Prev == True:
            print("PIR deactivated")
            IOT.send("false", Pir)
            Pir_Prev = False
        sleep(.3)

    except IOError:
        print ""

            IOT.send("false", Led)               #provide feedback to the cloud that the operation was succesful
        else:
            print("unknown value: " + value)
    else:
        print("unknown actuator: " + id)
IOT.on_message = on_message

#make certain that the device & it's features are defined in the cloudapp
IOT.connect()
IOT.addAsset(Pir, "PIR", "PIR SENSOR", False, "bool")
IOT.addAsset(Led, "LED", "Light Emitting Diode", True, "bool")
IOT.subscribe()                                                                 #starts the bi-directional communication

#main loop: run as long as the device is turned on
while True:
    try:
        if grovepi.digitalRead(Pir) == 1:
            if Pir_Prev == False:
                print("PIR activated")
                IOT.send("true", Pir)
                Pir_Prev = True
        elif Pir_Prev == True:
            print("PIR deactivated")
            IOT.send("false", Pir)
            Pir_Prev = False
        sleep(.3)

    except IOError:
        print ""

sensorPrev = False

doorBell = 2  # The Pin number of the Shield, also used to construct the AssetID

#set up the pins
grovepi.pinMode(doorBell, "INPUT")

#callback: handles values sent from the cloudapp to the device

#make certain that the device & it's features are defined in the cloudapp
IOT.connect()
IOT.addAsset(doorBell, "DoorBell", "DoorBell", False, "bool")
IOT.subscribe()  #starts the bi-directional communication

#main loop: run as long as the device is turned on
while True:
    try:
        if grovepi.digitalRead(doorBell) == 1:
            if sensorPrev == False:
                print("DoorBell  activated")
                IOT.send("true", doorBell)
                sensorPrev = True
        elif sensorPrev == True:
            print("DoorBell  deactivated")
            IOT.send("false", doorBell)
            sensorPrev = False
        sleep(.3)

    except IOError:
        print ""
Esempio n. 41
0
In1Name = "Put the name of your sensor"                                #name of the button
In1Id = 1                                                            #the id of the button, don't uses spaces. required for the att platform
Out1Name = "Put the name of your actuator"
Out1Id = 2


#callback: handles values sent from the cloudapp to the device
def on_message(id, value):
    global nextVal
    if id.endswith(str(Out1Id)) == True:			
        print("value received: " + value)		  # the value that we receive from the cloud is a string
        IOT.send(value, Out1Id)                #provide feedback to the cloud that the operation was successful, the value is still a string, so we can simply send it back to the cloud.
        nextVal = int(value)					# convert the received data, which is a string, into an integer
    else:
        print("unknown actuator: " + id)
IOT.on_message = on_message

#make certain that the device & it's features are defined in the cloudapp
IOT.connect()
IOT.addAsset(In1Id, In1Name, "put your description here", False, "integer")
IOT.addAsset(Out1Id, Out1Name, "put your description here", True, "integer")
IOT.subscribe()                                        		#starts the bi-directional communication

nextVal = 0
#main loop: run as long as the device is turned on
while True:
    print("value: " + str(nextVal))
    IOT.send(str(nextVal), In1Id)
    nextVal = nextVal + 1
    sleep(5)