def main(logger, config_file): config = get_config(config_file) init_temp = read_temperature() notify_init() logger.info('raspi-chill has started!') logger.info('[ REGULATION ]') logger.info('- initial ext temperature: %s' % init_temp) logger.info('- target ext temperature: %s' % config.get('UPPER_LIMIT')) logger.info('- regulation enabled: %s' % config.get('REGULATION_ENABLED')) logger.info('- cooling cycle time: %s' % config.get('COOLING_SECONDS_INTERVAL')) logger.info('- passive cycle time: %s' % config.get('PASSIVE_SECONDS_INTERVAL')) logger.info('[ LOGS ]') logger.info('- int temperature log: %s' % (logger.INTERNAL_TEMPERATURE_LOG_FILE)) logger.info('- ext temperature log: %s' % (logger.EXTERNAL_TEMPERATURE_LOG_FILE)) logger.info('- gravity log: %s' % (logger.GRAVITY_LOG_FILE)) logger.info('- events log: %s' % (logger.EVENTS_LOG_FILE)) alarm_cycles = 0 while True: # refresh config config = get_config(config_file) current_temp = read_temperature() logger.writeExternalTemperature(current_temp) if config.get('REGULATION_ENABLED'): if current_temp > config.get('ALARM_LIMIT'): alarm() alarm_cycles += 1 logger.info('ALARM - %s consecutive cycles' % alarm_cycles) if current_temp > config.get('UPPER_LIMIT'): turn_cooling_on() sleep(config.get('COOLING_SECONDS_INTERVAL')) if current_temp <= config.get('UPPER_LIMIT'): turn_cooling_off() alarm_cycles = 0 sleep(config.get('PASSIVE_SECONDS_INTERVAL')) else: if is_cooling_on(): turn_cooling_off() sleep(config.get('PASSIVE_SECONDS_INTERVAL'))
def process_message(message, fromid, remotejids): global bot,glparams resp="" talkonly = -1 if fromid == remotejids['master_id']: if message.find("hello")>=0 or message.find("hi")>=0: resp = u'marvel,欢迎您' talkonly = 1 elif message.find(u"温度")>=0 or message.find(u"多热")>=0 or message.find(u"多冷")>=0 : code, temp = sensor.read_temperature() if code < 0: resp = temp talkonly = 1 else: resp = u'marvel,您家里当前温度是%s摄氏度'%temp elif message.find(u"亮度")>=0 or message.find(u"多亮")>=0: code, brightness = sensor.read_brightness() if code < 0: resp = brightness talkonly = 1 else: desc = sensor.get_brightness_description(brightness) resp = u'marvel,您家里当前亮度是%s,%s'%(brightness, desc) elif message.find(u"图片")>=0: cm = camera.init_camera(glparams['tmp_image_file']) if camera.capture_camera(bot.cm) > 0: resp = u'已经照完' else: resp = u'照相失败' camera.release_camera(bot.cm) talkonly = 1 else: talkonly = 1 resp = u'marvel,我看不懂您的话,blush' if message.find(u"谢谢")>=0: resp = resp+u',不客气//%s'%message else: resp = resp+"//%s"%message if message.find("talkonly")>=0: talkonly = 1 sys.stdout.write("I said:%s\n"%resp) if glparams['rep_gtalk']=='true': bot.send_master_message(resp) sys.stdout.write("gtalk message sent\n") if talkonly < 0 and ( glparams['rep_twitter']=='true' or message.find(u'推一下')>=0): send_twitter_message(resp) sys.stdout.write("twitter message sent\n") if talkonly < 0 and glparams['rep_weibo']=='true': bot.send_weibo_message(resp) sys.stdout.write("weibo message sent\n") #os.write(sys.stdin.fileno(), resp) elif fromid == remotejids['weibo_id']: if message.find(u'[评论]')>=0: print "new comment received" elif message.find(u'[私信]')>=0: print "new mail received" return
#!/usr/bin/env python3 from time import sleep from sensor import read_temperature from buzzer import notify_init from cooler import turn_cooling_off, turn_cooling_on print("""raspi-chill - hardware tests - temperature sensor reading - buzzer - cooling device""") input('Press Enter (temperature sensor)') print(read_temperature()) input('Press Enter (buzzer)') notify_init() input('Press Enter (cooler 5 seconds)') turn_cooling_on() sleep(5) turn_cooling_off() print("No more tests for now!")
if not bot.xmpp_connect(): sys.stderr.write("Could not connect to server, or password mismatch!\n") sys.exit(1) print "Connected to gtalk server" tapi = twitter.Api(consumer_key=consumer_key, consumer_secret=consumer_secret, access_token_key=access_key, access_token_secret=access_secret) #, input_encoding=encoding) #tapi.SetCredentials(tid, tpassword); cl.sendInitPresence(requestRoster=0) # you may need to uncomment this for old server socketlist = {cl.Connection._sock:'xmpp',sys.stdin:'stdio'} temper_str = "" temper_code, temper = sensor.read_temperature() if temper_code<0: if glparams['psend_gtalk'] == 'true': bot.send_master_message("read temperature error: %s"%temper) sys.stderr.write("read temperature error: %s\n"%temper); # sig_exit() # exit() else: temper_str="温度是%s摄氏度,"%temper bright_str = "" bright_code, brightness = sensor.read_brightness() if bright_code<0: if glparams['psend_gtalk'] == 'true': bot.send_master_message("read brightness error:%s"%brightness) sys.stderr.write("read brightness error:%s\n"%brightness);
print "Connected to gtalk server" tapi = twitter.Api(consumer_key=consumer_key, consumer_secret=consumer_secret, access_token_key=access_key, access_token_secret=access_secret) #, input_encoding=encoding) #tapi.SetCredentials(tid, tpassword); cl.sendInitPresence( requestRoster=0) # you may need to uncomment this for old server socketlist = {cl.Connection._sock: 'xmpp', sys.stdin: 'stdio'} temper_str = "" temper_code, temper = sensor.read_temperature() if temper_code < 0: if glparams['psend_gtalk'] == 'true': bot.send_master_message("read temperature error: %s" % temper) sys.stderr.write("read temperature error: %s\n" % temper) # sig_exit() # exit() else: temper_str = "温度是%s摄氏度," % temper bright_str = "" bright_code, brightness = sensor.read_brightness() if bright_code < 0: if glparams['psend_gtalk'] == 'true': bot.send_master_message("read brightness error:%s" % brightness) sys.stderr.write("read brightness error:%s\n" % brightness)
def process_message(message, fromid, remotejids): global bot, glparams resp = "" talkonly = -1 if fromid == remotejids['master_id']: if message.find("hello") >= 0 or message.find("hi") >= 0: resp = u'marvel,欢迎您' talkonly = 1 elif message.find(u"温度") >= 0 or message.find( u"多热") >= 0 or message.find(u"多冷") >= 0: code, temp = sensor.read_temperature() if code < 0: resp = temp talkonly = 1 else: resp = u'marvel,您家里当前温度是%s摄氏度' % temp elif message.find(u"亮度") >= 0 or message.find(u"多亮") >= 0: code, brightness = sensor.read_brightness() if code < 0: resp = brightness talkonly = 1 else: desc = sensor.get_brightness_description(brightness) resp = u'marvel,您家里当前亮度是%s,%s' % (brightness, desc) elif message.find(u"图片") >= 0: cm = camera.init_camera(glparams['tmp_image_file']) if camera.capture_camera(bot.cm) > 0: resp = u'已经照完' else: resp = u'照相失败' camera.release_camera(bot.cm) talkonly = 1 else: talkonly = 1 resp = u'marvel,我看不懂您的话,blush' if message.find(u"谢谢") >= 0: resp = resp + u',不客气//%s' % message else: resp = resp + "//%s" % message if message.find("talkonly") >= 0: talkonly = 1 sys.stdout.write("I said:%s\n" % resp) if glparams['rep_gtalk'] == 'true': bot.send_master_message(resp) sys.stdout.write("gtalk message sent\n") if talkonly < 0 and (glparams['rep_twitter'] == 'true' or message.find(u'推一下') >= 0): send_twitter_message(resp) sys.stdout.write("twitter message sent\n") if talkonly < 0 and glparams['rep_weibo'] == 'true': bot.send_weibo_message(resp) sys.stdout.write("weibo message sent\n") #os.write(sys.stdin.fileno(), resp) elif fromid == remotejids['weibo_id']: if message.find(u'[评论]') >= 0: print "new comment received" elif message.find(u'[私信]') >= 0: print "new mail received" return