def ping(): """ Send a ping to the server """ global _nextPingAt _nextPingAt = datetime.datetime.now() + datetime.timedelta(0, PingFrequency) IOT.sendCommandTo(_pingCounter, IOT.DeviceId, WatchDogAssetId)
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)
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')
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')
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)
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')
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")
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")
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
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")
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
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)
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 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
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 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
def setup(mylist): R=int(mylist[1]) A=int(mylist[2]) E=int(mylist[3]) IOT.connect() for x in range(0, R): dtype = "RaspberryPi" + str(x) print("complete device name: "+dtype) devlist=IOT.createDevice(dtype, "lightSensor", True) with open('devicess.txt', 'a') as file_: file_.write(devlist[1] + " "+devlist [0] + '\n') for x in range(0, A): dtype = "Arduino" +str(x) devlist=IOT.createDevice(dtype, "lightSensor", True) with open('devicess.txt', 'a') as file_: file_.write(devlist[1] + " "+devlist [0] + '\n') for x in range(0, E): dtype = "IntelDevice"+str(x) devlist=IOT.createDevice(dtype, "lightSensor", True) with open('devicess.txt', 'a') as file_: file_.write(devlist[1] + " "+devlist [0] + '\n') IOT.deleteDevice()
def setup(mylist): R = int(mylist[1]) A = int(mylist[2]) E = int(mylist[3]) IOT.connect() for x in range(0, R): dtype = "RaspberryPi" + str(x) print("complete device name: " + dtype) devlist = IOT.createDevice(dtype, "lightSensor", True) with open('devicess.txt', 'a') as file_: file_.write(devlist[1] + " " + devlist[0] + '\n') for x in range(0, A): dtype = "Arduino" + str(x) devlist = IOT.createDevice(dtype, "lightSensor", True) with open('devicess.txt', 'a') as file_: file_.write(devlist[1] + " " + devlist[0] + '\n') for x in range(0, E): dtype = "IntelDevice" + str(x) devlist = IOT.createDevice(dtype, "lightSensor", True) with open('devicess.txt', 'a') as file_: file_.write(devlist[1] + " " + devlist[0] + '\n') IOT.deleteDevice()
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)
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')
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")
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) elif val == 1: IOT.sendValueHTTP("True",1) else: pass sleep(2)
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)
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) elif val == 1: IOT.sendValueHTTP("True", 1) else: pass sleep(2)
def sendpack(): ###### sending vallues to created devices results=[] with open('devicess.txt') as inputfile: results = list(csv.reader(inputfile)) str1 = "" for line in results: str1 = ''.join(line) a = str1.split('\t') name= a[0] idd = 0 IOT.DeviceId = str(a[1]) print "This id deviceid:" + '\n' print IOT.DeviceId idd = int(a[3]) IOT.connect() if a[2] == 'T': val = random.uniform(float(a[4]),float(a[5])) IOT.sendValueHTTP(val,idd) #IOT.send(val,idd) sleep(1) elif a[2] == 'L': val = randint(int(a[4]),int(a[5])) IOT.sendValueHTTP(val,idd) sleep(1) elif a[2] == 'D': val = randint(0,1) if val== 0: booll= "True" else: booll = "False" IOT.sendValueHTTP(booll,idd) sleep(1) else : print "Wromg entry"
def sendpack(): ###### sending vallues to created devices results = [] with open('devicess.txt') as inputfile: results = list(csv.reader(inputfile)) str1 = "" for line in results: str1 = ''.join(line) a = str1.split('\t') name = a[0] idd = 0 IOT.DeviceId = str(a[1]) print "This id deviceid:" + '\n' print IOT.DeviceId idd = int(a[3]) IOT.connect() if a[2] == 'T': val = random.uniform(float(a[4]), float(a[5])) IOT.sendValueHTTP(val, idd) #IOT.send(val,idd) sleep(1) elif a[2] == 'L': val = randint(int(a[4]), int(a[5])) IOT.sendValueHTTP(val, idd) sleep(1) elif a[2] == 'D': val = randint(0, 1) if val == 0: booll = "True" else: booll = "False" IOT.sendValueHTTP(booll, idd) sleep(1) else: print "Wromg entry"
#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)
str1 = ''.join(results[3]) a = str1.split('\t') R1 = [a[2], a[3], a[4]] R2 = [a[6], a[7], a[8]] R3 = [a[10]] R = [R0, R1, R2, R3] str1 = "" str1 = ''.join(results[4]) a = str1.split('\t') A1 = [a[2], a[3], a[4]] A2 = [a[6], a[7], a[8]] A3 = [a[10]] A = [A0, A1, A2, A3] str1 = "" str1 = ''.join(results[5]) a = str1.split('\t') E1 = [a[2], a[3], a[4]] E2 = [a[6], a[7], a[8]] E3 = [a[10]] E = [E0, E1, E2, E3] inlist = [N, R, A, E] #print inlist # IOT.connect() sendpack()
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)
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 ""
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) 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
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 ""
) #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) 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
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)
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) #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
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, "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
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 )
) #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)
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
import string import random from random import randint import thread from sys import exit import os IOT.ClientId = "teamoopsindiahacks" IOT.ClientKey ="5zgkgpfpxee" #old setting working #IOT.ClientId = "indiahack_oops" #IOT.ClientKey ="1tbxrq5itbs" IOT.connect() # delete the output file devicess.txt results=[] with open('devicess.txt') as inputfile: results = list(csv.reader(inputfile)) str1 = "" print "inside file read" for line in results: print "inside lines... " str1 = ''.join(line) a = str1.split('\t') name= a[0] idd = 0
print "l-OFF" 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)
if id.endswith(actuatorId) == True: 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
A3=[a[10]] A= [A0,A1,A2,A3] str1 = "" str1 = ''.join(results[5]) a = str1.split('\t') E1=[a[2],a[3],a[4]] E2=[a[6],a[7],a[8]] E3=[a[10]] 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
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 ""
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")
#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 ""
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) 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)
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) 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)
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)
sensorName = "Button" 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:
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
#set up the SmartLiving ioT platform 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
A2 = [a[6], a[7], a[8]] A3 = [a[10]] A = [A0, A1, A2, A3] str1 = "" str1 = ''.join(results[5]) a = str1.split('\t') E1 = [a[2], a[3], a[4]] E2 = [a[6], a[7], a[8]] E3 = [a[10]] E = [E0, E1, E2, E3] inlist = [N, R, A, E] #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,