Last active
July 24, 2020 21:26
-
-
Save marcelstoer/08dc0ff6b05c73af322f4b236f3524d4 to your computer and use it in GitHub Desktop.
Publish BME280 data from Raspberry Pi to ThingSpeak
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import thingspeak # from https://thingspeak.readthedocs.io/en/latest/ | |
import bme280 # from https://www.raspberrypi-spy.co.uk/2016/07/using-bme280-i2c-temperature-pressure-sensor-in-python/ | |
# return the Pi CPU/GPU temperature in degree Celcius; it's a SoC and thus there's no need to read both, see | |
# https://www.cyberciti.biz/faq/linux-find-out-raspberry-pi-gpu-and-arm-cpu-temperature-command/#comment-796904 | |
def get_temp(): | |
with open('/sys/class/thermal/thermal_zone0/temp', 'r') as infile: | |
return float(infile.read()) * 1e-3 | |
ch = thingspeak.Channel(275145, "*********", "*********") | |
temperature, pressure, humidity = bme280.readBME280All() | |
data = {"field1": temperature, "field2": humidity, "field3": pressure, "field4": get_temp()} | |
# print(data) | |
ch.update(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment