I am trying the python script below, the influxdb (v2.6.1) settings for URL/token/org/bucket are correct, these work on other devices, but when I run the script from the terminal I get
root@pi:/home/user# python3 temps.py
Temperature: 52.1°C | Response: 404
Any ideas? Thanks all
import os
import requests
import time
INFLUXDB_URL = "http://192.168.0.10:8086"
TOKEN = "12kjeDvikaXkvWivf_ae-bIL_ZF5TgX-lZIrZQrX495wnT5qaEx9789KGZOKxCVrRofmThb7kCxf1dX5iofr_Q=="
ORG = "myorg"
BUCKET = "test"
def get_cpu_temperature():
temp = os.popen("vcgencmd measure_temp").readline()
return float(temp.replace("temp=", "").replace("'C\n", ""))
while True:
temperature = get_cpu_temperature()
data = f"temperature value={temperature}"
payload = f"{BUCKET} data={data}"
headers = {
"Authorization": f"Token {TOKEN}",
"Content-Type": "application/x-www-form-urlencoded"
}
params = {
"org": ORG
}
response = requests.post(f"{INFLUXDB_URL}/api/v2/write", data=payload, headers=headers, params=params)
print(f"Temperature: {temperature}°C | Response: {response.status_code}")
time.sleep(60) # Send data every 60 seconds