# Script to read data from BME280
# Sensor connected to i2c on address 76 (use sudo i2cdetect -y 1 to get the address )
# sudo python3 /var/www/nebuleair_pro_4g/BME280/read.py

import board
import busio
import json

from adafruit_bme280 import basic as adafruit_bme280

# Create I2C bus
i2c = busio.I2C(board.SCL, board.SDA)
bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c, address=0x76)

# Configure settings
bme280.sea_level_pressure = 1013.25  # Update this value for your location

# Read sensor data

#print(f"Temperature: {bme280.temperature:.2f} °C")
#print(f"Humidity: {bme280.humidity:.2f} %")
#print(f"Pressure: {bme280.pressure:.2f} hPa")
#print(f"Altitude: {bme280.altitude:.2f} m")

sensor_data = {
    "temp": round(bme280.temperature, 2),  # Temperature in °C
    "hum": round(bme280.humidity, 2),        # Humidity in %
    "press": round(bme280.pressure, 2),        # Pressure in hPa
}


# Convert to JSON and print
print(json.dumps(sensor_data, indent=4))