Repository navigation
Add CO2 sensing with SCD4X #4601
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
Changes from 2 commits
8fa513f
30532d4
e73ff62
f599984
c9233fe
8a4427a
a28e83c
318da22
8faf466
81f9b38
e34aada
16e2540
a1cbe8e
3cef1e8
ad7647e
7fe9efe
bac816d
726cf86
02a8414
58d916d
ef203b5
cfc355b
1eeadde
80175b1
f0775c5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| #include "configuration.h" | ||
|
|
||
| #if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR | ||
|
|
||
| #include "../mesh/generated/meshtastic/telemetry.pb.h" | ||
| #include "SCD4XSensor.h" | ||
| #include "TelemetrySensor.h" | ||
| #include <SensirionI2CScd4x.h> | ||
|
|
||
| SCD4XSensor::SCD4XSensor() : TelemetrySensor(meshtastic_TelemetrySensorType_SCD4X, "SCD4X") {} | ||
|
|
||
| int32_t SCD4XSensor::runOnce() | ||
| { | ||
| LOG_INFO("Init sensor: %s\n", sensorName); | ||
| if (!hasSensor()) { | ||
| return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS; | ||
| } | ||
| // scd4x = SensirionI2CScd4x(nodeTelemetrySensorsMap[sensorType].second); | ||
| // status = scd4x.begin(nodeTelemetrySensorsMap[sensorType].first); | ||
| scd4x.begin(*nodeTelemetrySensorsMap[sensorType].second); | ||
| scd4x.stopPeriodicMeasurement(); | ||
| status = scd4x.startLowPowerPeriodicMeasurement(); | ||
| if (status == 0) { | ||
| status = 1; | ||
| } else { | ||
| status = 0; | ||
| } | ||
| return initI2CSensor(); | ||
| } | ||
|
|
||
| void SCD4XSensor::setup() | ||
| { | ||
|
|
||
| } | ||
|
|
||
| bool SCD4XSensor::getMetrics(meshtastic_Telemetry *measurement) | ||
| { | ||
| uint16_t co2, error; | ||
| float temperature, humidity; | ||
| error = scd4x.readMeasurement( | ||
| co2, temperature, humidity | ||
| ); | ||
| if (error || co2 == 0) { | ||
| LOG_DEBUG("Skipping invalid SCD4X measurement.\n"); | ||
| return false; | ||
| } else { | ||
| measurement->variant.environment_metrics.has_temperature = true; | ||
| measurement->variant.environment_metrics.has_relative_humidity = true; | ||
| measurement->variant.environment_metrics.has_co2 = true; | ||
| measurement->variant.environment_metrics.temperature = temperature; | ||
| measurement->variant.environment_metrics.relative_humidity = humidity; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried a similar approach with an SCD30 but setting the I suggest to set the |
||
| measurement->variant.environment_metrics.co2 = co2; | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| #endif | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| #include "configuration.h" | ||
|
|
||
| #if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR | ||
|
|
||
| #include "../mesh/generated/meshtastic/telemetry.pb.h" | ||
| #include "TelemetrySensor.h" | ||
| #include <SensirionI2CScd4x.h> | ||
|
|
||
| class SCD4XSensor : public TelemetrySensor | ||
| { | ||
| private: | ||
| SensirionI2CScd4x scd4x = SensirionI2CScd4x(); | ||
|
|
||
| protected: | ||
| virtual void setup() override; | ||
|
|
||
| public: | ||
| SCD4XSensor(); | ||
| virtual int32_t runOnce() override; | ||
| virtual bool getMetrics(meshtastic_Telemetry *measurement) override; | ||
| }; | ||
|
|
||
| #endif |
Uh oh!
There was an error while loading. Please reload this page.