Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix timeout error in adafruit_bme680.py #77

Merged
merged 1 commit into from
Nov 18, 2024

Conversation

savannahcofer
Copy link
Contributor

This fixes #76.

Line 393 of the library adafruit_bme680.py is written,

if start_time >= time.monotonic() - 3.0:
raise RuntimeError("Timeout while reading sensor data")

However, this is always going to return true and raise a Runtime Error regardless of your timing rate. This commit replaces line of code with the inverse of that, which is looking at the difference between the time.monotonic (the overall time) and the start_time (when you are looking at a new sensor data):

if time.monotonic() - start_time >= 3.0:
raise RuntimeError("Timeout while reading sensor data")

This fixes adafruit#76.

Line 393 of the library adafruit_bme680.py is written,

if start_time >= time.monotonic() - 3.0:
                raise RuntimeError("Timeout while reading sensor data")

However, this is always going to return true and raise a Runtime Error regardless of your timing rate. This commit replaces line of code with the inverse of that, which is looking at the difference between the time.monotonic (the overall time) and the start_time (when you are looking at a new sensor data):

if time.monotonic() - start_time >= 3.0:
                raise RuntimeError("Timeout while reading sensor data")
Copy link
Contributor

@FoamyGuy FoamyGuy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. This was a logic error on my part in a recent (attempted) fix for hanging infinitely.

Thank you for the fix @savannahcofer

@FoamyGuy FoamyGuy merged commit 6e6555b into adafruit:main Nov 18, 2024
1 check passed
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Nov 19, 2024
Updating https://github.com/adafruit/Adafruit_CircuitPython_BME680 to 3.7.11 from 3.7.10:
  > Merge pull request adafruit/Adafruit_CircuitPython_BME680#77 from savannahcofer/bugfix/script_timeout

Updating https://github.com/adafruit/Adafruit_CircuitPython_BLE to 10.0.10 from 10.0.9:
  > Merge pull request adafruit/Adafruit_CircuitPython_BLE#205 from ktnyt/hid-multiple-reports

Updating https://github.com/adafruit/Adafruit_CircuitPython_Display_Shapes to 2.10.0 from 2.9.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_Display_Shapes#76 from FoamyGuy/polygon_fill

Updating https://github.com/adafruit/Adafruit_CircuitPython_Display_Text to 3.2.0 from 3.1.7:
  > Merge pull request adafruit/Adafruit_CircuitPython_Display_Text#216 from FoamyGuy/text_box

Updating https://github.com/adafruit/Adafruit_CircuitPython_Bundle/circuitpython_library_list.md to NA from NA:
  > Updated download stats for the libraries
caternuson referenced this pull request Dec 1, 2024
timeout if we don't receive new data after too long
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RuntimeError always occurs while reading sensor data using adafruit_bme680.py
2 participants