Skip to content
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

Uart pm25 retry #683

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ lib_deps =

; Common build environment for ESP32 platform
[common:esp32]
platform = https://github.com/pioarduino/platform-espressif32/releases/download/51.03.07/platform-espressif32.zip
platform = https://github.com/pioarduino/platform-espressif32/releases/download/53.03.11/platform-espressif32.zip
; This is needed for occasional new features and bug fixes
; platform = https://github.com/pioarduino/platform-espressif32#develop
lib_ignore = WiFiNINA, WiFi101, OneWire
Expand Down Expand Up @@ -175,9 +175,10 @@ board_build.partitions = min_spiffs.csv
extends = common:esp32
board = esp32-c6-devkitm-1
build_type = debug
debug_tool = esp-builtin
debug_init_break = tbreak ws_uart_drv_pm25aqi
build_flags =
-DARDUINO_ESPRESSIF_ESP32C6_DEVKITM_1
-DARDUINO_ADAFRUIT_FEATHER_ESP32C6
-DNDEBUG=1
-DDEBUG=1
-DESP_LOG_LEVEL=5
Expand Down Expand Up @@ -219,7 +220,7 @@ extends = common:esp32
board = adafruit_feather_esp32s3
build_flags = -DARDUINO_ADAFRUIT_FEATHER_ESP32S3 -DBOARD_HAS_PSRAM
;set partition to tinyuf2-partitions-4MB.csv as of idf 5.1
board_build.partitions = tinyuf2-partitions-4MB.csv
board_build.partitions = tinyuf2-partitions-4MB-noota.csv
extra_scripts = pre:rename_usb_config.py

