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 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 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 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])) if (encoding): #val=str(val).encode(encoding='UTF-8','ignore') IOT.sendValueHTTP(val, idd) else: IOT.sendValueHTTP(val, idd) #IOT.send(val,idd) sleep(1) elif a[2] == 'L': val = randint(int(a[4]), int(a[5])) if (encoding): #val=str(val).encode(encoding='UTF-8','ignore') IOT.sendValueHTTP(val, idd) else: IOT.sendValueHTTP(val, idd) sleep(1) elif a[2] == 'D': val = randint(0, 1) if val == 0: booll = "True" else: booll = "False" if (encoding): #booll=str(booll).encode(encoding='UTF-8','ignore') IOT.sendValueHTTP(booll, idd) else: IOT.sendValueHTTP(booll, idd) sleep(1) else: print "Wrong 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])) if(encoding): #val=str(val).encode(encoding='UTF-8','ignore') IOT.sendValueHTTP(val,idd) else: IOT.sendValueHTTP(val,idd) #IOT.send(val,idd) sleep(1) elif a[2] == 'L': val = randint(int(a[4]),int(a[5])) if(encoding): #val=str(val).encode(encoding='UTF-8','ignore') IOT.sendValueHTTP(val,idd) else: IOT.sendValueHTTP(val,idd) sleep(1) elif a[2] == 'D': val = randint(0,1) if val== 0: booll= "True" else: booll = "False" if(encoding): #booll=str(booll).encode(encoding='UTF-8','ignore') IOT.sendValueHTTP(booll,idd) else: IOT.sendValueHTTP(booll,idd) sleep(1) else : print "Wrong entry"
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 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 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 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 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 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)
#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
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