From d80c8b3813b635c15b99342648cb6cc45364a69c Mon Sep 17 00:00:00 2001 From: Mike Bell Date: Sat, 21 Jan 2023 14:00:58 +0000 Subject: [PATCH 1/9] Add concept of additional sensors and add SCD41 --- enviro/__init__.py | 15 +++++++++++++-- enviro/sensors/scd41.py | 26 ++++++++++++++++++++++++++ main.py | 4 ++-- 3 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 enviro/sensors/scd41.py diff --git a/enviro/__init__.py b/enviro/__init__.py index f92753d..09c0334 100644 --- a/enviro/__init__.py +++ b/enviro/__init__.py @@ -30,7 +30,13 @@ def get_board(): if model == "urban": import enviro.boards.urban as board return board - + +# return any additional sensors connected with Qw/ST +def get_additional_sensors(): + if 98 in i2c_devices: + import enviro.sensors.scd41 as scd41 + yield scd41 + # set up the activity led # =========================================================================== from machine import PWM, Timer @@ -411,9 +417,14 @@ def get_sensor_readings(): readings = get_board().get_sensor_readings(seconds_since_last, vbus_present) # readings["voltage"] = 0.0 # battery_voltage #Temporarily removed until issue is fixed + # Add any additional sensor readings + for sensor in get_additional_sensors(): + for key, value in sensor.get_sensor_readings(seconds_since_last).items(): + readings[key] = value + # write out the last time log with open("last_time.txt", "w") as timefile: - timefile.write(now_str) + timefile.write(now_str) return readings diff --git a/enviro/sensors/scd41.py b/enviro/sensors/scd41.py new file mode 100644 index 0000000..ae0f307 --- /dev/null +++ b/enviro/sensors/scd41.py @@ -0,0 +1,26 @@ +import time + +import breakout_scd41 + +from enviro import i2c + +breakout_scd41.init(i2c) +breakout_scd41.start() + +def get_sensor_readings(seconds_since_last): + retries = 25 + while retries > 0 and not breakout_scd41.ready(): + time.sleep(0.2) + retries -= 1 + + if retries == 0: + return {} + + scd_co2, scd_temp, scd_humidity = breakout_scd41.measure() + + from ucollections import OrderedDict + return OrderedDict({ + "scd_co2": scd_co2, + "scd_temperature": scd_temp, + "scd_humidity": scd_humidity + }) \ No newline at end of file diff --git a/main.py b/main.py index 95eff3b..de938bb 100644 --- a/main.py +++ b/main.py @@ -73,9 +73,9 @@ # here you can customise the sensor readings by adding extra information # or removing readings that you don't want, for example: # - # del readings["temperature"] # remove the temperature reading + # del reading["temperature"] # remove the temperature reading # - # readings["custom"] = my_reading() # add my custom reading value + # reading["custom"] = my_reading() # add my custom reading value # is an upload destination set? if enviro.config.destination: From f67f9a6f489f5e933169566b28ba148f354ddf86 Mon Sep 17 00:00:00 2001 From: Mike Bell Date: Tue, 24 Jan 2023 20:58:30 +0000 Subject: [PATCH 2/9] Name I2C address constants, and check for error initializing the SCD41 --- enviro/__init__.py | 14 +++++++++----- enviro/constants.py | 5 +++++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/enviro/__init__.py b/enviro/__init__.py index 09c0334..f4c4fda 100644 --- a/enviro/__init__.py +++ b/enviro/__init__.py @@ -10,9 +10,9 @@ i2c = PimoroniI2C(I2C_SDA_PIN, I2C_SCL_PIN, 100000) i2c_devices = i2c.scan() model = None -if 56 in i2c_devices: # 56 = colour / light sensor and only present on Indoor +if I2C_ADDR_BH1745 in i2c_devices: # colour / light sensor and only present on Indoor model = "indoor" -elif 35 in i2c_devices: # 35 = ltr-599 on grow & weather +elif I2C_ADDR_LTR559 in i2c_devices: # ltr-599 on grow & weather pump3_pin = Pin(12, Pin.IN, Pin.PULL_UP) model = "grow" if pump3_pin.value() == False else "weather" pump3_pin.init(pull=None) @@ -33,9 +33,13 @@ def get_board(): # return any additional sensors connected with Qw/ST def get_additional_sensors(): - if 98 in i2c_devices: - import enviro.sensors.scd41 as scd41 - yield scd41 + if I2C_ADDR_SCD41 in i2c_devices: + try: + import enviro.sensors.scd41 as scd41 + yield scd41 + except RuntimeError: + # Likely another device present on the SCD41 address + pass # set up the activity led # =========================================================================== diff --git a/enviro/constants.py b/enviro/constants.py index 78cfe8b..1cdf3fd 100644 --- a/enviro/constants.py +++ b/enviro/constants.py @@ -47,3 +47,8 @@ WATER_VAPOR_SPECIFIC_GAS_CONSTANT = 461.5 CRITICAL_WATER_TEMPERATURE = 647.096 CRITICAL_WATER_PRESSURE = 22064000 + +# I2C addresses +I2C_ADDR_BH1745 = 0x38 +I2C_ADDR_LTR559 = 0x23 +I2C_ADDR_SCD41 = 0x62 From f058cb4c84eeddbbc738af7b2c53a0c936b869cd Mon Sep 17 00:00:00 2001 From: Stephen Jefferson Date: Sat, 15 Jul 2023 15:00:51 +0100 Subject: [PATCH 3/9] BM688 in new module framework Bug fixes --- enviro/__init__.py | 26 +++++++++++++++++++------- enviro/config_defaults.py | 8 ++++++++ enviro/config_template.py | 5 +++++ enviro/qwst_modules/bme688.py | 20 ++++++++++++++++++++ 4 files changed, 52 insertions(+), 7 deletions(-) create mode 100644 enviro/qwst_modules/bme688.py diff --git a/enviro/__init__.py b/enviro/__init__.py index f4c4fda..8c5ce57 100644 --- a/enviro/__init__.py +++ b/enviro/__init__.py @@ -2,6 +2,7 @@ # =========================================================================== from enviro.constants import * from machine import Pin +import config hold_vsys_en_pin = Pin(HOLD_VSYS_EN_PIN, Pin.OUT, value=True) # detect board model based on devices on the i2c bus and pin state @@ -32,15 +33,22 @@ def get_board(): return board # return any additional sensors connected with Qw/ST -def get_additional_sensors(): +def get_qwst_modules(): if I2C_ADDR_SCD41 in i2c_devices: try: import enviro.sensors.scd41 as scd41 - yield scd41 + yield {"name": "SCD41", "include": scd41, "address": I2C_ADDR_SCD41} except RuntimeError: # Likely another device present on the SCD41 address pass + if config.bme688_address in i2c_devices: + try: + import enviro.qwst_modules.bme688 as bme688 + yield {"name": "BME688", "include": bme688, "address": config.bme688_address} + except RuntimeError: + pass + # set up the activity led # =========================================================================== from machine import PWM, Timer @@ -419,19 +427,23 @@ def get_sensor_readings(): readings = get_board().get_sensor_readings(seconds_since_last, vbus_present) + module_readings = get_qwst_modules_readings(seconds_since_last) + readings = readings | module_readings # readings["voltage"] = 0.0 # battery_voltage #Temporarily removed until issue is fixed - # Add any additional sensor readings - for sensor in get_additional_sensors(): - for key, value in sensor.get_sensor_readings(seconds_since_last).items(): - readings[key] = value - # write out the last time log with open("last_time.txt", "w") as timefile: timefile.write(now_str) return readings +def get_qwst_modules_readings(): + module_readings = {} + for module in get_qwst_modules(): + logging.info(f" - getting readings from module: {module['name']}") + module_readings = module_readings | module["include"].get_readings(i2c, module["address"], seconds_since_last) + return module_readings + # save the provided readings into a todays readings data file def save_reading(readings): # open todays reading file and save readings diff --git a/enviro/config_defaults.py b/enviro/config_defaults.py index 63a5877..060f48d 100644 --- a/enviro/config_defaults.py +++ b/enviro/config_defaults.py @@ -2,6 +2,7 @@ from phew import logging DEFAULT_USB_POWER_TEMPERATURE_OFFSET = 4.5 +DEFAULT_BME688_ADDRESS = None def add_missing_config_settings(): @@ -24,5 +25,12 @@ def add_missing_config_settings(): warn_missing_config_setting("wifi_country") config.wifi_country = "GB" + try: + config.bme688_address + except AttributeError: + warn_missing_config_setting("bme688_address") + config.bme688_address = DEFAULT_BME688_ADDRESS + + def warn_missing_config_setting(setting): logging.warn(f"> config setting '{setting}' missing, please add it to config.py") diff --git a/enviro/config_template.py b/enviro/config_template.py index 11404a9..63843fe 100644 --- a/enviro/config_template.py +++ b/enviro/config_template.py @@ -55,3 +55,8 @@ # compensate for usb power usb_power_temperature_offset = 4.5 + +# QW/ST modules +# These are modules supported out of the box, provide the I2C address if +# connected or otherwise leave as None +bme688_address = None \ No newline at end of file diff --git a/enviro/qwst_modules/bme688.py b/enviro/qwst_modules/bme688.py new file mode 100644 index 0000000..73f5fdd --- /dev/null +++ b/enviro/qwst_modules/bme688.py @@ -0,0 +1,20 @@ +from breakout_bme68x import BreakoutBME68X +from ucollections import OrderedDict +from phew import logging + +def get_readings(i2c, address): + bme688 = BreakoutBME68X(i2c) + bme688_data = bme688.read() + + readings = OrderedDict({ + "temperature_bme688": round(bme688_data[0], 2), + "humidity_bme688": round(bme688_data[2], 2), + "pressure_bme688": round(bme688_data[1] / 100.0, 2), + "gas_resistance_bme688": round(bme688_data[3], 2) + }) + + for reading in readings: + name_and_value = reading + " : " + str(readings[reading]) + logging.info(f" - {name_and_value}") + + return readings \ No newline at end of file From 07a80b8684cddaf3f28bee75940c13156e3a8119 Mon Sep 17 00:00:00 2001 From: Stephen Jefferson Date: Sat, 8 Jul 2023 11:32:17 +0100 Subject: [PATCH 4/9] Improved custom data points docs --- documentation/developer-guide.md | 23 +++++++++++++++++++++++ main.py | 13 +++++++------ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/documentation/developer-guide.md b/documentation/developer-guide.md index 9909970..b6bbf40 100644 --- a/documentation/developer-guide.md +++ b/documentation/developer-guide.md @@ -1,5 +1,28 @@ ## Tips if you want to modify the code +### Adding data points to the returned readings +#### Simple data mangling +Here you can customise the sensor readings to be saved and uploaded by adjusting the "reading" dictionary; Adding extra information or removing data points that you don't want, for example: +``` +del reading["temperature"] # remove the temperature data + +reading["custom"] = my_reading() # add my custom reading value +``` + +#### Custom module data points (BME688) +Add simple built in module calls here directly such as a BME688: + +``` +from breakout_bme68x import BreakoutBME68X +bme = BreakoutBME68X(enviro.i2c) +temperature, pressure, humidity, gas_resistance, status, gas_index, meas_index = bme.read() +reading["temperature2"] = temperature +``` +Credit: @hfg-gmuend in [#178](https://github.com/pimoroni/enviro/issues/178) + +Or add your own module to call or modify a function in the appropriate boards/*.py file + +The above code will overwrite the returned data if you use the same key name e.g. "temperature", ensure this is what you want to do, or otherwise pick a unique name for your new data point e.g. "temperature2" ### Code structure diff --git a/main.py b/main.py index de938bb..c1be85a 100644 --- a/main.py +++ b/main.py @@ -68,14 +68,15 @@ # TODO should the board auto take a reading when the timer has been set, or wait for the time? # take a reading from the onboard sensors enviro.logging.debug(f"> taking new reading") + + # Take a reading from the configured boards sensors, returns a dictionary of + # reading name and value pairs + # e.g. reading = {"temperature" : 19.1, "humidity" : 64,...} reading = enviro.get_sensor_readings() - # here you can customise the sensor readings by adding extra information - # or removing readings that you don't want, for example: - # - # del reading["temperature"] # remove the temperature reading - # - # reading["custom"] = my_reading() # add my custom reading value + # Here you can customise the returned date, adding or removing data points + # Refer to the documentation for more information: + # https://github.com/pimoroni/enviro/blob/main/documentation/developer-guide.md # is an upload destination set? if enviro.config.destination: From a798100acbc6723dfe18e636c3af35d73d6db801 Mon Sep 17 00:00:00 2001 From: Stephen Jefferson Date: Sat, 15 Jul 2023 16:07:16 +0100 Subject: [PATCH 5/9] Adjust main.py comment --- main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index c1be85a..8207cdc 100644 --- a/main.py +++ b/main.py @@ -69,8 +69,8 @@ # take a reading from the onboard sensors enviro.logging.debug(f"> taking new reading") - # Take a reading from the configured boards sensors, returns a dictionary of - # reading name and value pairs + # Take a reading from the configured boards sensors and any configured qw/st + # modules, returns a dictionary of reading name and value pairs # e.g. reading = {"temperature" : 19.1, "humidity" : 64,...} reading = enviro.get_sensor_readings() From 884f9f8ffb523e0b3e339eaed55bf4b912245b8c Mon Sep 17 00:00:00 2001 From: Stephen Jefferson Date: Sat, 15 Jul 2023 16:20:19 +0100 Subject: [PATCH 6/9] Clarity on where in which files to edit --- documentation/developer-guide.md | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/documentation/developer-guide.md b/documentation/developer-guide.md index b6bbf40..a040769 100644 --- a/documentation/developer-guide.md +++ b/documentation/developer-guide.md @@ -2,17 +2,31 @@ ## Tips if you want to modify the code ### Adding data points to the returned readings #### Simple data mangling -Here you can customise the sensor readings to be saved and uploaded by adjusting the "reading" dictionary; Adding extra information or removing data points that you don't want, for example: +You can customise the sensor readings to be saved and uploaded by adjusting the "reading" dictionary; Adding extra information or removing data points that you don't want. Make any adustments after the line populating the reading dictionary: ``` -del reading["temperature"] # remove the temperature data +reading = enviro.get_sensor_readings() +``` + +For example: +``` +reading = enviro.get_sensor_readings() +del reading["temperature"] # remove the temperature data reading["custom"] = my_reading() # add my custom reading value ``` -#### Custom module data points (BME688) -Add simple built in module calls here directly such as a BME688: +#### Custom data points (BME688 example) +Add simple built in module calls in main.py after the reading dictionary is populated and modify the reading dictionary as required +Add your code after the line: +``` +reading = enviro.get_sensor_readings() ``` + +A simple BME688 module example: +``` +reading = enviro.get_sensor_readings() + from breakout_bme68x import BreakoutBME68X bme = BreakoutBME68X(enviro.i2c) temperature, pressure, humidity, gas_resistance, status, gas_index, meas_index = bme.read() @@ -20,10 +34,11 @@ reading["temperature2"] = temperature ``` Credit: @hfg-gmuend in [#178](https://github.com/pimoroni/enviro/issues/178) -Or add your own module to call or modify a function in the appropriate boards/*.py file - The above code will overwrite the returned data if you use the same key name e.g. "temperature", ensure this is what you want to do, or otherwise pick a unique name for your new data point e.g. "temperature2" +#### Modifying specific board sensor collections +If the existing readings from a specific board require adjustment, for example adding a sea level adjusted value for atmospheric pressure readings. This should be done in the in board specific file in the boards directory, modifying the necessary lines in the get_sensor_readings() function. + ### Code structure ### Boot up process From 8959bca72d6b5ba06eb01655113e7fc626ce358b Mon Sep 17 00:00:00 2001 From: Stephen Jefferson Date: Sat, 15 Jul 2023 17:27:06 +0100 Subject: [PATCH 7/9] Documentation --- documentation/developer-guide.md | 77 ++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/documentation/developer-guide.md b/documentation/developer-guide.md index a040769..abfb025 100644 --- a/documentation/developer-guide.md +++ b/documentation/developer-guide.md @@ -36,6 +36,83 @@ Credit: @hfg-gmuend in [#178](https://github.com/pimoroni/enviro/issues/178) The above code will overwrite the returned data if you use the same key name e.g. "temperature", ensure this is what you want to do, or otherwise pick a unique name for your new data point e.g. "temperature2" +#### Adding a QW/ST globally supported module +You can add one or more module boards connected over the QW/ST connector and provide a global configuration for collecting and returning the data to the readings alongside the enviro board specific items. + +##### Method (with examples) +Add a line in config_template.py in the appropriate section to allow users to enable that board and specify an address on the I2C bus. + +Example: +``` +# QW/ST modules +# These are modules supported out of the box, provide the I2C address if +# connected or otherwise leave as None +bme688_address = None +``` + +The template should have the address set to None, config files should be manually adjusted by the user to an address value after provisioning has completed for any boards connected. + +Ensure your new configuration line has a default configuration in the config_defaults.py file to ensure firmware updates don't break older config files. + +Example: +``` +DEFAULT_BME688_ADDRESS = None + +def add_missing_config_settings(): + # <...existing default value blocks...> + + try: + config.bme688_address + except AttributeError: + warn_missing_config_setting("bme688_address") + config.bme688_address = DEFAULT_BME688_ADDRESS +``` + +Create a new python module in the enviro/qwst_modules/ directory that defines how your custom board should collect and return data to the reading dictionary. The readings must be performed in a function called get_readings that takes positional arguments i2c and address. The return of this function must be an OrderedDict{} and should contain key value pairs of reading names to values, with reading names that are likely to be unique to this board to ensure they do not overwrite other readings on upload. + +Example: + +Create file enviro/qwst_modules/bme688.py containing: +``` +from breakout_bme68x import BreakoutBME68X +from ucollections import OrderedDict +from phew import logging + +def get_readings(i2c, address): + bme688 = BreakoutBME68X(i2c) + bme688_data = bme688.read() + + readings = OrderedDict({ + "temperature_bme688": round(bme688_data[0], 2), + "humidity_bme688": round(bme688_data[2], 2), + "pressure_bme688": round(bme688_data[1] / 100.0, 2), + "gas_resistance_bme688": round(bme688_data[3], 2) + }) + + for reading in readings: + name_and_value = reading + " : " + str(readings[reading]) + logging.info(f" - {name_and_value}") + + return readings +``` + +Modify the function qwst_boards() in enviro/\_\_init\_\_.py to include an entry for your new board. This should use an if statement to check the address from the config file is visible on the I2C bus, reference your new module file path from the section above in the import statement and append a dictionary that has keys for "name", "include" and "address" to the modules list. The include key has a value of your imported module and the address is the I2C address from the config file. + +Example: +``` +def get_qwst_modules(): + modules = [] + # <...existing module configurations...> + + if config.bme688_address in i2c_devices: + import enviro.qwst_modules.bme688 as bme688 + modules.append({"name": "BME688", "include": bme688, "address": config.bme688_address}) + + return modules +``` + +To complete this example, adjust your config.py to have bme688_address = 118 with a factory address BME688 board connected via the QW/ST connector. + #### Modifying specific board sensor collections If the existing readings from a specific board require adjustment, for example adding a sea level adjusted value for atmospheric pressure readings. This should be done in the in board specific file in the boards directory, modifying the necessary lines in the get_sensor_readings() function. From 19fa8a7bd2b3e17ce95ae6a7994dc0dc03c60aea Mon Sep 17 00:00:00 2001 From: Stephen Jefferson Date: Sat, 15 Jul 2023 17:59:28 +0100 Subject: [PATCH 8/9] Fix incorrect function name --- documentation/developer-guide.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/developer-guide.md b/documentation/developer-guide.md index abfb025..5dbf3c9 100644 --- a/documentation/developer-guide.md +++ b/documentation/developer-guide.md @@ -96,7 +96,7 @@ def get_readings(i2c, address): return readings ``` -Modify the function qwst_boards() in enviro/\_\_init\_\_.py to include an entry for your new board. This should use an if statement to check the address from the config file is visible on the I2C bus, reference your new module file path from the section above in the import statement and append a dictionary that has keys for "name", "include" and "address" to the modules list. The include key has a value of your imported module and the address is the I2C address from the config file. +Modify the function get_qwst_modules() in enviro/\_\_init\_\_.py to include an entry for your new board. This should use an if statement to check the address from the config file is visible on the I2C bus, reference your new module file path from the section above in the import statement and append a dictionary that has keys for "name", "include" and "address" to the modules list. The include key has a value of your imported module and the address is the I2C address from the config file. Example: ``` From 6e0eb262997d09a54e8a8f778ed2ac9c362eef2a Mon Sep 17 00:00:00 2001 From: Mike Bell Date: Fri, 10 May 2024 22:14:42 +0100 Subject: [PATCH 9/9] Fix things up after rebase --- documentation/developer-guide.md | 34 ++++++----------------- enviro/__init__.py | 4 +-- enviro/qwst_modules/bme688.py | 2 +- enviro/{sensors => qwst_modules}/scd41.py | 8 ++---- 4 files changed, 15 insertions(+), 33 deletions(-) rename enviro/{sensors => qwst_modules}/scd41.py (77%) diff --git a/documentation/developer-guide.md b/documentation/developer-guide.md index 5dbf3c9..df2a89b 100644 --- a/documentation/developer-guide.md +++ b/documentation/developer-guide.md @@ -15,27 +15,6 @@ del reading["temperature"] # remove the temperature data reading["custom"] = my_reading() # add my custom reading value ``` -#### Custom data points (BME688 example) -Add simple built in module calls in main.py after the reading dictionary is populated and modify the reading dictionary as required - -Add your code after the line: -``` -reading = enviro.get_sensor_readings() -``` - -A simple BME688 module example: -``` -reading = enviro.get_sensor_readings() - -from breakout_bme68x import BreakoutBME68X -bme = BreakoutBME68X(enviro.i2c) -temperature, pressure, humidity, gas_resistance, status, gas_index, meas_index = bme.read() -reading["temperature2"] = temperature -``` -Credit: @hfg-gmuend in [#178](https://github.com/pimoroni/enviro/issues/178) - -The above code will overwrite the returned data if you use the same key name e.g. "temperature", ensure this is what you want to do, or otherwise pick a unique name for your new data point e.g. "temperature2" - #### Adding a QW/ST globally supported module You can add one or more module boards connected over the QW/ST connector and provide a global configuration for collecting and returning the data to the readings alongside the enviro board specific items. @@ -68,6 +47,8 @@ def add_missing_config_settings(): config.bme688_address = DEFAULT_BME688_ADDRESS ``` +Alternatively, if the module can only use a single address, you can simply add the address to constants.py + Create a new python module in the enviro/qwst_modules/ directory that defines how your custom board should collect and return data to the reading dictionary. The readings must be performed in a function called get_readings that takes positional arguments i2c and address. The return of this function must be an OrderedDict{} and should contain key value pairs of reading names to values, with reading names that are likely to be unique to this board to ensure they do not overwrite other readings on upload. Example: @@ -78,7 +59,7 @@ from breakout_bme68x import BreakoutBME68X from ucollections import OrderedDict from phew import logging -def get_readings(i2c, address): +def get_readings(i2c, address, seconds_since_last): bme688 = BreakoutBME68X(i2c) bme688_data = bme688.read() @@ -96,7 +77,7 @@ def get_readings(i2c, address): return readings ``` -Modify the function get_qwst_modules() in enviro/\_\_init\_\_.py to include an entry for your new board. This should use an if statement to check the address from the config file is visible on the I2C bus, reference your new module file path from the section above in the import statement and append a dictionary that has keys for "name", "include" and "address" to the modules list. The include key has a value of your imported module and the address is the I2C address from the config file. +Modify the function get_qwst_modules() in enviro/\_\_init\_\_.py to include an entry for your new board. This should use an if statement to check the address from the config file is visible on the I2C bus, reference your new module file path from the section above in the import statement and yield a dictionary that has keys for "name", "include" and "address" to the caller. The include key has a value of your imported module and the address is the I2C address from the config file. Example: ``` @@ -105,8 +86,11 @@ def get_qwst_modules(): # <...existing module configurations...> if config.bme688_address in i2c_devices: - import enviro.qwst_modules.bme688 as bme688 - modules.append({"name": "BME688", "include": bme688, "address": config.bme688_address}) + try: + import enviro.qwst_modules.bme688 as bme688 + yield {"name": "BME688", "include": bme688, "address": config.bme688_address} + except RuntimeError: + pass return modules ``` diff --git a/enviro/__init__.py b/enviro/__init__.py index 8c5ce57..a90943c 100644 --- a/enviro/__init__.py +++ b/enviro/__init__.py @@ -36,7 +36,7 @@ def get_board(): def get_qwst_modules(): if I2C_ADDR_SCD41 in i2c_devices: try: - import enviro.sensors.scd41 as scd41 + import enviro.qwst_modules.scd41 as scd41 yield {"name": "SCD41", "include": scd41, "address": I2C_ADDR_SCD41} except RuntimeError: # Likely another device present on the SCD41 address @@ -437,7 +437,7 @@ def get_sensor_readings(): return readings -def get_qwst_modules_readings(): +def get_qwst_modules_readings(seconds_since_last): module_readings = {} for module in get_qwst_modules(): logging.info(f" - getting readings from module: {module['name']}") diff --git a/enviro/qwst_modules/bme688.py b/enviro/qwst_modules/bme688.py index 73f5fdd..22f0ecc 100644 --- a/enviro/qwst_modules/bme688.py +++ b/enviro/qwst_modules/bme688.py @@ -2,7 +2,7 @@ from ucollections import OrderedDict from phew import logging -def get_readings(i2c, address): +def get_readings(i2c, address, seconds_since_last): bme688 = BreakoutBME68X(i2c) bme688_data = bme688.read() diff --git a/enviro/sensors/scd41.py b/enviro/qwst_modules/scd41.py similarity index 77% rename from enviro/sensors/scd41.py rename to enviro/qwst_modules/scd41.py index ae0f307..ed3b2f3 100644 --- a/enviro/sensors/scd41.py +++ b/enviro/qwst_modules/scd41.py @@ -2,12 +2,10 @@ import breakout_scd41 -from enviro import i2c +def get_readings(i2c, address, seconds_since_last): + breakout_scd41.init(i2c) + breakout_scd41.start() -breakout_scd41.init(i2c) -breakout_scd41.start() - -def get_sensor_readings(seconds_since_last): retries = 25 while retries > 0 and not breakout_scd41.ready(): time.sleep(0.2)