Skip to content

Instantly share code, notes, and snippets.

@kudarisenmon
Created May 17, 2025 08:15
Show Gist options
  • Select an option

  • Save kudarisenmon/d77ddc4df4e5d387ab322743a150fff3 to your computer and use it in GitHub Desktop.

Select an option

Save kudarisenmon/d77ddc4df4e5d387ab322743a150fff3 to your computer and use it in GitHub Desktop.
CO2-mini
from CO2Meter import *
import time
sensor = CO2Meter("/dev/hidraw0")
start_time = time.time()
timeout = 30 # seconds
while True:
time.sleep(1) # 短めのスリープで早めにデータ取得を試みる
data = sensor.get_data()
temperature = data.get('temperature')
co2 = data.get('co2')
if temperature is not None and co2 is not None:
print(f"Temperature: {temperature}")
print(f"CO2: {co2}")
break
if time.time() - start_time > timeout:
print("Timeout: データが取得できませんでした。")
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment