Skip to content

Commit 0ddb47f

Browse files
committed
UART PM2.5 retry data read
1 parent bab3c65 commit 0ddb47f

File tree

3 files changed

+35
-33
lines changed

3 files changed

+35
-33
lines changed

platformio.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ extends = common:esp32
220220
board = adafruit_feather_esp32s3
221221
build_flags = -DARDUINO_ADAFRUIT_FEATHER_ESP32S3 -DBOARD_HAS_PSRAM
222222
;set partition to tinyuf2-partitions-4MB.csv as of idf 5.1
223-
board_build.partitions = tinyuf2-partitions-4MB.csv
223+
board_build.partitions = tinyuf2-partitions-4MB-noota.csv
224224
extra_scripts = pre:rename_usb_config.py
225225

226226
; Adafruit Feather ESP32-S3 NO PSRAM

src/Wippersnapper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
{ \
9696
unsigned long startTime = millis(); \
9797
while (millis() - startTime < timeout) { \
98-
result_type result_var = func(__VA_ARGS__); \
98+
result_var = func(__VA_ARGS__); \
9999
if (condition(result_var)) { \
100100
break; \
101101
} \

src/components/uart/drivers/ws_uart_drv_pm25aqi.h

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -102,35 +102,37 @@ class ws_uart_drv_pm25aqi : public ws_uart_drv {
102102
*/
103103
/*******************************************************************************/
104104
bool read_data() override {
105-
Serial.println("[UART, PM25] Reading data...");
106-
// Attempt to read the PM2.5 Sensor
107-
if (!_aqi->read(&_data)) {
108-
Serial.println("[UART, PM25] Data not available.");
109-
delay(500);
110-
return false;
105+
// Attempt to read the PM2.5 Sensor, can be flaky see Adafruit_PM25AQI#14
106+
bool result = false;
107+
RETRY_FUNCTION_UNTIL_TIMEOUT(_aqi->read, bool, result,
108+
[](bool res) -> bool { return res==true; },
109+
500, 100, &_data);
110+
111+
if (!result) {
112+
WS_DEBUG_PRINTLN("[UART, PM25] Data not available.");
113+
return result;
111114
}
112-
Serial.println("[UART, PM25] Read data OK");
113-
Serial.println();
114-
Serial.println(F("---------------------------------------"));
115-
Serial.println(F("Concentration Units (standard)"));
116-
Serial.println(F("---------------------------------------"));
117-
Serial.print(F("PM 1.0: "));
118-
Serial.print(_data.pm10_standard);
119-
Serial.print(F("\t\tPM 2.5: "));
120-
Serial.print(_data.pm25_standard);
121-
Serial.print(F("\t\tPM 10: "));
122-
Serial.println(_data.pm100_standard);
123-
Serial.println(F("Concentration Units (environmental)"));
124-
Serial.println(F("---------------------------------------"));
125-
Serial.print(F("PM 1.0: "));
126-
Serial.print(_data.pm10_env);
127-
Serial.print(F("\t\tPM 2.5: "));
128-
Serial.print(_data.pm25_env);
129-
Serial.print(F("\t\tPM 10: "));
130-
Serial.println(_data.pm100_env);
131-
Serial.println(F("---------------------------------------"));
132-
133-
return true;
115+
WS_DEBUG_PRINTLN("[UART, PM25] Read data OK");
116+
WS_DEBUG_PRINTLN();
117+
WS_DEBUG_PRINTLN(F("---------------------------------------"));
118+
WS_DEBUG_PRINTLN(F("Concentration Units (standard)"));
119+
WS_DEBUG_PRINTLN(F("---------------------------------------"));
120+
WS_DEBUG_PRINT(F("PM 1.0: "));
121+
WS_DEBUG_PRINT(_data.pm10_standard);
122+
WS_DEBUG_PRINT(F("\t\tPM 2.5: "));
123+
WS_DEBUG_PRINT(_data.pm25_standard);
124+
WS_DEBUG_PRINT(F("\t\tPM 10: "));
125+
WS_DEBUG_PRINTLN(_data.pm100_standard);
126+
WS_DEBUG_PRINTLN(F("Concentration Units (environmental)"));
127+
WS_DEBUG_PRINTLN(F("---------------------------------------"));
128+
WS_DEBUG_PRINT(F("PM 1.0: "));
129+
WS_DEBUG_PRINT(_data.pm10_env);
130+
WS_DEBUG_PRINT(F("\t\tPM 2.5: "));
131+
WS_DEBUG_PRINT(_data.pm25_env);
132+
WS_DEBUG_PRINT(F("\t\tPM 10: "));
133+
WS_DEBUG_PRINTLN(_data.pm100_env);
134+
WS_DEBUG_PRINTLN(F("---------------------------------------"));
135+
return result;
134136
}
135137

136138
/*******************************************************************************/
@@ -187,17 +189,17 @@ class ws_uart_drv_pm25aqi : public ws_uart_drv {
187189
pb_ostream_from_buffer(mqttBuffer, sizeof(mqttBuffer));
188190
if (!ws_pb_encode(&ostream, wippersnapper_signal_v1_UARTResponse_fields,
189191
&msgUARTResponse)) {
190-
Serial.println("[ERROR, UART]: Unable to encode device response!");
192+
WS_DEBUG_PRINTLN("[ERROR, UART]: Unable to encode device response!");
191193
return;
192194
}
193195

194196
// Publish message to IO
195197
size_t msgSz;
196198
pb_get_encoded_size(&msgSz, wippersnapper_signal_v1_UARTResponse_fields,
197199
&msgUARTResponse);
198-
Serial.print("[UART] Publishing event to IO..");
200+
WS_DEBUG_PRINT("[UART] Publishing event to IO..");
199201
mqttClient->publish(uartTopic, mqttBuffer, msgSz, 1);
200-
Serial.println("Published!");
202+
WS_DEBUG_PRINTLN("Published!");
201203

202204
setPrvPollTime(millis());
203205
}

0 commit comments

Comments
 (0)