def loop(): # toggle off if (GPIO.digitalRead(DOOR) == GPIO.HIGH): logger.info("sending LOW signal") webiopi.sleep(1) GPIO.digitalWrite(DOOR, GPIO.LOW)
def loop(): global door_open, kiosk_open, lock_open, lock_opened, t1, t2, t3 lock_opened = mc.get("lock_opened") kiosk_open = mc.get("kiosk_open") # retrieve current datetime now = datetime.datetime.now() if GPIO.digitalRead(T1) == GPIO.LOW and t1: t1 = False # Drawer 1 closed if GPIO.digitalRead(T1) == GPIO.HIGH and not t1: t1 = True # Drawer 1 open if GPIO.digitalRead(T2) == GPIO.LOW and t2: t2 = False # Drawer 2 closed if GPIO.digitalRead(T2) == GPIO.HIGH and not t2: t2 = True # Drawer 2 open if GPIO.digitalRead(T3) == GPIO.LOW and t3: t3 = False # Drawer 3 closed if GPIO.digitalRead(T3) == GPIO.HIGH and not t3: t3 = True # Drawer 3 open if not kiosk_open: if GPIO.digitalRead(DOOR) == GPIO.HIGH and not door_open: door_open = True # We have an intrusion if GPIO.digitalRead(DOOR) == GPIO.LOW and door_open: door_open = False # Intrusion ended if kiosk_open: if GPIO.digitalRead(DOOR) == GPIO.HIGH and not door_open: door_open = True # Kiosk opened if GPIO.digitalRead(DOOR) == GPIO.LOW and door_open: door_open = False kiosk_open = False mc.set("kiosk_open", kiosk_open) if GPIO.digitalRead(LOCK) == GPIO.LOW: GPIO.digitalWrite(LOCK, GPIO.HIGH) lock_open = False # Kiosk closed if GPIO.digitalRead(LOCK) == GPIO.LOW and lock_opened < datetime.datetime.now() - datetime.timedelta(seconds=6): GPIO.digitalWrite(LOCK, GPIO.HIGH) lock_open = False # gives CPU some time before looping again webiopi.sleep(1)
def loop(): while True: try: updatedb() webiopi.sleep(1) except: continue
def loop(): global schedule global currentShow global showStartTime #webiopi.debug("loop... schedule count: " + str(len(schedule))) if len(schedule) > 0: #webiopi.debug("running schedule") currentTime = int(time.time()) if (currentShow == -1) or ((currentTime - showStartTime) > schedule[currentShow].length): # currentShow == -1 means we're starting a schedule for the first time... give time to fade out of previous if (currentShow == -1): time.sleep(2) currentShow += 1 if (currentShow >= len(schedule)): currentShow = 0 showStartTime = currentTime webiopi.debug("next show: " + schedule[currentShow].program + " for " + str(schedule[currentShow].length) + " seconds"); if (schedule[currentShow].program != 'fadeout'): serial.writeString("program ") else: serial.writeString("push ") serial.writeString(schedule[currentShow].program) if (schedule[currentShow].program != 'fadeout'): serial.writeString(" fadein") serial.writeString("\r") webiopi.sleep(1)
def loop(): if (serialUSB.available() > 0): try: data = serialUSB.readString() except: pass lines = data.split("\r\n") count = len(lines) lines = lines[0:count - 1] for pair in lines: cv = pair.split("=") try: channel = int(cv[0]) except: pass try: value = cv[1] except: pass try: sensors[channel] = value except: pass webiopi.sleep(1)
def loop(): # retrieve current datetime now = datetime.datetime.now() # toggle light ON all days at the correct time if ((now.hour == HOUR_ON) and (now.minute == 0) and (now.second == 0)): if (GPIO.digitalRead(FRONT) == GPIO.HIGH): GPIO.digitalWrite(FRONT, GPIO.LOW) # toggle light ON all days at the correct time if ((now.hour == HOUR_ON) and (now.minute == 0) and (now.second == 20)): if (GPIO.digitalRead(BACK) == GPIO.HIGH): GPIO.digitalWrite(BACK, GPIO.LOW) # toggle light OFF if ((now.hour == HOUR_OFF) and (now.minute == 0) and (now.second == 0)): if (GPIO.digitalRead(FRONT) == GPIO.LOW): GPIO.digitalWrite(FRONT, GPIO.HIGH) # toggle light OFF if ((now.hour == HOUR_OFF) and (now.minute == 0) and (now.second == 00)): if (GPIO.digitalRead(BACK) == GPIO.LOW): GPIO.digitalWrite(BACK, GPIO.HIGH) # gives CPU some time before looping again webiopi.sleep(1)
def postToAppEngine(jsonMessage): retry = 30 maxWait = 1800 maxWait = 1800 totalWait = 0 while totalWait <= maxWait: # Send the http POST to App Engine try: response = requests.post(URL + '/' + serviceID, data=jsonMessage) # response = requests.post(URL, data=jsonMessage) # Check for errors if response.status_code == 200: successMessage = jsonMessage + " -- Notification sent: Status Code " + str( response.status_code) webiopi.debug(successMessage) break else: errorMessage = jsonMessage + " -- Notification failed to send: " + str( response.status_code) + " - " + response.text webiopi.debug(errorMessage) break except: webiopi.debug( "Unable to establish http connection - trying again in 30 seconds" ) webiopi.sleep(retry) totalWait = totalWait + retry
def loop(): global Takki1Status, Takki2Status, Takki3Status, Takki4Status #readStatus(Takki1,Takki1Status,Takki1Safn) #readStatus(Takki2,Takki2Status,Takki2Safn) #readStatus(Takki3,Takki3Status,Takki3Safn) readStatus(Takki4,Takki4Status,Takki4Safn) webiopi.sleep(0.3)
def loop(): # retrieve current datetime # now = datetime.datetime.now() global status, catID, catAte, catFull doorOpen = False while (not doorOpen): if (serial.available() > 0): data = serial.readString() if (data[0] == "o"): catID = int(data[1]) if (catAte[catID] < catDiet[catID]): serial.writeString("1") status = data doorOpen = True else: serial.writeString("0") webiopi.sleep(0.5) while (doorOpen): if (serial.available() > 0): data = serial.readString() if (data[0] == "c"): catAte[catID] = round((catAte[catID] + float(data[1:])), 2) if(catAte[catID] > catDiet[catID]): catFull[catID] = 1 else: catFull[catID] = 0 status = "c:" + str(catFull[0]) + ":" + str(catAte[0]) + ":" + str(catFull[1]) + ":"+ str(catAte[1]) doorOpen = False webiopi.sleep(1)
def loop(): global lastRead global currentRead global secondsOpen # Read the state of the switch currentRead = GPIO.digitalRead(SWITCHPIN) # If the state of the switch has changed, record the event if currentRead != lastRead: print('Door state has changed, recording event') recordEvent(currentRead) lastRead = currentRead # If the door is open, keep track of how long. Send out a notification every 15 mins until closed. if currentRead == DOOROPEN and AUTONOTIFICATIONS == True: secondsOpen += SLEEPTIME if secondsOpen > OPENWARNINGTIMEINMINS * 60: print('Door has been open for ' + str(secondsOpen) + ' seconds. Sending notification') # Fetch the last two records to send off with the notification lastTwo = getRecords(2) sendNotification('{' + lastTwo + '}') # Reset the timer so we can send again in another 15 mins secondsOpen = 0 else: secondsOpen = 0 # gives CPU some time before looping again webiopi.sleep(SLEEPTIME)
def stop(): # 各GPIOをLOWにしてから1ミリ秒停止 GPIO.digitalWrite(LED1, GPIO.LOW) GPIO.digitalWrite(LED2, GPIO.LOW) GPIO.digitalWrite(IN1, GPIO.LOW) GPIO.digitalWrite(IN2, GPIO.LOW) webiopi.sleep(0.001)
def loop(): """ Loop run by WebIOPi """ webiopi.sleep(0.05) button_push = not GPIO.digitalRead(BUTTON) if button_push: togglePower() webiopi.sleep(0.5)
def Relaythread(pin,status,sec,delay): relay = relay1 #Select relay object and set logic pin if int(pin) <= 8: relay = relay1 inPin = int(pin)-1 elif int(pin) <= 16: relay = relay2 inPin = int(pin)-9 elif int(pin) <= 24: relay = relay3 inPin = int(pin)-17 else: webiopi.debug(tempList[0] + " is not a valid command") return "ERROR - " + tempList[0] + " is not a valid command" #Handle delay in needed if (str(delay) != "0"): webiopi.sleep(float(delay)) #Write desired status webiopi.debug("Writing to pin " + str(inPin)) relay.digitalWrite(inPin, status) #If interval needed then wait and toggle if (str(sec) != "0"): webiopi.sleep(float(sec)) if (status == ON): relay.digitalWrite(inPin, OFF) else: relay.digitalWrite(inPin, ON)
def setPcOn(): if GPIO.digitalRead(PWSTATUS) == GPIO.LOW: GPIO.digitalWrite(LIGHT, GPIO.HIGH) # wait 1 sec webiopi.sleep(1) GPIO.digitalWrite(LIGHT, GPIO.LOW) return true
def loop(): global lastRead global currentRead global secondsOpen # Read the state of the switch currentRead = GPIO.digitalRead(SWITCHPIN) # If the state of the switch has changed, record the event if currentRead != lastRead: print('Door state has changed, recording event') recordEvent(currentRead) lastRead = currentRead # If the door is open, keep track of how long. Send out a notification every 15 mins until closed. if currentRead == DOOROPEN and AUTONOTIFICATIONS == True: secondsOpen += SLEEPTIME if secondsOpen > OPENWARNINGTIMEINMINS*60: print('Door has been open for ' + str(secondsOpen) + ' seconds. Sending notification') # Fetch the last two records to send off with the notification lastTwo = getRecords(2) sendNotification('{' + lastTwo + '}') # Reset the timer so we can send again in another 15 mins secondsOpen = 0 else: secondsOpen = 0 # gives CPU some time before looping again webiopi.sleep(SLEEPTIME)
def loop(): webiopi.debug("Loop") # Toggle LED each 1 second value = not GPIO.digitalRead(LED_GREEN) GPIO.digitalWrite(LED_GREEN, value) webiopi.sleep(1)
def uploadTowebiopi(): print("Uploading data to Webiopi") serial = webiopi.deviceInstance("serial") serial = Serial("ttyAMA0", 2400) if (serial.available() > 0): data = serial.readString() webiopi.sleep(1)
def main(): # write data to serial port for i in range(1, 5): serial.writeString("M1: 1023\r\n") print("M1 Fwd") sleep(2) serial.writeString("M1: 0\r\n") print("M1 Off") sleep(2) serial.writeString("M2: 1023\r\n") print("M2 Fwd") sleep(2) serial.writeString("M2: 0\r\n") print("M2 Off") sleep(2) serial.writeString("M1: -1023\r\n") print("M1 Reverse") sleep(2) serial.writeString("M1: 0\r\n") print("M1 Off") sleep(2) serial.writeString("M2: -1023\r\n") print("M2 Reverse") sleep(2) serial.writeString("M2: 0\r\n") print("M2 Off") if (serial.available() > 0): data = serial.readString() print(data) webiopi.sleep(1)
def loop(): webiopi.debug("Looptest script - Loop") #optional, can be omitted if BLINKING: print("B-L-I-N-K") webiopi.sleep(BLINKPERIOD) print("---------") webiopi.sleep(BLINKPERIOD)
def loop(): if not isRunning(): webiopi.sleep(0.1) return global lastReadingTime global lastReading i = readCurrent() v = readVoltage() now = datetime.now(timezone.utc) t = (now - startTime).total_seconds() accumulatedReadings['i'].append(i) accumulatedReadings['v'].append(v) deltaSeconds = (now - lastReadingTime).total_seconds() # Read from the ADC as fast as possible, but only return a reading at the predefined rate. # All the extra readings can be averaged together to reduce noise, i.e. oversampling. if deltaSeconds >= settings.updatePeriod: lastReadingTime = now averageCurrent = sum(accumulatedReadings['i']) / float( len(accumulatedReadings['i'])) averageVoltage = sum(accumulatedReadings['v']) / float( len(accumulatedReadings['v'])) lastReading = {'i': averageCurrent, 'v': averageVoltage, 't': t} readings.append(lastReading) del accumulatedReadings['i'][:] del accumulatedReadings['v'][:] if settings.limits.exceeded(averageCurrent, averageVoltage, t): stop() try: runScript({'i': i, 'v': v, 't': t}) except Exception: stop()
def loop(): global RAINBOW_CYCLE if RAINBOW_CYCLE == False: # gives CPU some time before looping again webiopi.sleep(1) elif RAINBOW_CYCLE == True: rainbowStateMachine()
def Pause(): webiopi.debug("一時停止") GPIO.output(ini_position1, False) GPIO.output(ini_position2, False) GPIO.output(RUN1, False) GPIO.output(RUN2, False) GPIO.output(Relay, False) webiopi.sleep(1)
def Do(): webiopi.debug("実行中") GPIO.output(ini_position1, False) GPIO.output(ini_position2, False) GPIO.output(RUN1, True) GPIO.output(RUN2, True) GPIO.output(Relay, True) webiopi.sleep(1)
def getTempLoop(): while True: global temp try: temp = read_adt7410() except IOError: pass webiopi.sleep(1)
def End(): webiopi.debug("終了しました") GPIO.output(ini_position1, True) GPIO.output(ini_position2, True) GPIO.output(RUN1, False) GPIO.output(RUN2, False) GPIO.output(Relay, False) webiopi.sleep(1)
def loop(): for i in range(0, len(rotary_list)): if rotary_list[i].isRotatingClockWise(): print "Rotary:", i, "Step +" elif rotary_list[i].isRotatingAntiClockWise(): print "Rotary:", i, "Step -" webiopi.sleep(0.1)
def blink(userInput): count = 0 while (count < int(userInput) * 2): state = gpio.digitalRead(PIN) gpio.digitalWriter(PIN, not state) print("in blink") webiopi.sleep(1) count = count + 1
def loop(): if switchDist.switch_state == True: scanDistance() if switchMvt.switch_state == True: searchMvt() webiopi.sleep(0.01)
def allOn(number): #global AUTOMAN seq= int(number) for f in range(seq): light(1,f+1) webiopi.sleep(0.1) #light(1,f+1) return
def loop(): # retrieve current datetime #nowDatetime = datetime.datetime.now() #humidity, temperature = Adafruit_DHT.read_retry(DH11, PIN) # gives CPU some time before looping again #print(temperature, humidity) webiopi.sleep(1)
def allOff(number): seq= int(number) for f in range(seq): lightoff(1,f+1) webiopi.sleep(0.1) #lightoff(1,f+1) return
def testIO(): #Relays n = 0 while n < 16: relay.digitalWrite(n, ON) webiopi.sleep(.5) relay.digitalWrite(n, OFF) n = n + 1
def loop(): #PWM tests GPIO.pwmWrite(LED0, 0.90) #webiopi.sleep(0.25) GPIO.pwmWrite(LED0, 0.30) #webiopi.sleep(0.2) GPIO.pwmWrite(LED0, 0.70) webiopi.sleep(0.2)
def loop(): # gives CPU some time before looping again #print "\n LIGHT_value = %d\n" %(GPIO.digitalRead(LIGHT)) if (GPIO.digitalRead(SWITCH) == GPIO.LOW): GPIO.digitalWrite(LIGHT, GPIO.LOW) if (GPIO.digitalRead(SWITCH) == GPIO.HIGH): GPIO.digitalWrite(LIGHT, GPIO.HIGH) webiopi.sleep(1)
def loop(): # check GAS ALARM and start ALARM SIGNAL # I thing this is the open collector! bAlarmGAS = GPIO.digitalRead(PIN_MQ2_SENSOR) == GPIO.LOW if bAlarmGAS: GPIO.digitalWrite(PIN_ALARM_GAS, GPIO.HIGH) else: GPIO.digitalWrite(PIN_ALARM_GAS, GPIO.LOW) webiopi.sleep(1)
def loop(): global restart OFF = GPIO.digitalRead(SWITCH) if(OFF and not restart): GPIO.digitalWrite(LED, 1) #restartRPIHelper() restart = True webiopi.debug('restart') webiopi.sleep(.4)
def get_done(): print("spotter start") newest = max(glob.iglob('*.[j][p][g]'), key=os.path.getctime) cmd = "sudo ./deepbelief {} > try6.txt & ".format(newest) proc = subprocess.Popen(cmd, shell=True) cmd2 = "cp {} raju2.png".format(newest) proc2 = subprocess.Popen(cmd2, shell=True) webiopi.sleep(10) print("spotter stop")
def PWMthread(pin,DC,sec,delay): #Handel delay if needed if (str(delay) != "0"): webiopi.sleep(float(delay)) #Write out PWM to to DC pwm.pwmWriteFloat(int(pin),float(DC)) #If interval needed then wait and toggle if (str(sec) != "0"): webiopi.sleep(float(sec)) pwm.pwmWriteFloat(int(pin),0.0)
def defaultPosition(): global time_stamp if time_stamp <= time.time() - 0.2 and (CURRENT_ANGLE != DEFAULT_ANGLE): time_stamp = time.time() global CURRENT_ANGLE CURRENT_ANGLE = DEFAULT_ANGLE GPIO.pulseRatio(SERVO, 1) GPIO.pulseAngle(SERVO,DEFAULT_ANGLE) webiopi.sleep(0.5) GPIO.pulseRatio(SERVO, 0)
def PowerMeterProc( ): testing=rxData( ) if (conv2Float(testing[ 4: 8])) == 0.0 and not (conv2Float(testing[ 8: 12])) == 0.0: f = open("/home/pi/LogData/rxdErrorLog.txt", 'a') for n in testing: f.write(str(n)) f.write(',') f.write('\r \n') f.close() if (conv2Float(testing[ 4: 8])) == 0.0: webiopi.sleep(0.3) testing = rxData( ) if( mcp0.digitalRead(8) ): din = '0' else: din = '1' for i in range(7): if( mcp0.digitalRead(i+9) ): din += '0' else: din += '1' a = len(testing) if a < 54 : b = din else: b = 'V_rs='+("%.1f" %(conv2Float(testing[ 4: 8]))) +':' b += 'V_st='+("%.1f" %(conv2Float(testing[ 8:12]))) +':' b += 'V_tr='+("%.1f" %(conv2Float(testing[12:16]))) +':' b += 'I_r=' +("%.1f" %(conv2Float(testing[16:20]))) +':' b += 'I_s=' +("%.1f" %(conv2Float(testing[20:24]))) +':' b += 'I_t=' +("%.1f" %(conv2Float(testing[24:28]))) +':' b += 'P_re='+("%.1f" %(conv2Float(testing[28:32])/1000)) +':' b += 'Pvar='+("%.1f" %(conv2Float(testing[32:36])/1000)) +':' b += 'pf=' +("%.1f" %(conv2Float(testing[36:40]))) +':' b += 'Hz=' +("%.1f" %(conv2Float(testing[40:44]))) +':' b += 'kWh=' +("%.1f" %(conv2Float(testing[44:48]))) +':' b += 'kVah='+("%.1f" %(conv2Float(testing[48:52]))) +':' b += din +':END' return b
def loop(): #終了シグナルの実行(RUN1=0など初期状態にする) if (GPIO.input(EndCallBack) == 1): webiopi.debug("動作終了です\n") GPIO.output(RUN1, False) GPIO.output(RUN2, False) GPIO.output(ini_position1, True) GPIO.output(ini_position2, True) GPIO.output(Relay, False) webiopi.sleep(1) webiopi.debug("待機中\n")
def loop(): if (AUTO): dht = webiopi.deviceInstance("dht0") celsius = dht.getCelsius() # get current temperature if (celsius < MIN): GPIO.digitalWrite(LIGHT, GPIO.HIGH) if (celsius > MAX): GPIO.digitalWrite(LIGHT, GPIO.LOW) webiopi.sleep(1)
def SoundThread(sound,relay,delay): #Handel delay if needed webiopi.debug("SOUND ON") if (str(delay) != "0"): webiopi.sleep(float(delay)) timeOn = sound.get_length() + .5 threading.Thread(target=Relaythread,args=(relay,ON,timeOn,"0.25",)).start() sound.play() webiopi.sleep(float(timeOn)) Stat.onBool = False webiopi.debug("SOUND OFF")
def flashAllLights(repeat, delay): for i in range(0, repeat): for light in LIGHTS: GPIO.digitalWrite(light, GPIO.HIGH) webiopi.sleep(delay) for light in LIGHTS: GPIO.digitalWrite(light, GPIO.LOW) webiopi.sleep(1)
def loop(): # retrieve current datetime global motion if GPIO.digitalRead(PIR): if motion == False: print("Motion Detected") SendEmail("Motion Detected!") motion = True else: motion = False webiopi.sleep(1)
def left(): global CURRENT_ANGLE,time_stamp webiopi.debug("left") if CURRENT_ANGLE < DEFAULT_ANGLE and time_stamp <= time.time() - 0.2: GPIO.pulseRatio(SERVO, 1) time_stamp = time.time() CURRENT_ANGLE = CURRENT_ANGLE + 30 GPIO.pulseAngle(SERVO, CURRENT_ANGLE) webiopi.sleep(0.5) time_stamp = time.time() GPIO.pulseRatio(SERVO, 0)
def right(): global CURRENT_ANGLE, time_stamp webiopi.debug("right") if CURRENT_ANGLE > DEFAULT_ANGLE - 9*10 and time_stamp <= time.time() - 0.2: GPIO.pulseRatio(SERVO, 1) time_stamp = time.time() CURRENT_ANGLE = CURRENT_ANGLE - 30 GPIO.pulseAngle(SERVO, CURRENT_ANGLE) webiopi.sleep(0.5) time_stamp = time.time() GPIO.pulseRatio(SERVO, 0)
def loop(): if(loadsheddingtimea == time.strftime("%H:%M:%S") or loadsheddingtimeb == time.strftime("%H:%M:%S")): if (GPIO.digitalRead(LIGHT) == GPIO.HIGH): GPIO.digitalWrite(LIGHT, GPIO.LOW) time.sleep(2) if(loadsheddingtimeaON == time.strftime("%H:%M:%S") or loadsheddingtimebON == time.strftime("%H:%M:%S")): if (GPIO.digitalRead(LIGHT) == GPIO.LOW): GPIO.digitalWrite(LIGHT, GPIO.HIGH) time.sleep(2) webiopi.sleep(1)
def loop(): if g_active == 1: FunMoveMotor(forward, 1) if g_active == 2: FunMoveMotor(turnLeft, 1) if g_active == 3: FunMoveMotor(turnRight, 1) if g_active == 4: FunMoveMotor(back, 1) if g_active == 5: FunMoveMotor(stop, 0.5) webiopi.sleep(0.5)
def loop(): # LED1、LED2の値に応じて、呼び出す処理を変更 led1 = GPIO.digitalRead(LED1) led2 = GPIO.digitalRead(LED2) if led1 == GPIO.HIGH and led2 == GPIO.LOW: forward() if led1 == GPIO.LOW and led2 == GPIO.HIGH: back() if led1 == GPIO.LOW and led2 == GPIO.LOW: stop() # 1.0秒間処理を停止 webiopi.sleep(1.0)
def loop(): global refreshTimeInterval global allGpsData try: webiopi.info('Read:%s' % getAllGpsData()) except Exception as Err: webiopi.debug('%s' % Err) finally: # Cyclic Period webiopi.sleep(1)
def setup(): # set the GPIO used by the light to output GPIO.setFunction(LIGHT, GPIO.OUT) # retrieve current datetime now = datetime.datetime.now() print(" scriptLed17Blink | SETUP at:" + str(now)) state = True for x in range(0, 6): GPIO.digitalWrite(LIGHT, state) state = not state # gives CPU some time before looping again webiopi.sleep(0.5)
def graduateRight(): global CURRENT_ANGLE, time_stamp webiopi.debug("graduateright") if CURRENT_ANGLE > DEFAULT_ANGLE - 9*10 and time_stamp <= time.time() - 0.2: for i in range(0,30): GPIO.pulseRatio(SERVO, 1) time_stamp = time.time() CURRENT_ANGLE = CURRENT_ANGLE - 1 GPIO.pulseAngle(SERVO, CURRENT_ANGLE) webiopi.sleep(0.015) GPIO.pulseRatio(SERVO, 0) time_stamp = time.time()
def loop(): # update time now = datetime.datetime.now() # see what to do if(((HOURON < now.hour < HOUROFF) and (MINON < now.minute)) and (GPIO.digitalRead(TOGGLE) == GPIO.LOW)): turnOn() else: turnOff() # rest webiopi.sleep(10)
def logTowebiopi(self, uploading=None): if uploading is not None: self.uploading = uploading if self.uploading: port.flushInput() print "Logging to Webiopi" serial = webiopi.deviceInstance("serial") serial = Serial("ttyAMA0", 2400) if (serial.available() > 0): data = serial.readString() webiopi.sleep(1) self.master.after(1, self.logTowebiopi)
def logTowebiopi(self, uploading=None): if uploading is not None: self.uploading = uploading print "Please choose an option to log data to... " if self.uploading: port.flushInput() #Empty serial buffer print "Logging to Webiopi" serial = webiopi.deviceInstance("serial") serial = Serial("ttyAMA0", 2400) if (serial.available() > 0): #Uploads to Webiopi data = serial.readString() webiopi.sleep(1) self.master.after(1, self.logTowebiopi)
def count_a_lot(): x = 0 GPIO.digitalWrite(RED, GPIO.HIGH) while x < 1000000: x += 1 GPIO.digitalWrite(RED, GPIO.LOW) GPIO.digitalWrite(GREEN, GPIO.HIGH) webiopi.sleep(1) GPIO.digitalWrite(GREEN, GPIO.LOW) return x
def loop(): # retrieve current datetime now = datetime.datetime.now() # toggle light ON if (GPIO.digitalRead(LIGHT) == GPIO.LOW): GPIO.digitalWrite(LIGHT, GPIO.HIGH) # toggle light OFF if (GPIO.digitalRead(LIGHT) == GPIO.HIGH): GPIO.digitalWrite(LIGHT, GPIO.LOW) # gives CPU some time before looping again webiopi.sleep(1)