def stop_door(): with GPIO(gpioc) as gpio: gpio.digital_write(GPIO_C, GPIO.LOW) with GPIO(gpioe) as gpio: gpio.digital_write(GPIO_E, GPIO.LOW) with GPIO(gpioi) as gpio: gpio.digital_write(GPIO_I, GPIO.LOW) with GPIO(gpiok) as gpio: gpio.digital_write(GPIO_K, GPIO.LOW)
def blink(pin): with GPIO(pins) as gpio: for i in range(3): gpio.digital_write(pin[0], GPIO.HIGH) time.sleep(i) gpio.digital_write(pin[0], GPIO.LOW) time.sleep(1)
def main(): while no_face: vc = cv2.VideoCapture(DEVICE_NUMBER) retVal, frame = vc.read() small = cv2.resize(frame, (0, 0), fx=0.5, fy=0.5) cv2.imwrite(IMAGE_FILE, small) vc.release() print("Done reading image.") response = requests.post(API, files={ "image": open( '/home/linaro/haven/dragon_board/output.jpg', 'r')}) print("Received web response.") if response.status_code == 200: user = json.loads(response.text)['user'] confidence = json.loads(response.text)['confidence'] if confidence > 0.97: # home_actions(user) first = user.split("-")[0].title() last = user.split("-")[1].title() print(first + " " + last + " recognised.") # text = "Welcome home " + first + " " + last) # tts = gTTS(text, lang='en') # tts.save("welcome_msg.mp3") # os.system("mp321 welcome_msg.mp3") with GPIO(light_pins) as gpio: turn_on(gpio) open_door() time.sleep(3) close_door() # filename = sys/class/gpio/gpio12 # os.system('./Electronics/turnOnGPIO.sh') k = raw_input("") if k == 'q': with GPIO(light_pins) as gpio: turn_off(gpio) sys.exit(1) else: with GPIO(light_pins) as gpio: turn_off(gpio)
def readpot(gpio): gpio.digital_write(GPIO_A, GPIO.HIGH) time.sleep(0.0002) gpio.digital_write(GPIO_A, GPIO.LOW) r = spi.xfer2([0x01, 0x80, 0x00]) gpio.digital_write(GPIO_A, GPIO.HIGH) adcout = (r[1] << 8) & 0b1100000000 adcout = adcout | (r[2] & 0xff) return adcout if adcout > 500.0: with GPIO(pins) as gpio: blink(gpio) return adcout
def voice(): blink(GPIO(pins)) callers = { "+18577010279": "Sherry"} from_number = request.values.get('From', None) print ("calling") if from_number in callers: caller = callers[from_number] else: caller = "Monkey" resp = VoiceResponse() resp.say("Hello " + caller) gather = Gather(num_digits=1, action='/storytime') gather.say('To listen to Three Little Pigs, press 1. To listen to Little Red Riding Hood, press 2.') resp.append(gather) return str(resp)
def on_message(client, userdata, msg): print(msg.topic+" "+str(msg.qos)+" "+str(msg.payload)) if(msg.topic == 'v1/' + Username + '/things/' + clientID + '/cmd/channel'): payload = str(msg.payload).split(",") client.publish('v1/'+ Username +'/things/' + clientID + '/data/channel', payload[1], qos=0) status = int(payload[1]) with GPIO(pins) as gpio: if(status): gpio.digital_write(GPIO_A, GPIO.HIGH) print 'turn ON' laststatus = payload else: gpio.digital_write(GPIO_A, GPIO.LOW) print 'turn OFF' laststatus = payload
def blink(i): with GPIO(pins[i]) as gpio: while True: val = gpio.digital_read(gpio_arr[i]) print("Sensor " + str(i) + " : " + str(val)) try: if (val == 0 and send_status[i] == 0): command = 'at+qhttpget=' + str(data['response_time']) se.write(command + '\r\n') print(command) send_status[i] = 1 elif (val == 1): send_status[i] = 0 except KeyboardInterrupt: break time.sleep(1)
def storytime(): blink(GPIO(pins)) if 'Digits' in request.values: choice = request.values['Digits'] if choice == '1': f = open('threelittlepigs.txt', 'r') lines = f.readlines() for line in lines: resp.say(line) resp.redirect("/voice") return str(resp) elif choice == '2': g = open('littlered.txt', 'r') lines = g.readlines() for line in lines: resp.say(line) resp.redirect("/voice") return str(resp) else: resp.say("Sorry, I don't understand that choice.") resp.redirect("/voice") return str(resp)
def sms(): blink(GPIO(pins)) resp = MessagingResponse() # msg.media("https://i.ytimg.com/vi/sAqks9CB6mg/maxresdefault.jpg") body = request.values.get('Body', None) # Add a message # resp.message() listfrm=body.split(' ') greetings_list = ['hi','hello','hey'] if listfrm.length >= 2: if listfrm[0].lower()=='remind' and listfrm[1].lower() =='me': print("reminded") resp.message("REMINDERTIME!!") elif body.lower() in greetings_list: random_greetings=random.choice(greetings_list) resp.message(random_greetings) elif body == 'bye': resp.message("Bye! :)") return str(resp)
"alarme": alarme, "temp": vtemp, "lumi": vlumi, "bam_nuvem": bam_nuvem, "bebe": alarme_bebe, "reset": reset_nuvem, "estado": estado_am, "liga_des": ld_nuvem, }) print "Ar Condicionado Desligado" print("Temperatura: %2.1f" % vtemp) print("Luminosidade: %2.1f \n" % vlumi) #Aqui é executado o programa principal até que seja interrompido with GPIO(pins) as gpio: while True: #Faz a leitura e atualização das variáveis Leitura_nuvem() botao_valor = gpio.digital_read(BOTAO) vtemp = readtemp(gpio) vlumi = readLumi(gpio) #Verifica se o botão local ou botão na nuvem(aplicativo) foi acionado if botao_valor == 0 or bam_nuvem == 0: #Se nenhum acionado o sistema está em automático e caso temperatura maior que 24, liga #o ar condicionadi e uma variável na nuvem estado_am receberá 1, informado ao app que #está em automático estado_am = 1 if vtemp > 23: Aut_Liga() #caso temperatura medida for menor que 24, desliga ar condicionado
def stepper(): if steps == 0: with GPIO(gpioc) as gpio: gpio.digital_write(GPIO_C, GPIO.LOW) with GPIO(gpioe) as gpio: gpio.digital_write(GPIO_E, GPIO.LOW) with GPIO(gpioi) as gpio: gpio.digital_write(GPIO_I, GPIO.LOW) with GPIO(gpiok) as gpio: gpio.digital_write(GPIO_K, GPIO.HIGH) elif steps == 1: with GPIO(gpioc) as gpio: gpio.digital_write(GPIO_C, GPIO.LOW) with GPIO(gpioe) as gpio: gpio.digital_write(GPIO_E, GPIO.LOW) with GPIO(gpioi) as gpio: gpio.digital_write(GPIO_I, GPIO.HIGH) with GPIO(gpiok) as gpio: gpio.digital_write(GPIO_K, GPIO.HIGH) elif steps == 2: with GPIO(gpioc) as gpio: gpio.digital_write(GPIO_C, GPIO.LOW) with GPIO(gpioe) as gpio: gpio.digital_write(GPIO_E, GPIO.LOW) with GPIO(gpioi) as gpio: gpio.digital_write(GPIO_I, GPIO.HIGH) with GPIO(gpiok) as gpio: gpio.digital_write(GPIO_K, GPIO.LOW) elif steps == 3: with GPIO(gpioc) as gpio: gpio.digital_write(GPIO_C, GPIO.LOW) with GPIO(gpioe) as gpio: gpio.digital_write(GPIO_E, GPIO.HIGH) with GPIO(gpioi) as gpio: gpio.digital_write(GPIO_I, GPIO.HIGH) with GPIO(gpiok) as gpio: gpio.digital_write(GPIO_K, GPIO.LOW) elif steps == 4: with GPIO(gpioc) as gpio: gpio.digital_write(GPIO_C, GPIO.LOW) with GPIO(gpioe) as gpio: gpio.digital_write(GPIO_E, GPIO.HIGH) with GPIO(gpioi) as gpio: gpio.digital_write(GPIO_I, GPIO.LOW) with GPIO(gpiok) as gpio: gpio.digital_write(GPIO_K, GPIO.LOW) elif steps == 5: with GPIO(gpioc) as gpio: gpio.digital_write(GPIO_C, GPIO.HIGH) with GPIO(gpioe) as gpio: gpio.digital_write(GPIO_E, GPIO.HIGH) with GPIO(gpioi) as gpio: gpio.digital_write(GPIO_I, GPIO.LOW) with GPIO(gpiok) as gpio: gpio.digital_write(GPIO_K, GPIO.LOW) elif steps == 6: with GPIO(gpioc) as gpio: gpio.digital_write(GPIO_C, GPIO.HIGH) with GPIO(gpioe) as gpio: gpio.digital_write(GPIO_E, GPIO.LOW) with GPIO(gpioi) as gpio: gpio.digital_write(GPIO_I, GPIO.LOW) with GPIO(gpiok) as gpio: gpio.digital_write(GPIO_K, GPIO.LOW) elif steps == 7: with GPIO(gpioc) as gpio: gpio.digital_write(GPIO_C, GPIO.HIGH) with GPIO(gpioe) as gpio: gpio.digital_write(GPIO_E, GPIO.LOW) with GPIO(gpioi) as gpio: gpio.digital_write(GPIO_I, GPIO.LOW) with GPIO(gpiok) as gpio: gpio.digital_write(GPIO_K, GPIO.HIGH) else: with GPIO(gpioc) as gpio: gpio.digital_write(GPIO_C, GPIO.LOW) with GPIO(gpioe) as gpio: gpio.digital_write(GPIO_E, GPIO.LOW) with GPIO(gpioi) as gpio: gpio.digital_write(GPIO_I, GPIO.LOW) with GPIO(gpiok) as gpio: gpio.digital_write(GPIO_K, GPIO.LOW)
def gpio_h(gpid): pins = ((gpid, 'out'), ) with GPIO(pins) as gpio: gpio.digital_write(gpid, GPIO.HIGH)
def gpio_r(gpid): pins = ((gpid, 'in'), ) with GPIO(pins) as gpio: data = gpio.digital_read(gpid) return data