コード例 #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
ファイル: BME280Sensor.py プロジェクト: jfhenriques/tempmqtt
    def readData(self):
        data_all = bme280.read_all()
        if data_all is None:
            return False

        if self.lastReading is None:
            self.lastReading = TempReading()

        self.lastReading.humidity = data_all.humidity
        self.lastReading.temperature = data_all.temperature
        self.lastReading.pressure = data_all.pressure
        return True
コード例 #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
    def displayTemp(self):
        data = bme280.read_all()
        temp = data.temperature

        if self.temp_scale == 'F':
            temp = self.c_to_f(temp)
        temp_str = "{:3d}*{} ".format(int(round(temp)), self.temp_scale)
        #self.logger.debug('Current Temperature: "%s"', temp_str)

        # clear colon, set decimal point
        self.clear_all()

        self.set_digit(5, temp_str[0])
        self.set_digit(4, temp_str[1])
        self.set_digit(3, temp_str[2])
        self.set_digit(2, temp_str[3])
        self.set_digit(1, temp_str[4])
        self.set_digit(0, temp_str[5])
コード例 #5
0
    def displayTemp(self):
        data = bme280.read_all()
        temp = data.temperature

        if self.temp_scale == 'F':
            temp = self.c_to_f(temp)
        temp_str = "{:3d}*{} ".format(int(round(temp)), self.temp_scale)
        #self.logger.debug('Current Temperature: "%s"', temp_str)

        # clear colon, set decimal point
        self.clear_all()

        self.set_digit(5, temp_str[0])
        self.set_digit(4, temp_str[1])
        self.set_digit(3, temp_str[2])
        self.set_digit(2, temp_str[3])
        self.set_digit(1, temp_str[4])
        self.set_digit(0, temp_str[5])
コード例 #6
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)
コード例 #7
0
button = Button(BUTTON_PIN)
bme280_i2c.set_default_i2c_address(I2C_ADDRESS)
bme280_i2c.set_default_bus(I2C_BUS)
bme280.setup()

is_stop = False  # 繰り返し継続判定用
while not is_stop:  # is_stopがFalseの間、繰り返し
    cnt = 0  # 記録するデータ数に到達したかの判定用
    values = []  # CSV出力用データを保存するリスト
    while cnt < DATA_NUM:  # DATA_NUMまでリストへ記録
        if button.is_pressed:  # スイッチの状態確認
            is_stop = True  # 停止のためTrue
            led.on()  # 保存開始のLED点灯
            break  # このwhileの処理を抜ける
        t = datetime.now()  # 現在時刻取得
        data = bme280.read_all()  # データ取得
        values.append([  # valuesリストへデータ追加
             t,  # 時刻
             data.pressure,  # 気圧
             data.humidity,  # 湿度
             data.temperature])  # 温度
        cnt += 1  # カウントアップ
        sleep(WAIT_TIME)  # WAIT_TIME秒休止
    current_datetime = datetime.now()  # ファイル名用
    file_name = current_datetime.strftime(FILE_NAME)
    mode = 'wt'  # ↑ 現在時刻からファイル名決定
    with open(file_name, mode) as file_obj:  # 記録
        csv_writer = csv.writer(file_obj)
        csv_writer.writerows(values)

led.off()  # 保存完了のLED消灯
コード例 #8
0
def print_weather():
    data = bme280.read_all()
    p = "{0:7.2f} hPa".format(data.pressure)
    h = "{0:7.2f} %".format(data.humidity)
    t = "{0:7.2f} C".format(data.temperature)
    print('{0}:{1}:{2}'.format(p, h, t))
コード例 #9
0
ファイル: sensor_file.py プロジェクト: abbasz/IoTPlants
        ubi_api.get_variable(air_temperature_ubi_api_key)

# Set up communication to BME280.
bme280_i2c.set_default_bus(i2c_bus)
bme280_i2c.set_default_i2c_address(int(bme280_address, 0))
bme280.setup()

while True:

    soil_channel_level = ReadChannel(soil_channel)
    soil_channel_volts = ConvertVolts(soil_channel_level, 4)

    light_channel_level = ReadChannel(light_channel)
    light_channel_volts = ConvertVolts(light_channel_level, 4)

    all_bme280_data = bme280.read_all()

    if is_ubisoft_requested:
        print('------------------------')
        try:
            response = light_sensor_level_ubi.save_value(
                {"value": soil_channel_level})
            print('light sensor level')
            print(response)
            response = light_sensor_volt_ubi.save_value(
                {"value": soil_channel_volts})
            print('light sensor volt')
            print(response)
            response = soil_sensor_level_ubi.save_value(
                {"value": light_channel_level})
            print('soil sensor level')