Skip to content

Commit 4578099

Browse files
committed
Offline/SD - Fix PM25 sensor
1 parent 3d969cf commit 4578099

File tree

3 files changed

+27
-12
lines changed

3 files changed

+27
-12
lines changed

src/components/uart/controller.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,22 @@ bool UARTController::Handle_UartAdd(pb_istream_t *stream) {
5757
// TODO: Have we already configured this UART hardware instance?!
5858
WS_DEBUG_PRINTLN("[uart] Configuring UART hardware instance...");
5959
wippersnapper_uart_UartSerialConfig cfg_serial = add_msg->cfg_serial;
60+
// Print out the UART configuration for debugging
61+
WS_DEBUG_PRINTLN("[uart] UART Serial Configuration:");
62+
WS_DEBUG_PRINT("[uart] RX Pin: ");
63+
WS_DEBUG_PRINTLN(cfg_serial.pin_rx);
64+
WS_DEBUG_PRINT("[uart] TX Pin: ");
65+
WS_DEBUG_PRINTLN(cfg_serial.pin_tx);
66+
WS_DEBUG_PRINT("[uart] UART Number: ");
67+
WS_DEBUG_PRINTLN(cfg_serial.uart_nbr);
68+
WS_DEBUG_PRINT("[uart] Baud Rate: ");
69+
WS_DEBUG_PRINTLN(cfg_serial.baud_rate);
70+
WS_DEBUG_PRINT("[uart] Packet Format: ");
71+
WS_DEBUG_PRINTLN(cfg_serial.format);
72+
WS_DEBUG_PRINT("[uart] Timeout: ");
73+
WS_DEBUG_PRINTLN(cfg_serial.timeout);
74+
WS_DEBUG_PRINT("[uart] Use Software Serial: ");
75+
WS_DEBUG_PRINTLN(cfg_serial.use_sw_serial ? "True" : "False");
6076
UARTHardware *uart_hardware = new UARTHardware(cfg_serial);
6177
if (!uart_hardware->ConfigureSerial()) {
6278
WS_DEBUG_PRINTLN("[uart] ERROR: Failed to configure UART hardware!");
@@ -128,7 +144,7 @@ bool UARTController::Handle_UartAdd(pb_istream_t *stream) {
128144
cfg_device.config.pm25aqi.sensor_types,
129145
cfg_device.config.pm25aqi.sensor_types_count);
130146
uart_driver->SetSensorPeriod(cfg_device.config.pm25aqi.period);
131-
WS_DEBUG_PRINT("added!");
147+
WS_DEBUG_PRINTLN("added!");
132148
break;
133149
case wippersnapper_uart_UartDeviceType_UART_DEVICE_TYPE_TM22XX:
134150
WS_DEBUG_PRINTLN("[uart] TM22XX device type not implemented!");
@@ -146,6 +162,7 @@ bool UARTController::Handle_UartAdd(pb_istream_t *stream) {
146162
if (!is_gps_drv) {
147163
WS_DEBUG_PRINTLN("[uart] STD UART drv...");
148164
did_begin = uart_driver->begin();
165+
WS_DEBUG_PRINTLN("[uart] STD UART driver initialized!");
149166
if (did_begin) {
150167
WS_DEBUG_PRINTLN("[uart] UART driver initialized successfully!");
151168
_uart_drivers.push_back(uart_driver);

src/components/uart/drivers/drvUartPm25.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,14 @@ class drvUartPm25 : public drvUartBase {
7676
@returns True if initialized successfully, False otherwise.
7777
*/
7878
bool begin() override {
79-
delay(3000); // Wait for the sensor to boot up
80-
/* if (IsSoftwareSerial)
81-
return _pm25->begin_UART(_sw_serial); */
79+
if (_hw_serial == nullptr)
80+
return false;
81+
82+
_pm25 = new Adafruit_PM25AQI();
83+
if (_pm25 == nullptr)
84+
return false;
85+
86+
delay(1000); // Wait for the sensor to boot
8287
return _pm25->begin_UART(_hw_serial);
8388
}
8489

src/provisioning/sdcard/ws_sdcard.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,6 @@ uint32_t ws_sdcard::HexStrToInt(const char *hex_str) {
474474
*/
475475
bool ws_sdcard::ParseUartAdd(JsonObject &component,
476476
wippersnapper_uart_UartAdd &msg_uart_add) {
477-
delay(5500);
478477
// Configure the Serial
479478
msg_uart_add.has_cfg_serial = true;
480479
snprintf(msg_uart_add.cfg_serial.pin_rx, sizeof(msg_uart_add.cfg_serial.pin_rx),
@@ -523,7 +522,7 @@ bool ws_sdcard::ParseUartAdd(JsonObject &component,
523522
ParseSensorType(sensor_type["type"]);
524523
sensor_type_count++;
525524
}
526-
msg_uart_add.cfg_device.config.generic_uart_input.sensor_types_count =
525+
msg_uart_add.cfg_device.config.pm25aqi.sensor_types_count =
527526
sensor_type_count;
528527
} else if (strcmp(device_type, "GENERIC-INPUT") == 0) {
529528
// TODO: Fill device name (requires an update to uart.pb.h so it's not a
@@ -1427,16 +1426,10 @@ bool ws_sdcard::LogEventUart(
14271426
doc["uart_device_id"] = msg_uart_input_event->device_id;
14281427
doc["uart_port"] = msg_uart_input_event->uart_nbr;
14291428

1430-
WS_DEBUG_PRINT("UART Events: ");
1431-
WS_DEBUG_PRINTLN(msg_uart_input_event->events_count);
14321429
// Log each event
14331430
for (pb_size_t i = 0; i < msg_uart_input_event->events_count; i++) {
14341431
doc["value"] = msg_uart_input_event->events[i].value.float_value;
14351432
doc["si_unit"] = SensorTypeToSIUnit(msg_uart_input_event->events[i].type);
1436-
WS_DEBUG_PRINT("Logging UART Event: ");
1437-
WS_DEBUG_PRINTLN(doc["value"].as<float>());
1438-
WS_DEBUG_PRINT("SI Unit: ");
1439-
WS_DEBUG_PRINTLN(doc["si_unit"].as<const char *>());
14401433
}
14411434

14421435
if (!LogJSONDoc(doc))

0 commit comments

Comments
 (0)