; Adafruit Feather ESP32-S3 NO PSRAM
Expand Down
4 changes: 2 additions & 2 deletions src/Wippersnapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2504,9 +2504,9 @@ void Wippersnapper::runNetFSM() {
void Wippersnapper::haltError(String error, ws_led_status_t ledStatusColor,
uint8_t seconds_until_reboot) {
#ifdef ARDUINO_ARCH_ESP8266
uint8_t wdt_timeout_ms = 3200;
uint16_t wdt_timeout_ms = 3200;
#else
uint8_t wdt_timeout_ms = 5000;
uint16_t wdt_timeout_ms = 5000;
#endif
int seconds_until_wdt_enable =
seconds_until_reboot - (int)(wdt_timeout_ms / 1000);
Expand Down
3 changes: 1 addition & 2 deletions src/Wippersnapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
while (millis() - start < timeout) { \
delay(10); \
yield(); \
feedWDT(); \
if (millis() < start) { \
start = millis(); /* if rollover */ \
} \
Expand Down Expand Up @@ -96,7 +95,7 @@
{ \
unsigned long startTime = millis(); \
while (millis() - startTime < timeout) { \
result_type result_var = func(__VA_ARGS__); \
result_var = func(__VA_ARGS__); \
if (condition(result_var)) { \
break; \
} \
Expand Down
6 changes: 6 additions & 0 deletions src/Wippersnapper_Boards.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@
#define USE_STATUS_NEOPIXEL
#define STATUS_NEOPIXEL_PIN PIN_NEOPIXEL
#define STATUS_NEOPIXEL_NUM 1
#elif defined(ARDUINO_ESPRESSIF_ESP32C6_DEVKITM_1)
#define BOARD_ID "feather-esp32c6" ///< TODO: add board def
#define USE_LITTLEFS
#define USE_STATUS_NEOPIXEL
#define STATUS_NEOPIXEL_PIN 8
#define STATUS_NEOPIXEL_NUM 1
#elif defined(ARDUINO_ADAFRUIT_FEATHER_ESP32_V2)
#define BOARD_ID "feather-esp32-v2"
#define USE_LITTLEFS
Expand Down
64 changes: 33 additions & 31 deletions src/components/uart/drivers/ws_uart_drv_pm25aqi.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,35 +102,37 @@ class ws_uart_drv_pm25aqi : public ws_uart_drv {
*/
/*******************************************************************************/
bool read_data() override {
Serial.println("[UART, PM25] Reading data...");
// Attempt to read the PM2.5 Sensor
if (!_aqi->read(&_data)) {
Serial.println("[UART, PM25] Data not available.");
delay(500);
return false;
// Attempt to read the PM2.5 Sensor, can be flaky see Adafruit_PM25AQI#14
bool result = false;
RETRY_FUNCTION_UNTIL_TIMEOUT(
_aqi->read, bool, result, [](bool res) -> bool { return res == true; },
500, 100, &_data);

if (!result) {
WS_DEBUG_PRINTLN("[UART, PM25] Data not available.");
return result;
}
Serial.println("[UART, PM25] Read data OK");
Serial.println();
Serial.println(F("---------------------------------------"));
Serial.println(F("Concentration Units (standard)"));
Serial.println(F("---------------------------------------"));
Serial.print(F("PM 1.0: "));
Serial.print(_data.pm10_standard);
Serial.print(F("\t\tPM 2.5: "));
Serial.print(_data.pm25_standard);
Serial.print(F("\t\tPM 10: "));
Serial.println(_data.pm100_standard);
Serial.println(F("Concentration Units (environmental)"));
Serial.println(F("---------------------------------------"));
Serial.print(F("PM 1.0: "));
Serial.print(_data.pm10_env);
Serial.print(F("\t\tPM 2.5: "));
Serial.print(_data.pm25_env);
Serial.print(F("\t\tPM 10: "));
Serial.println(_data.pm100_env);
Serial.println(F("---------------------------------------"));

return true;
WS_DEBUG_PRINTLN("[UART, PM25] Read data OK");
WS_DEBUG_PRINTLN();
WS_DEBUG_PRINTLN(F("---------------------------------------"));
WS_DEBUG_PRINTLN(F("Concentration Units (standard)"));
WS_DEBUG_PRINTLN(F("---------------------------------------"));
WS_DEBUG_PRINT(F("PM 1.0: "));
WS_DEBUG_PRINT(_data.pm10_standard);
WS_DEBUG_PRINT(F("\t\tPM 2.5: "));
WS_DEBUG_PRINT(_data.pm25_standard);
WS_DEBUG_PRINT(F("\t\tPM 10: "));
WS_DEBUG_PRINTLN(_data.pm100_standard);
WS_DEBUG_PRINTLN(F("Concentration Units (environmental)"));
WS_DEBUG_PRINTLN(F("---------------------------------------"));
WS_DEBUG_PRINT(F("PM 1.0: "));
WS_DEBUG_PRINT(_data.pm10_env);
WS_DEBUG_PRINT(F("\t\tPM 2.5: "));
WS_DEBUG_PRINT(_data.pm25_env);
WS_DEBUG_PRINT(F("\t\tPM 10: "));
WS_DEBUG_PRINTLN(_data.pm100_env);
WS_DEBUG_PRINTLN(F("---------------------------------------"));
return result;
}

/*******************************************************************************/
Expand Down Expand Up @@ -187,17 +189,17 @@ class ws_uart_drv_pm25aqi : public ws_uart_drv {
pb_ostream_from_buffer(mqttBuffer, sizeof(mqttBuffer));
if (!ws_pb_encode(&ostream, wippersnapper_signal_v1_UARTResponse_fields,
&msgUARTResponse)) {
Serial.println("[ERROR, UART]: Unable to encode device response!");
WS_DEBUG_PRINTLN("[ERROR, UART]: Unable to encode device response!");
return;
}

// Publish message to IO
size_t msgSz;
pb_get_encoded_size(&msgSz, wippersnapper_signal_v1_UARTResponse_fields,
&msgUARTResponse);
Serial.print("[UART] Publishing event to IO..");
WS_DEBUG_PRINT("[UART] Publishing event to IO..");
mqttClient->publish(uartTopic, mqttBuffer, msgSz, 1);
Serial.println("Published!");
WS_DEBUG_PRINTLN("Published!");

setPrvPollTime(millis());
}
Expand Down
9 changes: 5 additions & 4 deletions src/network_interfaces/Wippersnapper_ESP32.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,11 @@ class Wippersnapper_ESP32 : public Wippersnapper {
// For boards with a "3D Antenna", we need to reduce the TX power
// to prevent flaky operation.
// NOTE: This is a known issue with the QT Py series of boards.
#ifdef ARDUINO_ADAFRUIT_QTPY_ESP32S2 || \
ARDUINO_ADAFRUIT_QTPY_ESP32S3_NOPSRAM || \
ARDUINO_ADAFRUIT_QTPY_ESP32S3_N4R2 || ARDUINO_ADAFRUIT_QTPY_ESP32C3 || \
ARDUINO_ADAFRUIT_QTPY_ESP32_PICO
#if defined(ARDUINO_ADAFRUIT_QTPY_ESP32S2) || \
defined(ARDUINO_ADAFRUIT_QTPY_ESP32S3_NOPSRAM) || \
defined(ARDUINO_ADAFRUIT_QTPY_ESP32S3_N4R2) || \
defined(ARDUINO_ADAFRUIT_QTPY_ESP32C3) || \
defined(ARDUINO_ADAFRUIT_QTPY_ESP32_PICO)
WiFi.setTxPower(WIFI_POWER_15dBm);
#endif

Expand Down
3 changes: 2 additions & 1 deletion src/provisioning/littlefs/WipperSnapper_LittleFS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
defined(ARDUINO_ADAFRUIT_FEATHER_ESP32_V2) || \
defined(ARDUINO_ADAFRUIT_QTPY_ESP32_PICO) || \
defined(ARDUINO_ADAFRUIT_QTPY_ESP32C3) || \
defined(ARDUINO_ADAFRUIT_FEATHER_ESP32C6)
defined(ARDUINO_ADAFRUIT_FEATHER_ESP32C6) || \
defined(ARDUINO_ESPRESSIF_ESP32C6_DEVKITM_1)
#include "WipperSnapper_LittleFS.h"

/**************************************************************************/
Expand Down
Loading