# Complete project details at https://RandomNerdTutorials.com/micropython-bme680-esp32-esp8266/ from machine import Pin, I2C from time import sleep, time, localtime import ntptime from bme680 import * import urequests as requests from secrets import secrets # ESP32 - Pin assignment i2c = I2C(scl=Pin(22), sda=Pin(21)) bme = BME680_I2C(i2c=i2c) EPOCH = 946681200 while True: try: post_data = 'indoor-weather,location=wohnzimmer' post_data += ' ' post_data += 'temp=' post_data += str(round(bme.temperature, 2)) post_data += ',hum=' post_data += str(round(bme.humidity, 2)) post_data += ',pres=' post_data += str(round(bme.pressure, 2)) post_data += ',gas=' post_data += str(round(bme.gas/1000, 2)) # post_data += ' ' # post_data += str(ntptime.time()+EPOCH) print(post_data) res = requests.post(url = secrets['influx_endpoint'], data = post_data) temp = str(round(bme.temperature, 2)) + ' C' hum = str(round(bme.humidity, 2)) + ' %' pres = str(round(bme.pressure, 2)) + ' hPa' gas = str(round(bme.gas/1000, 2)) + ' KOhms' print('Temperature:', temp) print('Humidity:', hum) print('Pressure:', pres) print('Gas:', gas) print('-------') except OSError as e: print('Failed to read sensor.') sleep(5)