[GH-ISSUE #601] Obtain WiFi channel after connecting to AP? #503

Closed
opened 2026-02-28 01:25:36 +03:00 by kerem · 5 comments
Owner

Originally created by @debsahu on GitHub (Apr 25, 2018).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/601

After successful connection to AP using WiFiManager, is there an easy way to get the channel of the AP it is connected to? WiFi.SSID() and WiFi.psk() give SSID and password back but can't get channel number. Since WiFiManager does a scan, can I get the channel number of the connected network using ESP8266WiFiSTAClass?

int n = WiFi.scanNetworks(false, true); // This step is already done in WiFiManger?
String ssid; uint8_t encryptionType; int32_t RSSI; uint8_t* BSSID; int32_t channel; bool isHidden;
for (int i = 0; i < n; i++) {
  WiFi.getNetworkInfo(i, ssid, encryptionType, RSSI, BSSID, channel, isHidden);
  Serial.printf("%d: %s, Ch:%d (%ddBm) %s %s\n", i + 1, ssid.c_str(), channel, RSSI, encryptionType == ENC_TYPE_NONE ? "open" : "", isHidden ? "hidden" : "");
}
Originally created by @debsahu on GitHub (Apr 25, 2018). Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/601 After successful connection to AP using WiFiManager, is there an easy way to get the channel of the AP it is connected to? `WiFi.SSID()` and `WiFi.psk()` give SSID and password back but can't get channel number. Since WiFiManager does a scan, can I get the channel number of the connected network using ESP8266WiFiSTAClass? ``` int n = WiFi.scanNetworks(false, true); // This step is already done in WiFiManger? String ssid; uint8_t encryptionType; int32_t RSSI; uint8_t* BSSID; int32_t channel; bool isHidden; for (int i = 0; i < n; i++) { WiFi.getNetworkInfo(i, ssid, encryptionType, RSSI, BSSID, channel, isHidden); Serial.printf("%d: %s, Ch:%d (%ddBm) %s %s\n", i + 1, ssid.c_str(), channel, RSSI, encryptionType == ENC_TYPE_NONE ? "open" : "", isHidden ? "hidden" : ""); } ```
kerem 2026-02-28 01:25:36 +03:00
  • closed this issue
  • added the
    Question
    label
Author
Owner

@tablatronix commented on GitHub (Apr 25, 2018):

Serial.println(WiFi.channel());

<!-- gh-comment-id:384314228 --> @tablatronix commented on GitHub (Apr 25, 2018): ` Serial.println(WiFi.channel());`
Author
Owner

@debsahu commented on GitHub (Apr 25, 2018):

I thought channel() needed a networkItem, according to https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/scan-class.html#channel I might be wrong.

<!-- gh-comment-id:384316072 --> @debsahu commented on GitHub (Apr 25, 2018): I thought channel() needed a `networkItem`, according to https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/scan-class.html#channel I might be wrong.
Author
Owner

@tablatronix commented on GitHub (Apr 25, 2018):

/**
 * Return the current channel associated with the network
 * @return channel (1-13)
 */
int32_t ESP8266WiFiGenericClass::channel(void) {
    return wifi_get_channel();
}
<!-- gh-comment-id:384318304 --> @tablatronix commented on GitHub (Apr 25, 2018): ```cpp /** * Return the current channel associated with the network * @return channel (1-13) */ int32_t ESP8266WiFiGenericClass::channel(void) { return wifi_get_channel(); } ```
Author
Owner

@debsahu commented on GitHub (Apr 25, 2018):

you the best, thank you. close?

<!-- gh-comment-id:384318786 --> @debsahu commented on GitHub (Apr 25, 2018): you the best, thank you. close?
Author
Owner

@tablatronix commented on GitHub (Apr 25, 2018):

now the scan class does have its own channel function also which is what you posted above

<!-- gh-comment-id:384319078 --> @tablatronix commented on GitHub (Apr 25, 2018): now the scan class does have its own channel function also which is what you posted above
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/WiFiManager#503
No description provided.