Exemple #1
0
def main():

    now = datetime.datetime.now()  # 現在の日時を取得
    # --- BME280
    temperature, pressure, humidity = bme280.readData()
    co2 = mh_z19b.getCo2()

    sensor = sensor_class.Sensor(now, humidity, temperature, pressure, co2)
    sensor.dump()

    writeCsv(sensor)
    line_notify.notify(sensor)
    line_notify.notify_for_co2(sensor)
    # TODO : if error , notify by line message.
    google_spreadsheet_writer.write(sensor)
Exemple #2
0
 def on_message(self, message):
     print("Message Received")
     while True:
         pres, temp, hum = readData()
         self.temps.append(temp)
         n_temp = len(self.temps)
         if n_temp > 12:
             self.temps = self.temps[1:]
         payload = {"temp": self.temps}
         message = json.dumps(payload)
         self.write_message(message)
         print(temp)
         print(pres)
         print(hum)
         time.sleep(5)  #何秒に一回データを取るか
Exemple #3
0
def main():
    try:
        i = 0
        for i in range(max_try + 1):
            pressure, temperature, humidity = bme280.readData()
            cpu_temp = get_cpu_temp()
            if pressure == 0 and temperature == 0 and humidity == 0:
                # wait 5 seconds and retry if failed.
                time.sleep(5)
                continue
            if not is_last_success():
                send_to_slack("Recovered from failure")
            print_csv(temperature, humidity, cpu_temp, pressure)
            return
        cpu_temp = get_cpu_temp()
        # Failed to get data.
        if is_last_success():
            send_to_slack("Failed to get data from BME280")
        print_csv(0, 0, cpu_temp, 0)
    except:
        pass
            if vVerbose.startswith('test'):
                print datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'), "direct request from", httpDall.addr[0]
            
            fileHandle = open ('/var/sensorTool/sServiceErr.log', 'a')
            fileHandle.write (str(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))+ ': direct request from ' + httpDall.addr[0] + '\n')
            fileHandle.close()
    except Exception as e:
        if vDebug:
            fileHandle = open ('/var/sensorTool/sServiceErr.log', 'a')
            fileHandle.write (str(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))+ ': ' + str(e) + '\n')
            fileHandle.close()
        pass

    # bme280 values to dictsensor
    try:
        (degC, hPa, hRel) = bme280.readData()
        dictSensors['bme280']['Time'] = vNow
        dictSensors['bme280']['T'] = round(degC, 2)
        dictSensors['bme280']['RH'] = round(hRel, 2)
        dictSensors['bme280']['hPa'] = round(hPa, 2)
        vNew = False
    except Exception as e:
        if vDebug:
            fileHandle = open ('/var/sensorTool/sServiceErr.log', 'a')
            fileHandle.write (str(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))+ ': ' + str(e) + '\n')
            fileHandle.close()
        pass    
    
    # Betrachte nur La Crosse Daten
    if str(obj)[0:3] == 'La ':
        vSensor = ast.literal_eval(str(obj)[10:])
def threadSensors(out_q, vVerbose=''):
#def threadSensors(vVerbose=''):
    vDebug = vVerbose
    vDebug = 'test'
    print str(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))+'- Anfang -'+'\n'
    if vDebug.startswith('test'):
        fileHandle = open ('/var/sensorTool/sServiceErr.log', 'w')
        fileHandle.write(str(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))+'- Anfang -'+'\n')
        fileHandle.close()
    # Empfaenger Modul starten
    rfm = Rfm69()
     
    rfm.SetParams(
        Freq=868.300,  # MHz center frequency
        Datarate=9.579,  # 17.241, #kbit/s baudrate
        ModulationType=rfm69.FSK,  # modulation
        SyncPattern=[0x2d, 0xd4],  # syncword
        Bandwidth=200,  # kHz bandwidth
        LnaGain=0x88
        )

    if vDebug.startswith('test'):
        fileHandle = open ('/var/sensorTool/sServiceErr.log', 'a')
        fileHandle.write(str(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))+'RFM initialized'+'\n')
        fileHandle.close()
        pass

 
    data = []
    dictSensors = {}
    dictSensors['bme280'] = {}

    # Werte empfangene Daten bis MAXTIME aus
    # while time.strftime('%H%M') < MAXTIME:
    refreshTime = 0
    refreshTX35 = 18
    refreshTX29 = 10
    #if vVerbose.startswith('test'):
    #    refreshTX35 = 9
    #    refreshTX29 = 5
    
    refreshTime = 0
    
    iInterval = refreshTX35 + refreshTX29 + 1
    refreshTime2 = time.time() + iInterval
    boolTX35 = True
    boolRun = True
    #iCountRuns = 0
