def get_meteo(): (temperature, pressure) = bmp180.readBmp180() meteo = { 'temperature': temperature, 'pressure': pressure, 'timestamp': datetime.now() } return jsonify(meteo)
def get_press(): t_array = np.zeros(10) p_array = np.zeros(10) for i in range(0, len(t_array)): t_array[i], p_array[i] = bmp.readBmp180() temperature = np.median(t_array) pressure = np.median(p_array) return temperature, pressure
def main(): global DEVICE global SMBUSID global LEDGPIO global SWITCHGPIO global INTERVAL global AUTOSHUTDOWN global THINGSPEAKKEY global THINGSPEAKURL # Check if config file exists and overwrite # default constants with new values if os.path.isfile('/boot/templogger.cfg') == True: print "Found templogger.cfg" f = open('/boot/templogger.cfg', 'r') data = f.read().splitlines() f.close() if data[0] == 'Temp Logger': print "Using templogger.cfg" DEVICE = int(data[1], 16) SMBUSID = int(data[2]) LEDGPIO = int(data[3]) SWITCHGPIO = int(data[4]) INTERVAL = int(data[5]) AUTOSHUTDOWN = int(data[6]) THINGSPEAKKEY = data[7] THINGSPEAKURL = data[8] # Setup GPIO GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) # LED on GPIO17 GPIO.setup(LEDGPIO, GPIO.OUT) # Switch on GPIO22 as input pulled LOW by default GPIO.setup(SWITCHGPIO, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) # Define what function to call when switch pressed GPIO.add_event_detect(SWITCHGPIO, GPIO.RISING, callback=switchCallback) bus = smbus.SMBus(SMBUSID) try: while True: GPIO.output(LEDGPIO, True) (temperature, pressure) = bmp180.readBmp180(DEVICE) sendData(THINGSPEAKURL, THINGSPEAKKEY, 'field1', 'field2', temperature, pressure) sys.stdout.flush() # Toggle LED while we wait for next reading for i in range(0, INTERVAL * 60): GPIO.output(LEDGPIO, not GPIO.input(LEDGPIO)) time.sleep(1) except: # Reset GPIO settings GPIO.cleanup()
def main(): global DEVICE global SMBUSID global LEDGPIO global SWITCHGPIO global INTERVAL global AUTOSHUTDOWN global THINGSPEAKKEY global THINGSPEAKURL # Check if config file exists and overwrite # default constants with new values if os.path.isfile('/boot/templogger.cfg')==True: print "Found templogger.cfg" f = open('/boot/templogger.cfg','r') data = f.read().splitlines() f.close() if data[0]=='Temp Logger': print "Using templogger.cfg" DEVICE = int(data[1],16) SMBUSID = int(data[2]) LEDGPIO = int(data[3]) SWITCHGPIO = int(data[4]) INTERVAL = int(data[5]) AUTOSHUTDOWN = int(data[6]) THINGSPEAKKEY = data[7] THINGSPEAKURL = data[8] # Setup GPIO GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) # LED on GPIO17 GPIO.setup(LEDGPIO , GPIO.OUT) # Switch on GPIO22 as input pulled LOW by default GPIO.setup(SWITCHGPIO, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) # Define what function to call when switch pressed GPIO.add_event_detect(SWITCHGPIO, GPIO.RISING, callback=switchCallback) bus = smbus.SMBus(SMBUSID) try: while True: GPIO.output(LEDGPIO, True) (temperature,pressure)=bmp180.readBmp180(DEVICE) sendData(THINGSPEAKURL,THINGSPEAKKEY,'field1','field2',temperature,pressure) sys.stdout.flush() # Toggle LED while we wait for next reading for i in range(0,INTERVAL*60): GPIO.output(LEDGPIO, not GPIO.input(LEDGPIO)) time.sleep(1) except : # Reset GPIO settings GPIO.cleanup()
def main(): sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) while True: time.sleep(1) temp, presure = bmp180.readBmp180() data = {'currentTemp': temp} #Publish temp data to the network sock.sendto(json.dumps(data), ("192.168.0.255", 4444))
def readInfo(): (temperature,pressure) = bmp180.readBmp180() print "Temperatura : {0} C".format(temperature) print "Cisnienie : {0} HPa".format(pressure) if temperature is not None and pressure is not None: return saveToDatabase(temperature,pressure),save(pressure) else: print 'nie udalo sie sprobuj ponownie!' sys.exit(1)
def main(): # Setup SPI cfg.DISP = LCD.PCD8544(cfg.DC, cfg.RST, spi=SPI.SpiDev(cfg.SPI_PORT, cfg.SPI_DEVICE, max_speed_hz=4000000)) # Initialize library cfg.DISP.begin(contrast=cfg.LCDCONTRAST) # Clear cfg.DISPlay cfg.DISP.clear() cfg.DISP.display() # Get IP address cfg.IP = getip('wlan0') # Setup GPIO GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) # Switches setup as inputs pulled HIGH by default GPIO.setup(cfg.SWITCH1, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(cfg.SWITCH2, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(cfg.SWITCH3, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Define function to call when switch pressed GPIO.add_event_detect(cfg.SWITCH1, GPIO.FALLING, callback=switch1Callback, bouncetime=300) GPIO.add_event_detect(cfg.SWITCH2, GPIO.FALLING, callback=switch2Callback, bouncetime=300) GPIO.add_event_detect(cfg.SWITCH3, GPIO.FALLING, callback=switch3Callback, bouncetime=300) bus = smbus.SMBus(cfg.SMBUSID) # Initial sensor reading (temperature, pressure) = bmp180.readBmp180(cfg.DEVICE) try: while True: sendData(cfg.THINGSPEAKURL, cfg.THINGSPEAKKEY, 'field1', 'field2', temperature, pressure) sys.stdout.flush() # 2 second loops for i in range(0, cfg.INTERVAL * 30): time.sleep(2) (temperature, pressure) = bmp180.readBmp180(cfg.DEVICE) updateAll(cfg.DISP, temperature, pressure) except: # Reset GPIO settings print "error", sys.exc_info()[0] GPIO.cleanup()
def gettime(): t = time.localtime() dtime = '%s.%s.%s %s:%s:%s ' % (t.tm_mday, t.tm_mon, t.tm_year, t.tm_hour, t.tm_min, t.tm_sec) return dtime def getparams(ptime, ttyp, tval): params = urllib.urlencode({ 'DTIME' : ptime, 'MID' : ttyp, 'VAL' : tval }) return params ltime = gettime() print('Trivadis Data Uploader for server room 5') print('Start time: %s' % ltime) lnow = getsec() if lnow > 0: print('You have to wait %s seconds to start!' % (60 - lnow)) time.sleep(60-lnow) print (temperature,pressure) = readBmp180() print('Server room data at %s: Temperature: %s C, Pressure: %s hPa' % (ltime, temperature, pressure)) response = urllib2.urlopen(url,getparams(ltime, 'TTEMP', temperature)).read() response = urllib2.urlopen(url,getparams(ltime, 'TPRES', pressure)).read()
sys.stderr.write("Terminated.\n") draw.rectangle((0,0,83,47), outline=255, fill=255) disp.image(image) disp.display() sys.exit(0) for sig in [signal.SIGTERM, signal.SIGINT, signal.SIGHUP, signal.SIGQUIT]: signal.signal(sig, signal_term_handler) #sio = io.TextIOWrapper(io.BufferedRWPair(ser, ser)) try: while 1: # Clear image buffer. draw.rectangle((0,0,83,47), outline=255, fill=255) #disp.clear() temperature = bmp180.readBmp180()[0] pressure = bmp180.readBmp180()[1] draw.text((0,0), "temp:", font=font) tempstr = str(temperature) + " C" draw.text((0,10), tempstr, font=font) draw.text((0,20), "pressure:", font=font) presstr = str(pressure) + " mbar" draw.text((0,30), presstr, font=font) # Display image. disp.image(image) disp.display() time.sleep(1) except: draw.rectangle((0,0,83,47), outline=255, fill=255) # Display image. disp.image(image)
time.time()).strftime('%Y-%m-%d %H:%M:%S') erf.write(etime) erf.write('\n') erf.write(str(e)) erf.write('\n') erf.close() time.sleep(180) # pause for 3 min to give humans time to react os.system('sudo reboot') # Pressure m_time = time.time() print "The time is...:", datetime.datetime.fromtimestamp( time.time()).strftime('%Y-%m-%d %H:%M:%S') print "Checking pressure (and bonus temperature)" try: (btemp, press) = bmp.readBmp180() press_time = time.time() print 'Temp={0:0.1f}*C Pressure={1:0.1mbar}%'.format( btemp, press) except Exception as e: Error_count += 1 print '---------------------------------------------' print 'ERROR: Failed to get pressure reading' print e print '---------------------------------------------' erf = open(error_log_name, 'a+') etime = datetime.datetime.fromtimestamp( time.time()).strftime('%Y-%m-%d %H:%M:%S') erf.write(etime) erf.write('\n')
sys.stderr.write("Terminated.\n") draw.rectangle((0,0,83,47), outline=255, fill=255) disp.image(image) disp.display() sys.exit(0) for sig in [signal.SIGTERM, signal.SIGINT, signal.SIGHUP, signal.SIGQUIT]: signal.signal(sig, signal_term_handler) #sio = io.TextIOWrapper(io.BufferedRWPair(ser, ser)) try: while 1: # Clear image buffer. draw.rectangle((0,0,83,47), outline=255, fill=255) #disp.clear() temperature = bmp180.readBmp180()[0] pressure = bmp180.readBmp180()[1] draw.text((0,0), "temp:", font=font) tempstr = str(temperature) + " C" draw.text((0,10), tempstr, font=font) draw.text((0,20), "pressure:", font=font) presstr = str(pressure) + " mbar" draw.text((0,30), presstr, font=font) # Display image. disp.image(image) disp.display() time.sleep(1) except: draw.rectangle((0,0,83,47), outline=255, fill=255) # Display image. disp.image(image)