@@ -102,35 +102,37 @@ class ws_uart_drv_pm25aqi : public ws_uart_drv {
102
102
*/
103
103
/* ******************************************************************************/
104
104
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;
111
114
}
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\t PM 2.5: " ));
120
- Serial.print (_data.pm25_standard );
121
- Serial.print (F (" \t\t PM 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\t PM 2.5: " ));
128
- Serial.print (_data.pm25_env );
129
- Serial.print (F (" \t\t PM 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\t PM 2.5: " ));
123
+ WS_DEBUG_PRINT (_data.pm25_standard );
124
+ WS_DEBUG_PRINT (F (" \t\t PM 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\t PM 2.5: " ));
131
+ WS_DEBUG_PRINT (_data.pm25_env );
132
+ WS_DEBUG_PRINT (F (" \t\t PM 10: " ));
133
+ WS_DEBUG_PRINTLN (_data.pm100_env );
134
+ WS_DEBUG_PRINTLN (F (" ---------------------------------------" ));
135
+ return result;
134
136
}
135
137
136
138
/* ******************************************************************************/
@@ -187,17 +189,17 @@ class ws_uart_drv_pm25aqi : public ws_uart_drv {
187
189
pb_ostream_from_buffer (mqttBuffer, sizeof (mqttBuffer));
188
190
if (!ws_pb_encode (&ostream, wippersnapper_signal_v1_UARTResponse_fields,
189
191
&msgUARTResponse)) {
190
- Serial. println (" [ERROR, UART]: Unable to encode device response!" );
192
+ WS_DEBUG_PRINTLN (" [ERROR, UART]: Unable to encode device response!" );
191
193
return ;
192
194
}
193
195
194
196
// Publish message to IO
195
197
size_t msgSz;
196
198
pb_get_encoded_size (&msgSz, wippersnapper_signal_v1_UARTResponse_fields,
197
199
&msgUARTResponse);
198
- Serial. print (" [UART] Publishing event to IO.." );
200
+ WS_DEBUG_PRINT (" [UART] Publishing event to IO.." );
199
201
mqttClient->publish (uartTopic, mqttBuffer, msgSz, 1 );
200
- Serial. println (" Published!" );
202
+ WS_DEBUG_PRINTLN (" Published!" );
201
203
202
204
setPrvPollTime (millis ());
203
205
}
0 commit comments