Linux Magazine #4 2020 – ThingsBoard listing
- August 31, 2020
- 0
import json
import os
import adafruit_bmp280
import board
import busio
import requests
i2c = busio.I2C(board.SCL, board.SDA)
bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(i2c, address=0x76)
HOST = os.getenv(“IOT_THINGSBOARD_URL”)
ACCESS_TOKEN = os.getenv(“IOT_THINGSBOARD_ACCESS_TOKEN”)
URL = f”{HOST}/api/v1/{ACCESS_TOKEN}/telemetry”
sensor_data = {}
sensor_data[“temperature”] = bmp280.temperature
sensor_data[“pressure”] = bmp280.pressure
payload = json.dumps(sensor_data)
r = requests.post(URL, data=payload)
print(r.text)