#    while 1:
    if vDebug.startswith('test'):
        fileHandle = open ('/var/sensorTool/sServiceErr.log', 'a')
        fileHandle.write(str(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))+'SensorService starts while'+'\n')
        fileHandle.close()
        pass

    while boolRun:
        print 'while'
        #if not boolRunQ.empty():
        #    boolRun = boolRunQ.get()
        #    if vVerbose.startswith('test'):
        #        print 'T1: boolRun = ' + str(boolRun) 
            
        if time.time() > refreshTime:
             
            if boolTX35:
                try:
                    if vDebug.startswith('test'):
                        fileHandle = open ('/var/sensorTool/sServiceErr.log', 'a')
                        fileHandle.write(str(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))+': TX 35'+'\n')
                        fileHandle.close()
                        print 'TX35'
                        rfm.SetParams(Datarate=9.579),  # 17.241, #kbit/s baudrate
                except Exception as e:
                    if vDebug.startswith('test'):
                        fileHandle = open ('/var/sensorTool/sServiceErr.log', 'a')
                        fileHandle.write(str(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))+': TX35 ' + str(e)+'\n')
                        fileHandle.close()
                    pass
                refreshTime = time.time() + refreshTX35
                boolTX35 = False
            else:
                try:
                    if vDebug.startswith('test'):
                        fileHandle = open ('/var/sensorTool/sServiceErr.log', 'a')
                        fileHandle.write(str(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))+': TX 29'+'\n')
                        fileHandle.close()
                        print 'TX29'
                        rfm.SetParams(Datarate=17.241),  # 17.241, #kbit/s baudrate
                except Exception as e:
                    if vDebug.startswith('test'):
                        fileHandle = open ('/var/sensorTool/sServiceErr.log', 'a')
                        fileHandle.write(str(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))+': TX29 ' + str(e)+'\n')
                        fileHandle.close()
                        print str(e)
                    pass
                refreshTime = time.time() + refreshTX29
                boolTX35 = True
                
            #iCountRuns = iCountRuns + 1

        obj = None
        data = rfm.ReceivePacket(7)
        obj = rawsensor.CreateSensor(data)
        try:
            pass
        except Exception as e:
            if vDebug.startswith('test'):
                fileHandle = open ('/var/sensorTool/sServiceErr.log', 'a')
                fileHandle.write(str(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))+': ' + str(e)+'\n')
                fileHandle.close()
            print str(e)
            pass
            
        vNow = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')

        # bme280 values to dictsensor
        try:
            (degC, hPa, hRel) = bme280.readData()
            dictSensors['bme280']['Time'] = vNow
            dictSensors['bme280']['T'] = round(degC, 2)
            dictSensors['bme280']['RH'] = round(hRel, 2)
            dictSensors['bme280']['hPa'] = round(hPa, 2)
            vNew = False
        except Exception as e:
            if vDebug.startswith('test'):
                fileHandle = open ('/var/sensorTool/sServiceErr.log', 'a')
                fileHandle.write(str(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))+': ' + str(e)+'\n')
                fileHandle.close()
            print str(e)
            pass

        # Betrachte nur La Crosse Daten
        if str(obj)[0:3] == 'La ':
            vSensor = ast.literal_eval(str(obj)[10:])
            
            if vSensor['ID'] not in dictSensors:
                dictSensors[vSensor['ID']] = {}  

            dictSensors[vSensor['ID']]['Time'] = vNow
            if 'T' in vSensor:
                dictSensors[vSensor['ID']]['T'] = vSensor['T']
            if 'RH' in vSensor:
                dictSensors[vSensor['ID']]['RH'] = vSensor['RH']

        if vDebug.startswith('test'):
            fileHandle = open ('/var/sensorTool/sServiceErr.log', 'a')
            fileHandle.write(str(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))+': T1 Sensors:'+'\n')
            for vKey in dictSensors:
                fileHandle.write(str(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))+': T1:  ' + str(vKey) + ': ' + str(dictSensors[vKey])+'\n')
                print ': T1:  ' + str(vKey) + ': ' + str(dictSensors[vKey])+'\n'
            fileHandle.write(str(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))+': T1: out_q leer: ' + str(out_q.empty())+'\n')
            fileHandle.close()
            
        
        if time.time() > refreshTime2:
            
            if vDebug.startswith('test'):
                fileHandle = open ('/var/sensorTool/sServiceErr.log', 'a')
                fileHandle.write(str(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))+': ' + 'T1: Q.PUT nach ' + str(refreshTime2) + 's'+'\n')
                fileHandle.close()
                pass
            refreshTime2 = time.time() + iInterval
            try:
                if not out_q.empty():
                    out_q.get()
                    out_q.task_done()
           
                out_q.put(dictSensors)
            except Exception as e:
                if vDebug.startswith('test'):           
                    fileHandle = open ('/var/sensorTool/sServiceErr.log', 'a')
                    fileHandle.write(str(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))+': ' + str(e)+'\n')
                    fileHandle.close()
                print str(e)
        time.sleep(0.1)

    if vDebug.startswith('test'):
        fileHandle = open ('/var/sensorTool/sServiceErr.log', 'w')
        fileHandle.write(str(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))+'- Ende -\n')
        fileHandle.close()
