def on_message(self, mqttc, obj, msg): if (msg.topic.split("/")[1] in "inbox outbox"): box = (msg.topic.split("/")[1]) name = msg.topic.split("/")[2] address = msg.topic.split("/")[3] # Return device info on call to /inbox/name/deviceInfo:get if box == "inbox" and str( msg.payload) == "get" and address == "deviceInfo": self.publish("/outbox/" + self._client_id + "/deviceInfo", self.deviceInfo, 1) # set the new update rate if box == "inbox" and address == "updateRate": self.startTimer(msg.payload) self.publishUpdateRate() if box == "inbox" and address == "alarm": if str(msg.payload) < 1: buzz(1.0) else: buzz(msg.payload) if box == "inbox" and address == "reset": #initial values self.publish("/outbox/" + client_id + "/updateRate", '{"value":' + temperatureRate + '}', 1) print "Reseting values...." elif (msg.topic.split("/")[0] == "$SYS"): pass else: pass
def setAlarm(msg): print('listens in tele') chat_id = msg['chat']['id'] alarm = msg['text'] curr_time = int(time.strftime("%H%M")) try: intalarm = int(alarm) except: bot.sendMessage(chat_id, 'Not a valid time, please enter one in HHMM format') if curr_time >= intalarm: question, answer = random() bot.sendMessage(chat_id, ('Alarm set for tomorrow @ {}'.format(alarm))) buzz(500, 0.1) print(question) alarmON(intalarm, question, answer) if intalarm > curr_time: question, answer = random() bot.sendMessage(chat_id, ('Alarm set for today @ {}'.format(alarm))) buzz(500, 0.1) print(question) alarmON(intalarm, question, answer)
def sensor(): GPIO.setmode(GPIO.BCM) TRIG = 25 ECHO = 24 GPIO.setup(TRIG,GPIO.OUT) GPIO.setup(ECHO,GPIO.IN) GPIO.output(TRIG,False) time.sleep(2) GPIO.output(TRIG,True) time.sleep(0.00001) GPIO.output(TRIG, False) startTime = time.time() pulse_start = 0 pulse_end = 0 while GPIO.input(ECHO)==0: pulse_start = time.time() if time.time() - startTime > 5: break while GPIO.input(ECHO)==1: pulse_end = time.time() if time.time() - startTime > 5: break distance = (pulse_end - pulse_start) * 17150 distance = round(distance,2) print('Distance from ultrasonic sensor: ', distance, ' cm') if distance < 10 and distance > 0: buzz()
def ringHandler(pin): if "openeButtonCycle" not in globals(): global openeButtonCycle openeButtonCycle = True if GPIO.input(gpioConfig.ringListenerPin) == 0 and openeButtonCycle is True: openeButtonCycle = False elif openeButtonCycle is False: openeButtonCycle = True localtime = time.asctime( time.localtime(time.time()) ) print("Doorbell rang on PIN #" + str(pin) +" at: " + localtime) notifier.sendNotification() buzzer.buzz()
def watch_doorbell(stream, q=None): t = thread.currentThread() logging.warning( f"WARNING WARNING WARNING !!!! This thread may not be stop !! : «{t}»") # FIXME : find a way to kill this thread as ".iter_lines" is bloquant now = lambda: datetime.now().strftime("%H:%M:%S") for elt in stream.iter_lines(): if not getattr(t, "do_run", True): print(f"thread «{t}» watch_doorbell stopped") return if elt: elt = elt.decode("utf-8") if q: q.put(f"{now()} - {elt}") if "doorbell:H" in elt: logging.info(f"{now()}: Doorbird entrée sonné.") # print(f"{now()}: Doorbird entrée sonné.") buzzer.buzz()
def alarmON(alarm, question, answer): awake = 0 off = False attempt = 0 try: # Loop to continuously check time, buzz the buzzer for the set alarm time while True: # Continually get's the time as an integer value curr_time = int(time.strftime("%H%M")) pressed = GPIO.input(16) add = GPIO.input(27) minus = GPIO.input(22) if add == True: attempt = attempt + 1 print(attempt) if minus == True: attempt = attempt - 1 print(attempt) if pressed == True: if attempt == answer: print('alarm is off') break # Buzzes the buzzer when the time reaches the set alarm time if curr_time == alarm: buzz(10, 0.5) time.sleep(0.25) buzz(20, 0.5) time.sleep(0.25) awake = 1 lcd.text(question, 1) display = 'Answer is now ' + str(attempt) lcd.text(display, 2) # If alarm continues past the set alarm time without being # snoozed, the alarm time is changed to the current time. # This ensures the alarm buzzes continuously until the # snooze button is pressed. elif curr_time != alarm and awake == 1: alarm = curr_time buzz(10, 0.5) time.sleep(0.25) buzz(20, 0.5) time.sleep(3) lcd.text(question, 1) display = 'Answer is now ' + str(attempt) lcd.text(display, 2) sleep(3) finally: print('off')
def dbInsertValidate(now, startTime, timegap, temp): LCD.lcd_init() if now >= startTime + timedelta(minutes=timegap): #mysql insertion sql = "insert into TempRecord(rec_year, rec_month, rec_date, rec_time, temp) values(%s, %s, %s, %s, %s)" # print sql %(now.year, now.month, now.day, now.strftime('%H:%M:%S'), temp) try: cursor.execute(sql, (int(now.year), int(now.month), int(now.day), now.strftime('%H:%M:%S'), temp)) LCD.lcd_string('**db inserted**', 2) print '**temp value inserted**' buzzer.buzz(1) except: LCD.lcd_string('**db error!**', 2) time.sleep(2) db.rollback() db.commit() global start start = now
def takeeveningmeds(): x = 0 if time4 == False: # takenomeds() # if you want to be reminded that no medications to taken at this # time, then uncomment the command above. pass else: buzz(900, 0.5) time.sleep(0.5) print('') print('Time to take the following medication') for v in range(s): if eveningtime[v] == True: x += 1 print(medname[v]) if s == w + x: time.sleep(61) maintitle()
def takeafternoonmeds(): r = 0 if time3 == False: # takenomeds() # if you want to be reminded that no medications to taken at this # time, then uncomment the command above. pass else: buzz(900, 0.5) time.sleep(0.5) print('') print('Time to take the following medication') for p in range(m): if afternoontime[p] == True: r += 1 print(medname[p]) if m == q + r: time.sleep(61) maintitle()
def takemiddaymeds(): l = 0 if time2 == False: # takenomeds() # if you want to be reminded that no medications to taken at this # time, then uncomment the command above. pass else: buzz(900, 0.5) time.sleep(0.5) print('') print('Time to take the following medication') for j in range(g): if middaytime[j] == True: l += 1 print(medname[j]) if g == k + l: time.sleep(61) maintitle()
def takemorningmeds(): f = 0 if time1 == False: # takenomeds() # if you want to be reminded that no medications to taken at this # time, then uncomment the command above. pass else: buzz(900, 0.5) time.sleep(0.5) print('') print('Time to take the following medication(s)') for d in range(a): if morningtime[d] == True: f += 1 print(medname[d]) if a == e + f: time.sleep(61) maintitle()
def alarm(): if 75 < min_dist <= 150: for _ in range(3): bz.buzz(18, 2, 95) if 30 < min_dist <= 75: for _ in range(4): bz.buzz(18, 0.8, 95) if min_dist <= 30: for _ in range(5): bz.buzz(18, 0.2, 95)
def on_message_buzzer(client, userdata, msg): print("Running buzzer") buzzer.buzz()
import RPi.GPIO as GPIO #turn off all lights and buzzers settings.init() nextNumber = -1 BUZZ_TIME = 5 GAME_TIME = 10 game = 2 testNo = 0 while testNo < 6: testDone = False light.switch(settings.lightList[testNo], GPIO.HIGH) while not testDone: testDone = button.isPressed(settings.buttonList[testNo]) buzzer.buzz(settings.buzzerList[testNo], GPIO.HIGH) time.sleep(1) light.switch(settings.lightList[testNo], GPIO.LOW) buzzer.buzz(settings.buzzerList[testNo], GPIO.LOW) testNo = testNo + 1 while True: started = False light.switch(settings.readylight, GPIO.HIGH) while not started: started = button.isPressed(settings.startButton) light.switch(settings.readylight, GPIO.LOW) playing = True GAME_TIME = 10 BUZZ_TIME = 5
def handleRingCommand(bot, update): if(isAuthorized(update.message.chat.id)): print("Received sound command.") bot.sendMessage(secrets.chatId, text="Beep! Beep! Beep!") buzzer.buzz()
setupGPIOBoard() setupGPIOInput(mtnPin) try: while True: if camera_running: log('MAIN - Camera is running for ' + str(camera_time) + ' seconds') camera.runCamera(camera_time) log('MAIN - Camera is finished running') camera_running = False mtnInput = getGPIOInput(mtnPin) if mtnInput == False: log('MAIN - Motion Detected!') sendPush('Motion Detected', 'Motion has been detected on this camera!') api.updateTrigger(1) buzzer.buzz() camera_running = True sleep(0.2) else: camera_running = False except (KeyboardInterrupt, SystemExit): cleanupGPIO() log('MAIN - Exception') cleanupGPIO()
# Raspberry Pi Alarm Clock # 2014, Ismail Uddin # www.scienceexposure.com import time import RPi.GPIO as GPIO from buzzer import buzz GPIO.setmode(GPIO.BCM) GPIO.setup(25, GPIO.IN, pull_up_down=GPIO.PUD_UP) response = raw_input("Please input the time for the alarm in format HHMM: \n") print("Alarm has been set for %s hrs" % response) buzz(500, 0.1) alarm = int(response) awake = 0 try: # Loop to continuously check time, buzz the buzzer for the set alarm time while True: # Continually get's the time as an integer value curr_time = int(time.strftime("%H%M")) # Buzzes the buzzer when the time reaches the set alarm time if curr_time == alarm: buzz(10, 0.5) time.sleep(0.25) buzz(20, 0.5) time.sleep(0.25)
def takenomeds(): buzz(1500, 0.5) print('') print('There are no medications scheduled to taken at this time.') time.sleep(61) maintitle()
def read_sensors(current_hour, mylcd): global mutex, temperatures, humidities, temperature, humidity, temp_avg, hum_avg, count, cimis_count print("CURRENT HR: %d\n" % current_hour) temperatures = [None] * 24 humidities = [None] * 24 #current_hour = 14 #temperatures[15] = 77 #humidities[15] = 56 #temperatures[14] = 73.4 #humidities[14] = 54 ''' temperatures[9] = 75 humidities[9] = 54 temperatures[10]=77 humidities[10]=56 ''' today = datetime.date.today() t = threading.Thread(target=local.local_data, args=( mylcd, temperatures, humidities, mutex, )) t.start() #cimis_hr, cimis_eto, cimis_temp, cimis_hum = cimis.cimis(18*100,temperatures[18],humidities[18]) #print("CIMIS hr: %d eto: %f hum: %f" %(cimis_hr, cimis_eto, cimis_hum)) columns = [['Hour', 'Derated ET', 'Temperature', 'Humidity']] with open('data.csv', 'w') as f: writer = csv.writer(f) writer.writerow(columns) f.close() while (True): new_time = datetime.datetime.now().time() now = datetime.date.today() if ((new_time.hour > current_hour or now.day > today.day or now.month > today.month) and (new_time.minute == 30 or new_time.minute == 45 or new_time.minute == 50)): buzzer.buzz() if (cimis.cimis(current_hour * 100, temperatures[current_hour], humidities[current_hour]) == None): print("Current hour:%d\n" % (current_hour)) print("waiting\n") continue cimis_hr, cimis_eto, cimis_temp, cimis_hum = cimis.cimis( current_hour * 100, temperatures[current_hour], humidities[current_hour]) print("CIMIS hr: %d eto: %f hum: %f" % (cimis_hr, cimis_eto, cimis_hum)) print(temperatures[current_hour], humidities[current_hour]) new_et = derate(cimis_eto, cimis_hum, humidities[current_hour], cimis_temp, temperatures[current_hour]) data = [[ current_hour, new_et, temperatures[current_hour], humidities[current_hour] ]] with open('data.csv', 'a') as f: writer = csv.writer(f) writer.writerow(data) f.close() current_hour += 1 print("HOUR: %d\n" % current_hour) while (cimis.cimis(current_hour * 100, temperatures[current_hour], humidities[current_hour]) != None): cimis_hr1, cimis_eto1, cimis_temp1, cimis_hum1 = cimis.cimis( current_hour * 100, temperatures[current_hour], humidities[current_hour]) print("cimis eto1:%f\n" % cimis_eto1) et = derate(cimis_eto1, cimis_hum, humidities[current_hour], cimis_temp, temperatures[current_hour]) data = [[ current_hour, et, temperatures[current_hour], humidities[current_hour] ]] with open('data.csv', 'a') as f: writer = csv.writer(f) writer.writerow(data) f.close() new_et += et print("NEW ETO SUM: %f\n" % new_et) current_hour += 1 cimis_count += 1 print("MISSED HOURS: %d\n" % cimis_count) cimis_count = 0 print("CURRENT HOUR NEXT: %d\n" % current_hour) water = water_needed(new_et) print(water) duration = water_duration(water) print(duration) water_lawn(duration, mylcd, mutex)
def ringOnce(self): buzz(10,0.5) time.sleep(.25) buzz(10,0.5) time.sleep(.25)
# Raspberry Pi Alarm Clock # 2014, Ismail Uddin # www.scienceexposure.com import time import RPi.GPIO as GPIO from buzzer import buzz GPIO.setmode(GPIO.BCM) GPIO.setup(25, GPIO.IN, pull_up_down=GPIO.PUD_UP) response = raw_input("Please input the time for the alarm in format HHMM: \n") print("Alarm has been set for %s hrs" % response) buzz(500,0.1) alarm = int(response) awake = 0 try: # Loop to continuously check time, buzz the buzzer for the set alarm time while True: # Continually get's the time as an integer value curr_time = int(time.strftime("%H%M")) # Buzzes the buzzer when the time reaches the set alarm time if curr_time == alarm: buzz(10,0.5) time.sleep(0.25) buzz(20,0.5) time.sleep(0.25)