コード例 #1
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)
コード例 #2
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)
コード例 #3
0
ファイル: GrowMachine.py プロジェクト: ATT-JBO/GrowMachine
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
コード例 #4
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
コード例 #5
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)
コード例 #6
0
ファイル: STITsh.py プロジェクト: refap3/refAP3repo
            grovepi.digitalWrite( lightRELAY, 0 )
    if id.endswith( str( heaterRELAY ) ):
        value = value.lower()
        if value == "true":
            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:
コード例 #7
0
ファイル: ledserver.py プロジェクト: refap3/refAP3repo
        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                                                                                                                                               

if __name__ == '__main__':

  grovepi.pinMode( LED, 'output' )

  IOT.DeviceId   = "b8klgjaOEbLaCvncEX421VM"
  IOT.ClientId   = "itirockz"
  IOT.ClientKey  = "rcwenbi3ssg"

  IOT.on_message = on_message

  IOT.connect()
  IOT.addAsset( LED, "LED", "Light Emitting Diode", True, "boolean" )
  IOT.subscribe()

  while True:
      time.sleep( .1 )

コード例 #8
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)
コード例 #9
0
ファイル: lightsensor.py プロジェクト: miodragArsic/first-app
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 ""
コード例 #10
0
ファイル: shopWindow.py プロジェクト: miodragArsic/first-app

Led = 4

#set up the pins
grovepi.pinMode(Led,"OUTPUT")


#callback: handles values sent from the cloudapp to the device
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)
IOT.on_message = on_message

#make certain that the device & it's features are defined in the cloudapp
IOT.connect()
IOT.addAsset(Led, "Shop Light", "Shop Window Light", True, "boolean")
IOT.subscribe()                                                                 #starts the bi-directional communication

#main loop: run as long as the device is turned on
while True:
    sleep(.3)
コード例 #11
0
def on_message(id, value):
    if id.endswith(str(vMotor)) == True:
        value = value.lower(
        )  #make certain that the value is in lower case, for 'True' vs 'true'
        if value == "true":
            grovepi.digitalWrite(vMotor, 1)
            IOT.send(
                "true", vMotor
            )  #provide feedback to the cloud that the operation was succesful
        elif value == "false":
            grovepi.digitalWrite(vMotor, 0)
            IOT.send(
                "false", vMotor
            )  #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(vMotor, "vMotor", "Vibration Motor", True, "boolean")
IOT.subscribe()  #starts the bi-directional communication

#main loop: run as long as the device is turned on
while True:
    sleep(.3)
コード例 #12
0
        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)
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 GPIO.input(SensorPin) == 0:                        #for PUD_DOWN, == 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(1)
コード例 #13
0
    if id.endswith(str(heaterRELAY)):
        value = value.lower()
        if value == "true":
            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:
コード例 #14
0
vMotor = 2                                     # Shield pin nr & construct for AssetID

#set up the pins
grovepi.pinMode(vMotor,"OUTPUT")


#callback: handles values sent from the cloudapp to the device
def on_message(id, value):
    if id.endswith(str(vMotor)) == True:
        value = value.lower()                           #make certain that the value is in lower case, for 'True' vs 'true'
        if value == "true":
            grovepi.digitalWrite(vMotor, 1)
            IOT.send("true", vMotor)                #provide feedback to the cloud that the operation was succesful
        elif value == "false":
            grovepi.digitalWrite(vMotor, 0)
            IOT.send("false", vMotor)               #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(vMotor, "vMotor", "Vibration Motor", True, "boolean")
IOT.subscribe()                                                                 #starts the bi-directional communication

#main loop: run as long as the device is turned on
while True:
    sleep(.3)
コード例 #15
0
ファイル: doorbell.py プロジェクト: miodragArsic/first-app
IOT.ClientKey = ""

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, "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)
コード例 #16
0
sensorPin = 5

actuatorPin = 6

#set up the pins
grovepi.pinMode(sensorPin,"INPUT")
grovepi.pinMode(actuatorPin,"OUTPUT")

#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, "Push button", False, "boolean")
IOT.subscribe()    

IOT.send("false", sensorPin)

buttonVal = False;
sensorVal = False;
while True:
  try:
    sensorRead = grovepi.digitalRead(sensorPin)
    if sensorRead == 255:
      continue
    if sensorVal != sensorRead:
      sensorVal = sensorRead
      if sensorVal:
        buttonVal = not buttonVal