Exemple #6
0
# find out private ip address -------------------------------------------------

ip = [(s.connect(('8.8.8.8', 80)), s.getsockname()[0], s.close()) for s in [socket.socket(socket.AF_INET, socket.SOCK_DGRAM)]][0][1]
print datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'), "My private IP is:", ip

# init  -----------------------------------------------------------------------

httpd = httpservice.Service(2222)
led = gpio.GPIOout(26)
refreshTime = time.time() + INTERVAL;

# loop ------------------------------------------------------------------------

while True: 
	# read temperature, pressure, humidity
	(degC, hPa, hRel) = bme280.readData() 
	# read brightness data	
	(visible, ir, lux) = tsl2591.readData() 
	# provide data to potential direct connection to port 2222
	if httpd.provideData({'temperature':degC,'humidity':hRel, 'pressure':hPa, 'illuminance':lux, 'timestamp':'ALMOST REAL TIME!'}):
		thread.start_new_thread(led.pulse, (0.1, ) )
		print datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'), "direct request from", httpd.addr[0]
	# every 10 seconds, try to send data to servers
	if time.time() > refreshTime:
		now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
		refreshTime = time.time() + INTERVAL;
		print now, "T: %.1f degC, P: %.1f hPa, phi: %.1f %%rH, E: %.0f lux" % (degC, hPa, hRel, lux)
		payload = { 'device': DEVICE_ID, 'password': PASSWORD, 'temperature': degC, 'pressure': hPa, 'humidity': hRel, 'illuminance': lux, 'localaddr': ip }
		# send data to cloud server
		if SERVER:
			try: r=requests.get( "http://"+SERVER+"/store.php", params=payload, timeout=HTTP_TIMEOUT)
        # convert to actual unit of the each sensor
        # condition:
        #   analog output of the Panel Meter was set to 2.5V=100%
        # unit = [ % , kPa]
        correctedReadOut = [
            readOutInVolt[0] * 4 * 10, (readOutInVolt[1] - 1) / 4 * 100
        ]

        measurements["level"] = correctedReadOut[0]
        measurements["pressure"] = correctedReadOut[1]

        environmentalData = [0, 0, 0]

        if foundBME280:
            try:
                environmentalData = bme280.readData(bus, bme280_address)
            except IOError as msg:
                logger.warning('BME280 did not respond: %s', msg)
            except:
                logger.warning('Somthing happend on I2C bus')

        measurements["temp"] = environmentalData[0]
        measurements["humid"] = environmentalData[2]
        measurements["atmPressure"] = environmentalData[1]

        #payload = '\"temp\":{0[0]:.3f} ,\"humid\":{0[2]:.3f} ,\"atmPressure\":{0[1]:.2f}'.format(environmentalData)
        #payload = payload + ', \"level\":{0[0]:2.5f} ,\"pressure\":{0[1]:2.5f} '.format(ADSdata)
        #payload += ', \"level\":{0[0]:4.2f} ,\"pressure\":{0[1]:4.2f} '.format(correctedReadOut)

        #payload = "{" + payload + "}"
