def listen_for_alarm_stop_event(): """Stub method - should listen for button press event""" import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP) while True: input_state = GPIO.input(18) if input_state == False: light.off() print 'Button Pressed' return True time.sleep(0.2) return True
def recognize(self): aipSpeech = AipSpeech(APP_ID, API_KEY, SECRET_KEY) # 识别本地文件 res=aipSpeech.asr(self.get_file_content(WAVE_OUTPUT_FILENAME), 'wav', 16000, { 'lan': 'zh', }) print res print dircmd for word in res['result']: print word if word[:-1] in dircmd: iscmd=True print "开始打开电视请稍等" if word[:-1] == dircmd[1]: pass elif word[:-1] == dircmd[2]: light.on() elif word[:-1] == dircmd[3]: light.off()
def handle_request(client_socket): request = json.loads(client_socket.recv(1024)) logging.debug("Reveived: %s", request) client_socket.send("ACK!\r\n") # send back a packet client_socket.close() text = request['message']['text'].lower() sender_id = request['sender']['id'].encode('utf8') if u'pic' in text: camera.response_picture(sender_id) elif u'pm' in text: response.response_text(sender_id, pm2_5.PM_DB.discription()) elif u'temp' in text or u'tmp' in text: thermometer.response_temperature(sender_id) elif u'left' in text: servomotor.turn_left() elif u'right' in text: servomotor.turn_right() elif u'light on' in text: light.on() elif u'light off' in text: light.off() else: response.response_text(sender_id, "Try: picture, PM2.5, temperature.")
logger.info("ALARM FORM: {}".format(request.form)) alarm_time = request.form.get("time") if not alarm_time: logger.warning("Time not received") return redirect('/') hour, minute = alarm_time.split(":") DB.set_alarm_time(int(hour), int(minute)) return redirect('/') @app.route('/alarm/simulate', methods=['POST']) def alarm_simulate(): """Execute the alarm now. """ logger.info('Simulating alarm...') alarm.execute_alarm() return redirect('/') @app.route('/static/<path:path>') def send_static(path): return send_from_directory('static', path) if __name__ == "__main__": light.off() app.run(host=settings.SERVER_HOST, port=settings.SERVER_PORT)
def off(): light.off() # light.utilities.turn_off() return redirect(url_for('home'))