Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save marcelstoer/08dc0ff6b05c73af322f4b236f3524d4 to your computer and use it in GitHub Desktop.
Save marcelstoer/08dc0ff6b05c73af322f4b236f3524d4 to your computer and use it in GitHub Desktop.
Publish BME280 data from Raspberry Pi to ThingSpeak
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