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

275 add co2 sensor support to smibhid #276

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

sjefferson99
Copy link
Member

Add capability to add sensor modules on I2C that will poll on async loop and present their module information and readings on the API.
Fixed I2C not being defined at HID and main level to prevent incorrectly specifying different I2C parameters across the code.
Fixed updater crashing if the updates folder is not present.

@sjefferson99 sjefferson99 requested a review from sam57719 March 7, 2025 23:49
@sjefferson99 sjefferson99 linked an issue Mar 7, 2025 that may be closed by this pull request
@sjefferson99
Copy link
Member Author

Added BME280 module for easier testing.

@sjefferson99 sjefferson99 linked an issue Mar 12, 2025 that may be closed by this pull request
@sam57719
Copy link
Collaborator

Just tried some tests without any modules installed as I don't have any yet.
Generally looks good, however I was expecting a 404 not found error rather than a 500 internal server error for trying to access a sensor or its readings that doesn't exist

[2021-1-1 0:0:16][Mem: 39kB free][Error][Sensors]: Failed to load SGP30 sensor module: [Errno 5] EIO
[2021-1-1 0:0:16][Mem: 37kB free][Error][Sensors]: Failed to load BME280 sensor module: [Errno 5] EIO
[2021-1-1 0:0:16][Mem: 34kB free][Error][Sensors]: Failed to load SCD30 sensor module: 
[2025-3-12 20:48:49][Mem: 65kB free][Error][TinyWeb]: /api/sensors/%7Bmodule%7D
[2025-3-12 20:48:49][Mem: 63kB free][Error][TinyWeb]: Unhandled exception in user's method. Original error: %7Bmodule%7D
[2025-3-12 20:48:54][Mem: 65kB free][Error][TinyWeb]: /api/sensors/
[2025-3-12 20:48:54][Mem: 63kB free][Error][TinyWeb]: Unhandled exception in user's method. Original error: function missing required positional argument #2
[2025-3-12 20:48:59][Mem: 65kB free][Error][TinyWeb]: /api/sensors/readings/%7Bmodule%7D
[2025-3-12 20:48:59][Mem: 63kB free][Error][TinyWeb]: Unhandled exception in user's method. Original error: %7Bmodule%7D
[2025-3-12 20:49:43][Mem: 66kB free][Error][TinyWeb]: /api/sensors/123
[2025-3-12 20:49:44][Mem: 64kB free][Error][TinyWeb]: Unhandled exception in user's method. Original error: 123
[2025-3-12 20:50:23][Mem: 65kB free][Error][TinyWeb]: /api/sensors/crap-sensor
[2025-3-12 20:50:23][Mem: 63kB free][Error][TinyWeb]: Unhandled exception in user's method. Original error: crap-sensor

@sjefferson99
Copy link
Member Author

Not great at tinyweb/flask so have yet to really look at that, is a valid finding. But we could choose to add to a new issue to improve rather than adding complexity to this one given how big it has already grown. Any ideas how to modify the website.py file to achieve this?

@sam57719
Copy link
Collaborator

Personally I would suggest a layout more like this, grouping things better? You may disagree

Method Endpoint Description
GET /api/sensors/modules List available sensor modules
GET /api/sensors/modules/{module} List sensors in a specific module
GET /api/sensors/modules/{module}/readings/latest Get latest readings from a specific module
GET /api/sensors/readings/latest Get latest sensor readings from all modules

@sam57719
Copy link
Collaborator

R.e. the 404 thing

looks like if you do the following a 404 error is returned correctly. I tested it with a broad try/except but the KeyError looks to be the exception that gets triggered.

from http.webserver import HTTPException
...
...
...
class Modules():

    def get(self, data, sensors, logger: uLogger) -> str:
        logger.info("API request - sensors/modules")
        try:
            html = dumps(sensors.get_modules())
            logger.info(f"Return value: {html}")
        except KeyError:
            raise HTTPException(404)
        return html

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.

Add SCD-30 CO2 sensor support to SMIBHID Add CO2 sensor support to SMIBHID
2 participants