Skip to content

Commit 565cf8b

Browse files
authored
Merge pull request #3 from Sensirion/example-update
Update example to add retry after failed read
2 parents 7a328be + 5489351 commit 565cf8b

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

.github/workflows/arduino_quality_check.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,4 @@ jobs:
1313
expect-arduino-examples: true
1414
# change to "update" once you published the driver on Arduino library registry
1515
lint-lib-manager-check: submit
16-
17-
code-generation-check:
18-
uses: sensirion/.github/.github/workflows/driver.generated.metadata_check.yml@main
1916

examples/exampleUsage/exampleUsage.ino

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,22 @@ void loop() {
107107
error = sensor.readMeasurement(co2Concentration, temperature,
108108
relativeHumidity, sensorStatus);
109109
if (error != NO_ERROR) {
110-
Serial.print("Error trying to execute readMeasurement(): ");
110+
// A failed read can be caused by clock shifting. We advise to retry
111+
// after a delay of 150ms.
112+
Serial.print(
113+
"Error trying to execute readMeasurement() (retry in 150ms): ");
111114
errorToString(error, errorMessage, sizeof errorMessage);
112115
Serial.println(errorMessage);
113-
return;
116+
delay(150);
117+
error = sensor.readMeasurement(co2Concentration, temperature,
118+
relativeHumidity, sensorStatus);
119+
if (error != NO_ERROR) {
120+
Serial.print("Error trying to execute readMeasurement() after "
121+
"additional delay: ");
122+
errorToString(error, errorMessage, sizeof errorMessage);
123+
Serial.println(errorMessage);
124+
return;
125+
}
114126
}
115127
Serial.print("co2Concentration: ");
116128
Serial.print(co2Concentration);

examples/exampleUsageSingleShot/exampleUsageSingleShot.ino

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,22 @@ void loop() {
122122
error = sensor.readMeasurement(co2Concentration, temperature,
123123
relativeHumidity, status);
124124
if (error != NO_ERROR) {
125-
Serial.print("Error trying to execute readMeasurement(): ");
125+
// A failed read can be caused by clock shifting. We advise to retry
126+
// after a delay of 150ms.
127+
Serial.print(
128+
"Error trying to execute readMeasurement() (retry in 150ms): ");
126129
errorToString(error, errorMessage, sizeof errorMessage);
127130
Serial.println(errorMessage);
128-
return;
131+
delay(150);
132+
error = sensor.readMeasurement(co2Concentration, temperature,
133+
relativeHumidity, status);
134+
if (error != NO_ERROR) {
135+
Serial.print("Error trying to execute readMeasurement() after "
136+
"additional delay: ");
137+
errorToString(error, errorMessage, sizeof errorMessage);
138+
Serial.println(errorMessage);
139+
return;
140+
}
129141
}
130142
//
131143
// Power down the sensor to reduce power consumption.

0 commit comments

Comments
 (0)