예제 #1
0
def get_bme280_data():
    try:
        from bme280 import bme280, bme280_i2c
        bme280_i2c.set_default_i2c_address(0x77)
        bme280_i2c.set_default_bus(1)
        bme280.setup()
        return bme280.read_all()
    except:
        state['client'].publish(state['rootkey'] + '/bme280/error',
                                str(sys.exc_info()[0]))
        return None
예제 #2
0
    def __init__(self, I2C_ADDRESS=0x76, I2C_BUS=1):
        self.lastReading = None
        self.roundDigits = 1
        self.humidity_hist = None
        self.temperature_hist = None
        self.pressure_hist = None
        self.history_size = 5
        self.historyReading = None

        bme280.bme280_i2c.set_default_i2c_address(int(str(I2C_ADDRESS), 0))
        bme280.bme280_i2c.set_default_bus(int(I2C_BUS))
        bme280.setup()
예제 #3
0
def main():
    # 初期化
    bme280_i2c.set_default_i2c_address(0x76)
    bme280_i2c.set_default_bus(1)

    # キャリブレーション
    bme280.setup()

    # データ取得
    data_all = bme280.read_all()

    # 温度、湿度、気圧の表示
    print("%7.2f hPa" % data_all.pressure)
    print("%7.2f %%" % data_all.humidity)
    print("%7.2f C" % data_all.temperature)
    return
예제 #4
0
# Use logging
logging.basicConfig(stream=sys.stderr, level=logging.INFO)

client = mqtt.Client()
mqtthost = "192.168.3.1"
mqtttopic = "stat/pi-logger"


# The callback for when the client receives a CONNACK response from the server.
def on_connect(client, userdata, flags, rc):
    logging.info("Logger started. MQTT connected with result code " + str(rc))


bme280.bme280_i2c.set_default_i2c_address(0x76)
bme280.bme280_i2c.set_default_bus(1)
bme280.setup()

client.connect(mqtthost, 1883, 60)
client.loop_start()

while True:
    data = bme280.read_all()
    datajson = json.dumps({
        'humidity': data[id_h],
        'pressure': data[id_h],
        'temperature': data[id_t]
    })
    logging.debug("Measurement data send:" + str(datajson))
    client.publish(mqtttopic, payload=datajson)
    time.sleep(60)
예제 #5
0
# copyright 2016, Mark Dyer
import shifter as S
import Tsl2591
#import BME280
from bme280 import bme280
from bme280 import bme280_i2c

bme280_i2c.set_default_i2c_address(0x77)
bme280_i2c.set_default_bus(1)
bme280.setup()

import digit_defs as digits
from ClockMessage import VALID_MODES

from datetime import datetime as dt
import time
import logging
import pigpio

class BigDisplay:
    def __init__(self, log_name, ds, latch, clk, brightnessPin, tsl_config):
        self.logger = logging.getLogger('{}.Display'.format(log_name))
        self.logger.info('Creating Display')

        self.pi = pigpio.pi()

        self.shift = S.shifter('BigClock', ds, latch, clk)
        self.digits = [' ',' ',' ',' ',' ',' ']
        self.decimals = [False, False, False, False, False, False]
        self.colons = [False, False, False];
        self.dirty = True