Skip to content

Commit 7ccf609

Browse files
committed
Add error return
1 parent c12417c commit 7ccf609

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

libraries/WiFi/src/WiFiGeneric.cpp

+12-5
Original file line numberDiff line numberDiff line change
@@ -1273,27 +1273,34 @@ int32_t WiFiGenericClass::channel(void)
12731273
* Set the WiFi channel configuration
12741274
* @param primary primary channel. Depending on the region, not all channels may be available.
12751275
* @param secondary secondary channel (WIFI_SECOND_CHAN_NONE, WIFI_SECOND_CHAN_ABOVE, WIFI_SECOND_CHAN_BELOW)
1276+
* @return 0 on success, otherwise error
12761277
*/
1277-
void WiFiGenericClass::setChannel(uint8_t primary, wifi_second_chan_t secondary)
1278+
int WiFiGenericClass::setChannel(uint8_t primary, wifi_second_chan_t secondary)
12781279
{
12791280
wifi_country_t country;
1281+
esp_err_t ret;
12801282

1281-
if (esp_wifi_get_country(&country) != ESP_OK) {
1283+
ret = esp_wifi_get_country(&country);
1284+
if (ret != ESP_OK) {
12821285
log_e("Failed to get country info");
1283-
return;
1286+
return ret;
12841287
}
12851288

12861289
uint8_t min_chan = country.schan;
12871290
uint8_t max_chan = min_chan + country.nchan - 1;
12881291

12891292
if(primary < min_chan || primary > max_chan){
12901293
log_e("Invalid primary channel: %d", primary);
1291-
return;
1294+
return ESP_ERR_INVALID_ARG;
12921295
}
12931296

1294-
if (esp_wifi_set_channel(primary, secondary)) {
1297+
ret = esp_wifi_set_channel(primary, secondary);
1298+
if (ret != ESP_OK) {
12951299
log_e("Failed to set channel");
1300+
return ret;
12961301
}
1302+
1303+
return ESP_OK;
12971304
}
12981305

12991306
/**

libraries/WiFi/src/WiFiGeneric.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ class WiFiGenericClass
183183
static int waitStatusBits(int bits, uint32_t timeout_ms);
184184

185185
int32_t channel(void);
186-
void setChannel(uint8_t primary, wifi_second_chan_t secondary=WIFI_SECOND_CHAN_NONE);
186+
int setChannel(uint8_t primary, wifi_second_chan_t secondary=WIFI_SECOND_CHAN_NONE);
187187

188188
void persistent(bool persistent);
189189
void enableLongRange(bool enable);

0 commit comments

Comments
 (0)