Researched the exact modules the user is building with and fixed three
concrete issues the earlier speculative firmware got wrong:
1. WiFi: confirmed the target board (Waveshare ESP32-P4-Module-DEV-KIT,
chip ESP32-P4NRW32) bridges WiFi through an onboard ESP32-C6
co-processor over a fixed 7-pin SDIO link (CLK18/CMD19/D0-14/D1-15/
D2-16/D3-17/RESET54, cross-confirmed against Espressif's own
esp-hosted-mcu docs). wifi_manager.c's esp_wifi_init()/esp_wifi_start()
calls don't need to change — esp_wifi_remote/esp_hosted provide a
drop-in-compatible API — but the component manifest (new
main/idf_component.yml) and sdkconfig.defaults were missing entirely.
2. Real pin conflict: the presence sensor's original UART pins (17/18)
directly collided with the SDIO CLK/D3 pins above — wiring it there
would have broken WiFi, the sensor, or both. Moved to GPIO4/5.
3. Swapped placeholder parts for the user's actual hardware:
- BME280 -> BMP280 (GY-BMP280 module): temp+pressure only, no humidity.
Rewrote the driver rather than just renaming it — the old code would
have read nonexistent humidity registers and reported garbage
forever. 3.3V-only wiring note added (the BME280 assumption of
5V-tolerant logic doesn't hold for this specific breakout).
- LD2410 -> RD-03E (Ai-Thinker, not Hi-Link — a different manufacturer
with a different, incompatible UART protocol). Rewrote the frame
parser against the RD-03E's actual (if less-documented) 5-byte
simple-report format. Reports numeric distance instead of a boolean,
which better fits both the hardware's actual output and the backend's
statistical anomaly detector.
README, CMakeLists.txt, and all cross-references updated to match.
49 lines
2.1 KiB
C
49 lines
2.1 KiB
C
// Wi-Fi station-mode connection management, using the credentials in
|
|
// device_config.h.
|
|
//
|
|
// IMPORTANT hardware note: the ESP32-P4 SoC has no integrated 2.4GHz radio.
|
|
// Confirmed against the actual target hardware (Waveshare
|
|
// ESP32-P4-Module-DEV-KIT, chip ESP32-P4NRW32): it pairs the P4 with an
|
|
// onboard ESP32-C6 co-processor over a fixed 7-pin SDIO link, and Wi-Fi is
|
|
// brought up via the `espressif/esp_wifi_remote` + `espressif/esp_hosted`
|
|
// managed components (declared in main/idf_component.yml, configured in
|
|
// sdkconfig.defaults). Those components provide a drop-in-compatible
|
|
// esp_wifi_*/esp_netif_* API — this file's esp_wifi_init()/esp_wifi_start()
|
|
// calls are unchanged from what they'd be on a Wi-Fi-native chip; only the
|
|
// component manifest and sdkconfig differ, not this code. See README.md's
|
|
// Wi-Fi section for the reserved SDIO pins (14-19, 54) and sdkconfig.defaults
|
|
// for the exact config values — still unverified against real hardware
|
|
// (nobody in this build has the physical board), but now backed by a
|
|
// specific, sourced hardware architecture rather than a general caveat.
|
|
|
|
#pragma once
|
|
|
|
#include <stdbool.h>
|
|
#include "esp_err.h"
|
|
#include "freertos/FreeRTOS.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
// Initializes NVS (required by esp_wifi), the default netif, the event
|
|
// loop, and esp_wifi in station mode, then starts connecting using
|
|
// DEVICE_WIFI_SSID / DEVICE_WIFI_PASSWORD from device_config.h. Registers
|
|
// an internal event handler that retries on disconnect with a capped
|
|
// backoff. Call once from app_main() before starting the telemetry task.
|
|
esp_err_t wifi_manager_start(void);
|
|
|
|
// Blocks (efficiently, via an internal FreeRTOS event group) until the
|
|
// station has an IP address, or until `timeout_ticks` elapses.
|
|
// Returns ESP_OK once connected, ESP_ERR_TIMEOUT otherwise.
|
|
esp_err_t wifi_manager_wait_connected(TickType_t timeout_ticks);
|
|
|
|
// True if the station currently holds an IP (i.e. the last known state is
|
|
// "connected"), for callers that want a non-blocking check (e.g. the
|
|
// telemetry task deciding whether to bother building a request this cycle).
|
|
bool wifi_manager_is_connected(void);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|