コード例 #17
0
#callback: handles values sent from the cloudapp to the device
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)


IOT.on_message = on_message

#make certain that the device & it's features are defined in the cloudapp
IOT.connect()
IOT.addAsset(Led, "Shop Light", "Shop Window Light", True, "boolean")
IOT.subscribe()  #starts the bi-directional communication

#main loop: run as long as the device is turned on
while True:
    sleep(.3)
コード例 #18
0
#print inlist

IOT.connect()

encoding = False
#IOT.deleteDeviceAll()
#print "deleted all devices*************************!!!!!"

##### add assets to sample devices
#### sample arduino DeviceId
#### sample Edison DeviceId
#### sample Raspberry DeviceId
IOT.DeviceId = "ucbSbmSsfTS3MpDOdP780pW"
IOT.connect()
#IOT.subscribe()
IOT.addAsset(0, "Pressure sensor", "Pressure sensor in inches", False,
             "number", "Undefined")
IOT.addAsset(1, "Lock On/Off sensor", "Digital lock on or off", False,
             "boolean", "Undefined")
IOT.sendValueHTTP(15, 0)
IOT.sendValueHTTP("True", 1)


def sendSamplepack():
    ## send values to Sample sensor
    ## sample Arduino
    IOT.DeviceId = "ucbSbmSsfTS3MpDOdP780pW"
    IOT.connect()
    val = random.uniform(29, 31)
    IOT.sendValueHTTP(val, 0)
    sleep(2)
    val = randint(0, 1)
コード例 #19
0
ファイル: lightsensor.py プロジェクト: refap3/refAP3repo
        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 ""
コード例 #20
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 = ""

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

#set up the pins
grovepi.pinMode(lichtSensor,"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(lichtSensor, "lichtSensor", "Licht Sensor", False, "int")
IOT.subscribe()              							#starts the bi-directional communication

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

    except IOError:
        print ""
コード例 #21
0
E= [E0,E1,E2,E3]

inlist= [N,R,A,E]
#print inlist

#
IOT.connect()

##### add assets to sample devices
#### sample arduino DeviceId
#### sample Edison DeviceId
#### sample Raspberry DeviceId
IOT.DeviceId = "ucbSbmSsfTS3MpDOdP780pW"
IOT.connect()
#IOT.subscribe()
IOT.addAsset(0, "Pressure sensor", "Pressure sensor in inches", False, "number", "Undefined")
IOT.addAsset(1, "Lock On/Off sensor", "Digital lock on or off", False, "boolean", "Undefined")
IOT.sendValueHTTP(15,0)
IOT.sendValueHTTP("True",1)

def sendSamplepack():
    ## send values to Sample sensor
    ## sample Arduino
    IOT.DeviceId = "ucbSbmSsfTS3MpDOdP780pW"
    IOT.connect()
    val = random.uniform(29,31)
    IOT.sendValueHTTP(val,0)
    sleep(2)
    val = randint(0,1)
    if val== 0:
        IOT.sendValueHTTP("False",1)
コード例 #22
0
        value = value.lower()                        	#make certain that the value is in lower case, for 'True' vs 'true'
        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)
コード例 #23
0
#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 ""
コード例 #24
0
        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)
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)
コード例 #25
0
def setup():
    """
    Add the watchdog asset to the device.  This can be used as visual feedback for the state of the device.
    """
    IOT.addAsset(WatchDogAssetId, "network watchdog", "used to verify the connectivity with the broker", True, "integer")
コード例 #26
0
        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)
    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
コード例 #27
0
        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)
    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
コード例 #28
0
IOT.DeviceId = ""
IOT.ClientId = ""
IOT.ClientKey = ""

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)
コード例 #29
0
ファイル: drytest.py プロジェクト: refap3/refAP3repo
    if id.endswith( str( LED ) ):

        value = value.lower()

        if value == "true":
            print "ON"

        if value == "false":
            print "OFF"

    # 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
lightValue = 0 
while True:
    try:
        lightValue += 1
        print( "LightSensor = " + str(lightValue))
        IOT.send(lightValue, lightSensor)
        sleep(5)

    except IOError:
        print ""