From a72dc3e4d90a1a3fb35588846ccb656569bb3cb9 Mon Sep 17 00:00:00 2001 From: Rastislav Vysoky Date: Tue, 7 Apr 2026 20:58:55 +0200 Subject: [PATCH] fixes for esp32 and sx1276 --- zephcore/adapters/wifi/ZephyrWiFiStation.c | 13 ++++++++ .../0004-lora-sx127x-62k5-bandwidth.patch | 32 +++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 zephcore/patches/zephyr/0004-lora-sx127x-62k5-bandwidth.patch diff --git a/zephcore/adapters/wifi/ZephyrWiFiStation.c b/zephcore/adapters/wifi/ZephyrWiFiStation.c index f0317e5..d631207 100644 --- a/zephcore/adapters/wifi/ZephyrWiFiStation.c +++ b/zephcore/adapters/wifi/ZephyrWiFiStation.c @@ -98,6 +98,19 @@ static void wifi_event_handler(struct net_mgmt_event_callback *cb, if (success) { LOG_INF("WiFi link up (SSID: %s)", s_creds ? s_creds->wifi_ssid : "?"); s_wifi_link_up = true; + /* Disable power save — WIFI_PS_MIN_MODEM (default) sleeps between + * DTIM beacons, which delays ACKs and causes the MQTT broker's TCP + * stack to retransmit and eventually RST the connection (-ECONNRESET + * in the poll loop). WIFI_PS_DISABLED keeps the radio always awake. */ + struct wifi_ps_params ps = { + .enabled = WIFI_PS_DISABLED, + .type = WIFI_PS_PARAM_STATE, + }; + if (net_mgmt(NET_REQUEST_WIFI_PS, iface, &ps, sizeof(ps)) < 0) { + LOG_WRN("Failed to disable WiFi power save"); + } else { + LOG_INF("WiFi power save disabled"); + } /* DHCP will fire ipv4_event_handler when lease is obtained */ } else { LOG_WRN("WiFi connect failed (reason=%d) — retry in 10s", reason); diff --git a/zephcore/patches/zephyr/0004-lora-sx127x-62k5-bandwidth.patch b/zephcore/patches/zephyr/0004-lora-sx127x-62k5-bandwidth.patch new file mode 100644 index 0000000..f2d971e --- /dev/null +++ b/zephcore/patches/zephyr/0004-lora-sx127x-62k5-bandwidth.patch @@ -0,0 +1,32 @@ +diff --git a/drivers/lora/loramac-node/sx12xx_common.c b/drivers/lora/loramac-node/sx12xx_common.c +index 17689720dd2..09982dc2e70 100644 +--- a/drivers/lora/loramac-node/sx12xx_common.c ++++ b/drivers/lora/loramac-node/sx12xx_common.c +@@ -195,8 +195,15 @@ static void sx12xx_ev_rx_error(void) + /** + * @brief Convert Zephyr bandwidth enum to loramac-node bandwidth index + * +- * The loramac-node library expects bandwidth as an index (0, 1, 2) into its +- * internal Bandwidths[] array, not the actual kHz value. ++ * The loramac-node library expects bandwidth as an index into its internal ++ * Bandwidths[] array (not the actual kHz value). The SX127x hardware ++ * supports sub-125 kHz LoRa bandwidths; index 3 maps to 62.5 kHz (reg BW=6). ++ * ++ * Index mapping (kept in sync with sx1276.c / sx1272.c): ++ * 0 → 125 kHz (reg BW 7) ++ * 1 → 250 kHz (reg BW 8) ++ * 2 → 500 kHz (reg BW 9) ++ * 3 → 62.5 kHz (reg BW 6) — SX127x only + * + * @param bandwidth Zephyr lora_signal_bandwidth enum value + * @param bw_idx Pointer to store the resulting bandwidth index +@@ -215,6 +222,9 @@ static int sx12xx_get_bandwidth_idx(enum lora_signal_bandwidth bandwidth, + case BW_500_KHZ: + *bw_idx = 2; + break; ++ case BW_62_KHZ: ++ *bw_idx = 3; ++ break; + default: + return -EINVAL; + }