Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 8041

Troubleshooting • Re: Raspberry Pi after reboot, will not do anything.

$
0
0
Indeed...What the OP has done is implement a work around....Ideally that is buying time to fix it properly...
That is what it intended to be! It was more to keep the uptime above 50% as if it stops during the night, I am not around to go and restart it! With the restart it seems to be hovering around 90% but I know that it still with hour gaps here and there.

Personally, I think it is a OS/Not Python issue (In no way I am an expert) but here is the script (with some private details changed)

Code:

import boardimport busioimport adafruit_bme280import basicimport timeimport smbus2import bme280from gpiozero import CPUTemperaturefrom influxdb import InfluxDBClientfrom datetime import datetimeimport osimport requestsimport json# Initialize temperature sensor and InfluxDB clientcpu = CPUTemperature()influx_client = InfluxDBClient(host='localhost', port=8086, username='USERNAME', password='PASSWORD', database='DATABASE')# Create I2C busi2c = busio.I2C(board.SCL, board.SDA)# Create BME280 objectbme280 = basic.Adafruit_BME280_I2C(i2c, 0x76)# Print sensor dataprint("Temperature: {:.2f} °C".format(bme280.temperature))print("Pressure: {:.2f} hPa".format(bme280.pressure))print("Humidity: {:.2f} %".format(bme280.humidity))# Function to log CPU temperaturedef log_cpu_temperature():    val = cpu.temperature    fields_system = {"cpu_temperature": val}    json_body = [        {            "measurement": "systemstats",            "tags": {},            "fields": fields_system,        }    ]    influx_client.write_points(json_body)# Function to log BME280 sensor datadef log_bme280_data():    temperature_celsius = bme280.temperature    humidity = bme280.humidity    pressure = bme280.pressure    json_body = [        {            "measurement": "bme280",            "tags": {                "source": "bme280"            },            "fields": {                "temperature": temperature_celsius,                "humidity": humidity,                "pressure": pressure            }        }    ]    influx_client.write_points(json_body)# Infinite loop to log data every minutewhile True:    log_cpu_temperature()    log_bme280_data()    time.sleep(30)

Statistics: Posted by HumanProgrammer10000 — Sat May 03, 2025 4:42 pm



Viewing all articles
Browse latest Browse all 8041

Trending Articles