Created
May 17, 2025 08:15
-
-
Save kudarisenmon/d77ddc4df4e5d387ab322743a150fff3 to your computer and use it in GitHub Desktop.
CO2-mini
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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