@@ -92,6 +92,9 @@ static void register_set_oled_gpio(void);
9292#if !CONFIG_ETH_UPLINK
9393static void register_scan (void );
9494#endif
95+ #if WIFI_HAS_5GHZ
96+ static void register_set_sta_band (void );
97+ #endif
9598static void register_set_vpn (void );
9699static void register_set_tz (void );
97100
@@ -298,6 +301,9 @@ void register_router(void)
298301 register_set_ap_channel ();
299302#endif
300303 register_set_hostname ();
304+ #if WIFI_HAS_5GHZ
305+ register_set_sta_band ();
306+ #endif
301307#if defined(CONFIG_IDF_TARGET_ESP32C6 )
302308 register_set_rf_switch ();
303309#endif
@@ -1244,7 +1250,14 @@ static int show(int argc, char **argv)
12441250 if (ap_connect ) {
12451251 wifi_ap_record_t ap_info ;
12461252 if (esp_wifi_sta_get_ap_info (& ap_info ) == ESP_OK ) {
1247- printf ("Uplink AP: connected (%d dBm)\n" , ap_info .rssi );
1253+ #if WIFI_HAS_5GHZ
1254+ printf ("Uplink AP: connected (ch %d, %s, %d dBm)\n" ,
1255+ ap_info .primary ,
1256+ ap_info .primary > 14 ? "5 GHz" : "2.4 GHz" ,
1257+ ap_info .rssi );
1258+ #else
1259+ printf ("Uplink AP: connected (ch %d, %d dBm)\n" , ap_info .primary , ap_info .rssi );
1260+ #endif
12481261 } else {
12491262 printf ("Uplink AP: connected\n" );
12501263 }
@@ -1360,6 +1373,14 @@ static int show(int argc, char **argv)
13601373 printf (" Enterprise: <not active>\n" );
13611374 }
13621375
1376+
1377+ #if WIFI_HAS_5GHZ
1378+ {
1379+ const char * band_names [] = {"auto" , "2.4 GHz" , "5 GHz" };
1380+ printf (" Band preference: %s\n" , band_names [sta_band <= STA_BAND_5G ? sta_band : 0 ]);
1381+ }
1382+ #endif
1383+
13631384 if (ssid != NULL ) free (ssid );
13641385 if (ent_username != NULL ) free (ent_username );
13651386 if (ent_identity != NULL ) free (ent_identity );
@@ -2248,6 +2269,52 @@ static void register_set_ap_channel(void)
22482269}
22492270#endif
22502271
2272+ #if WIFI_HAS_5GHZ
2273+ /* 'set_sta_band' command - set STA band preference (5 GHz capable targets) */
2274+ static int set_sta_band_cmd (int argc , char * * argv )
2275+ {
2276+ if (argc < 2 ) {
2277+ const char * names [] = {"auto" , "2.4 GHz" , "5 GHz" };
2278+ printf ("STA band preference: %s\n" , names [sta_band <= STA_BAND_5G ? sta_band : 0 ]);
2279+ return 0 ;
2280+ }
2281+
2282+ int band_val ;
2283+ if (strcmp (argv [1 ], "auto" ) == 0 || strcmp (argv [1 ], "0" ) == 0 ) {
2284+ band_val = STA_BAND_AUTO ;
2285+ } else if (strcmp (argv [1 ], "2.4" ) == 0 || strcmp (argv [1 ], "1" ) == 0 ) {
2286+ band_val = STA_BAND_2G ;
2287+ } else if (strcmp (argv [1 ], "5" ) == 0 || strcmp (argv [1 ], "2" ) == 0 ) {
2288+ band_val = STA_BAND_5G ;
2289+ } else {
2290+ printf ("Invalid band. Use: auto, 2.4, or 5\n" );
2291+ return 1 ;
2292+ }
2293+
2294+ esp_err_t err = set_config_param_int ("sta_band" , band_val );
2295+ if (err == ESP_OK ) {
2296+ sta_band = (uint8_t )band_val ;
2297+ const char * names [] = {"auto" , "2.4 GHz" , "5 GHz" };
2298+ printf ("STA band preference set to: %s\n" , names [band_val ]);
2299+ printf ("Restart the device for changes to take effect.\n" );
2300+ } else {
2301+ printf ("Failed to save setting\n" );
2302+ }
2303+ return err ;
2304+ }
2305+
2306+ static void register_set_sta_band (void )
2307+ {
2308+ const esp_console_cmd_t cmd = {
2309+ .command = "set_sta_band" ,
2310+ .help = "Set STA band preference (auto, 2.4, 5; requires restart)" ,
2311+ .hint = NULL ,
2312+ .func = & set_sta_band_cmd ,
2313+ };
2314+ ESP_ERROR_CHECK ( esp_console_cmd_register (& cmd ) );
2315+ }
2316+ #endif /* WIFI_HAS_5GHZ */
2317+
22512318/**
22522319 * @brief Format IP address with device name for /32 addresses
22532320 * If the IP has a full /32 mask and a matching DHCP reservation with a name,
@@ -3004,13 +3071,24 @@ static int scan_cmd(int argc, char **argv)
30043071
30053072 /* Print header */
30063073 printf ("\nFound %d networks:\n" , ap_count );
3074+ #if WIFI_HAS_5GHZ
3075+ printf ("%-32s %3s %5s %4s %-12s\n" , "SSID" , "Ch" , "Band" , "RSSI" , "Security" );
3076+ printf ("-------------------------------- --- ----- ---- ------------\n" );
3077+
3078+ for (int i = 0 ; i < ap_count ; i ++ ) {
3079+ const char * auth = auth_mode_to_str (ap_list [i ].authmode );
3080+ printf ("%-32s %3d %5s %4d %s\n" , ap_list [i ].ssid , ap_list [i ].primary ,
3081+ ap_list [i ].primary > 14 ? "5 GHz" : "2.4 G" , ap_list [i ].rssi , auth );
3082+ }
3083+ #else
30073084 printf ("%-32s %3s %4s %-12s\n" , "SSID" , "Ch" , "RSSI" , "Security" );
30083085 printf ("-------------------------------- --- ---- ------------\n" );
30093086
30103087 for (int i = 0 ; i < ap_count ; i ++ ) {
30113088 const char * auth = auth_mode_to_str (ap_list [i ].authmode );
30123089 printf ("%-32s %3d %4d %s\n" , ap_list [i ].ssid , ap_list [i ].primary , ap_list [i ].rssi , auth );
30133090 }
3091+ #endif
30143092
30153093 free (ap_list );
30163094 return 0 ;
0 commit comments