Exemple #8
0
import json
import mhz19b
import bme280

if __name__ == '__main__':
    air_quality = {}

    mhz19b = mhz19b.mhz19b()
    data = mhz19b.read_co2()
    for key in data.keys():
        air_quality[key] = data[key]
    # print json.dumps(air_quality)

    bme280 = bme280.bme280()
    data = bme280.readData()
    for key in data.keys():
        air_quality[key] = data[key]

    if "temperature" in air_quality.keys() and "humidity" in air_quality.keys(
    ):
        t = air_quality["temperature"]["value"]
        H = air_quality["humidity"]["value"]
        discomfort_index = 0.81 * t + 0.01 * H * (0.99 * t - 14.3) + 46.3
        air_quality["discomfort_index"] = {
            "value": discomfort_index,
            "unit": None
        }

    print json.dumps(air_quality)
Exemple #9
0
def threadSensors(out_q, vVerbose=''):
    #def threadSensors(vVerbose=''):
    vDebug = vVerbose
    vDebug = 'test'
    print str(datetime.datetime.now().strftime(
        '%Y-%m-%d %H:%M:%S')) + '- Anfang -' + '\n'
    if vDebug.startswith('test'):
        fileHandle = open('/var/sensorTool/sServiceErr.log', 'w')
        fileHandle.write(
            str(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')) +
            '- Anfang -' + '\n')
        fileHandle.close()
    # Empfaenger Modul starten
    rfm = Rfm69()

    rfm.SetParams(
        Freq=868.300,  # MHz center frequency
        Datarate=9.579,  # 17.241, #kbit/s baudrate
        ModulationType=rfm69.FSK,  # modulation
        SyncPattern=[0x2d, 0xd4],  # syncword
        Bandwidth=200,  # kHz bandwidth
        LnaGain=0x88)

    if vDebug.startswith('test'):
        fileHandle = open('/var/sensorTool/sServiceErr.log', 'a')
        fileHandle.write(
            str(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')) +
            'RFM initialized' + '\n')
        fileHandle.close()
        pass

    data = []
    dictSensors = {}
    dictSensors['bme280'] = {}

    # Werte empfangene Daten bis MAXTIME aus
    # while time.strftime('%H%M') < MAXTIME:
    refreshTime = 0
    refreshTX35 = 18
    refreshTX29 = 10
    #if vVerbose.startswith('test'):
    #    refreshTX35 = 9
    #    refreshTX29 = 5

    refreshTime = 0

    iInterval = refreshTX35 + refreshTX29 + 1
    refreshTime2 = time.time() + iInterval
    boolTX35 = True
    boolRun = True
    #iCountRuns = 0
    #    while 1:
    if vDebug.startswith('test'):
        fileHandle = open('/var/sensorTool/sServiceErr.log', 'a')
        fileHandle.write(
            str(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')) +
            'SensorService starts while' + '\n')
        fileHandle.close()
        pass

    while boolRun:
        print 'while'
        #if not boolRunQ.empty():
        #    boolRun = boolRunQ.get()
        #    if vVerbose.startswith('test'):
        #        print 'T1: boolRun = ' + str(boolRun)

        if time.time() > refreshTime:

            if boolTX35:
                try:
                    if vDebug.startswith('test'):
                        fileHandle = open('/var/sensorTool/sServiceErr.log',
                                          'a')
                        fileHandle.write(
                            str(datetime.datetime.now().strftime(
                                '%Y-%m-%d %H:%M:%S')) + ': TX 35' + '\n')
                        fileHandle.close()
                        print 'TX35'
                        rfm.SetParams(
                            Datarate=9.579),  # 17.241, #kbit/s baudrate
                except Exception as e:
                    if vDebug.startswith('test'):
                        fileHandle = open('/var/sensorTool/sServiceErr.log',
                                          'a')
                        fileHandle.write(
                            str(datetime.datetime.now().strftime(
                                '%Y-%m-%d %H:%M:%S')) + ': TX35 ' + str(e) +
                            '\n')
                        fileHandle.close()
                    pass
                refreshTime = time.time() + refreshTX35
                boolTX35 = False
            else:
                try:
                    if vDebug.startswith('test'):
                        fileHandle = open('/var/sensorTool/sServiceErr.log',
                                          'a')
                        fileHandle.write(
                            str(datetime.datetime.now().strftime(
                                '%Y-%m-%d %H:%M:%S')) + ': TX 29' + '\n')
                        fileHandle.close()
                        print 'TX29'
                        rfm.SetParams(
                            Datarate=17.241),  # 17.241, #kbit/s baudrate
                except Exception as e:
                    if vDebug.startswith('test'):
                        fileHandle = open('/var/sensorTool/sServiceErr.log',
                                          'a')
                        fileHandle.write(
                            str(datetime.datetime.now().strftime(
                                '%Y-%m-%d %H:%M:%S')) + ': TX29 ' + str(e) +
                            '\n')
                        fileHandle.close()
                        print str(e)
                    pass
                refreshTime = time.time() + refreshTX29
                boolTX35 = True

            #iCountRuns = iCountRuns + 1

        obj = None
        data = rfm.ReceivePacket(7)
        obj = rawsensor.CreateSensor(data)
        try:
            pass
        except Exception as e:
            if vDebug.startswith('test'):
                fileHandle = open('/var/sensorTool/sServiceErr.log', 'a')
                fileHandle.write(
                    str(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
                    + ': ' + str(e) + '\n')
                fileHandle.close()
            print str(e)
            pass

        vNow = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')

        # bme280 values to dictsensor
        try:
            (degC, hPa, hRel) = bme280.readData()
            dictSensors['bme280']['Time'] = vNow
            dictSensors['bme280']['T'] = round(degC, 2)
            dictSensors['bme280']['RH'] = round(hRel, 2)
            dictSensors['bme280']['hPa'] = round(hPa, 2)
            vNew = False
        except Exception as e:
            if vDebug.startswith('test'):
                fileHandle = open('/var/sensorTool/sServiceErr.log', 'a')
                fileHandle.write(
                    str(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
                    + ': ' + str(e) + '\n')
                fileHandle.close()
            print str(e)
            pass

        # Betrachte nur La Crosse Daten
        if str(obj)[0:3] == 'La ':
            vSensor = ast.literal_eval(str(obj)[10:])

            if vSensor['ID'] not in dictSensors:
                dictSensors[vSensor['ID']] = {}

            dictSensors[vSensor['ID']]['Time'] = vNow
            if 'T' in vSensor:
                dictSensors[vSensor['ID']]['T'] = vSensor['T']
            if 'RH' in vSensor:
                dictSensors[vSensor['ID']]['RH'] = vSensor['RH']

        if vDebug.startswith('test'):
            fileHandle = open('/var/sensorTool/sServiceErr.log', 'a')
            fileHandle.write(
                str(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')) +
                ': T1 Sensors:' + '\n')
            for vKey in dictSensors:
                fileHandle.write(
                    str(datetime.datetime.now().strftime(
                        '%Y-%m-%d %H:%M:%S')) + ': T1:  ' + str(vKey) + ': ' +
                    str(dictSensors[vKey]) + '\n')
                print ': T1:  ' + str(vKey) + ': ' + str(
                    dictSensors[vKey]) + '\n'
            fileHandle.write(
                str(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')) +
                ': T1: out_q leer: ' + str(out_q.empty()) + '\n')
            fileHandle.close()

        if time.time() > refreshTime2:

            if vDebug.startswith('test'):
                fileHandle = open('/var/sensorTool/sServiceErr.log', 'a')
                fileHandle.write(
                    str(datetime.datetime.now().strftime(
                        '%Y-%m-%d %H:%M:%S')) + ': ' + 'T1: Q.PUT nach ' +
                    str(refreshTime2) + 's' + '\n')
                fileHandle.close()
                pass
            refreshTime2 = time.time() + iInterval
            try:
                if not out_q.empty():
                    out_q.get()
                    out_q.task_done()

                out_q.put(dictSensors)
            except Exception as e:
                if vDebug.startswith('test'):
                    fileHandle = open('/var/sensorTool/sServiceErr.log', 'a')
                    fileHandle.write(
                        str(datetime.datetime.now().strftime(
                            '%Y-%m-%d %H:%M:%S')) + ': ' + str(e) + '\n')
                    fileHandle.close()
                print str(e)
        time.sleep(0.1)

    if vDebug.startswith('test'):
        fileHandle = open('/var/sensorTool/sServiceErr.log', 'w')
        fileHandle.write(
            str(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')) +
            '- Ende -\n')
        fileHandle.close()
Exemple #10
0
    # サーバにメッセージを送る
        soracom.sendall(payload)
    # ネットワークのバッファサイズは1024。サーバからの文字列を取得する
        ret=soracom.recv(1024)
        logger.info('sent data')
    return ret

hostName='harvest.soracom.io'
portNumber=8514
resultSend=''

if __name__ == '__main__':
    bmeRead=[0.00 , 0.00, 0.00]
    interval = 18
    while True:
        bmeRead = bme280.readData()
        # print bmeRead
        payload = '\"temp\":{0[0]:.3f} ,\"humid\":{0[2]:.3f} ,\"atmPressure\":{0[1]:.2f}'.format(bmeRead)
        payload = "{" + payload + "}"

        # print payload
        logger.debug('%f - %s', time.time(),payload)

        try:
            resultSend = soraSend(hostName,portNumber,payload)
            logger.info('Result: %s', resultSend)
        except socket.gaierror as msg:
#            print("send error !")
            logger.warning('Error on sending data: %s',msg)
        except :
            logger.warning('unexpected errror occurred.')
import subprocess
import bme280

ROOTDIR = "/home/pi/HDO-Display"
CLIMATEHTML = ROOTDIR + "/html/climate.html"
CLIMATEBASE = ROOTDIR + "/html/climate.html.base"
GRAPHHTML = ROOTDIR + "/html/graph.html"
GRAPHBASE = ROOTDIR + "/html/graph.html.base"
GNUPLOT = "/usr/bin/gnuplot"
PLTFILE = ROOTDIR + "/bin/climate.plt"
PLTBASE = ROOTDIR + "/bin/climate.plt.base"

climatepngfull = ""


nowtemp, nowpress, nowhumid =  bme280.readData()
tmin = (int(nowtemp / 5) -1) *5
tmax = (int(nowtemp / 5) +3) *5
hmin = (int(nowhumid / 5) -1) *5
hmax = (int(nowhumid / 5) +3) *5

while 1:

    ## get temp and humidity

    nowtemp, nowpress, nowhumid =  bme280.readData()


    ## get localtime and check date
    logfile = ROOTDIR + '/data/' \
        + time.strftime("%Y-%m-%d") + '-logger.txt'
def sensing():
    return bme280.readData()
Exemple #13
0
#読み込み
import bme280

#初期設定
bme280.setup()
bme280.get_calib_param()

#温度(℃),気圧(hPa),湿度(%)の順でタプルとして出てくるので、アンパックして変数に代入
temp,pres,hum = bme280.readData()

#各値を表示
print(temp)
print(pres)
print(hum)
Exemple #14
0
import bme280
import datetime
from tsl2561 import TSL2561

tsl = TSL2561()
print "time:\"%s\"\ttemperature:%f\tpressure:%f\thumidity:%f\tlux:%d" % ((datetime.datetime.now(), ) + bme280.readData() + (tsl.lux(), ))
Exemple #15
0
#!/usr/bin/python
# -*- coding: latin-1 -*-

import time
import gpio
import bme280
import tsl2591 

led = gpio.GPIOout(26)

while True:
	print "Testing LED..."
	led.pulse(0.5)
	time.sleep(1)
	print "Reading Temperature/Pressure/Humidity...", 
	(degC, hPa, hRel) = bme280.readData() # read temperature, pressure, humidity
	print degC, hPa, hRel
	if (hPa!=0): led.pulse(0.5)
	time.sleep(1)
	print "Reading visible/IR light...", 
	(visible, ir, lux) = tsl2591.readData() # read brightness data	
	print visible, ir
	if (lux!=0): led.pulse(0.5)
	time.sleep(5)
Exemple #16
0
    pass
else:
    os.mkdir(ROOTDIR + '/data/')

nowtime = time.strftime("%Y-%m-%d %H:%M:%S")
time.sleep(60 - int(time.strftime("%S")))

while 1:

    if nowtime == time.strftime("%Y-%m-%d %H:%M:%S") :
        time.sleep(0.1)
        continue

    nowtime = time.strftime("%Y-%m-%d %H:%M:%S")

    ## get temp and humidity
    nowtemp, nowpress, nowhumid =  bme280.readData()


    ## get localtime and check date
    logfile = ROOTDIR + '/data/' \
        + time.strftime("%Y-%m-%d") + '-logger.txt'
    
    with open(logfile, 'a') as logwrite:

        logwrite.write('{0} {1:-6.1f} {2:6.1f} {3:6.1f}\n'.\
        format(nowtime, nowtemp, nowhumid, nowpress))

    logwrite.closed

Exemple #17
0
import bme280
import json

bme280.get_calib_param()
if __name__ == '__main__':
    try:
        print json.dumps(bme280.readData())
    except KeyboardInterrupt:
        pass
Exemple #18
0
#!/usr/bin/python3
#coding: utf-8

import time
import datetime
from spreadsheet import SpreadSheet
import bme280

# シート固有のid
sheet = SpreadSheet('xxx')

# データ取得のインターバル[sec]
delay = 600

while (1):
    start = time.time()
    d_time = datetime.datetime.now().strftime("%Y/%m/%d %H:%M:%S")
    sensor = bme280.readData()
    sheet.append([d_time, sensor[0], sensor[1], sensor[2]])
    lap = time.time() - start
    #print("lap_time:{0}".format(end) + "[sec]")
    neri = delay - lap
    time.sleep(neri)