mirror of https://github.com/ARMmbed/mbed-os.git
ESP8266: sets hardcoded country code(CC) policy to track AP's CC
parent
fa65546aa2
commit
96247dd76a
|
@ -1201,4 +1201,29 @@ nsapi_connection_status_t ESP8266::connection_status() const
|
|||
{
|
||||
return _conn_status;
|
||||
}
|
||||
|
||||
bool ESP8266::set_country_code_policy(bool track_ap, const char *country_code, int channel_start, int channels)
|
||||
{
|
||||
int t_ap = track_ap ? 0 : 1;
|
||||
|
||||
_smutex.lock();
|
||||
bool done = _parser.send("AT+CWCOUNTRY_DEF=%d,\"%s\",%d,%d", t_ap, country_code, channel_start, channels)
|
||||
&& _parser.recv("OK\n");
|
||||
|
||||
if (!done) {
|
||||
tr_error("\"AT+CWCOUNTRY_DEF=%d,\"%s\",%d,%d\" - FAIL", t_ap, country_code, channel_start, channels);
|
||||
}
|
||||
|
||||
done &= _parser.send("AT+CWCOUNTRY_CUR=%d,\"%s\",%d,%d", t_ap, country_code, channel_start, channels)
|
||||
&& _parser.recv("OK\n");
|
||||
|
||||
if (!done) {
|
||||
tr_error("\"AT+CWCOUNTRY_CUR=%d,\"%s\",%d,%d\" - FAIL", t_ap, country_code, channel_start, channels);
|
||||
}
|
||||
|
||||
_smutex.unlock();
|
||||
|
||||
return done;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -335,6 +335,15 @@ public:
|
|||
*/
|
||||
bool set_default_wifi_mode(const int8_t mode);
|
||||
|
||||
/**
|
||||
* @param track_ap if TRUE, sets the county code to be the same as the AP's that ESP is connected to,
|
||||
* if FALSE the code will not change
|
||||
* @param country_code ISO 3166-1 Alpha-2 coded country code
|
||||
* @param channel_start the channel number to start at
|
||||
* @param channels number of channels
|
||||
*/
|
||||
bool set_country_code_policy(bool track_ap, const char *country_code, int channel_start, int channels);
|
||||
|
||||
/** Get the connection status
|
||||
*
|
||||
* @return The connection status according to ConnectionStatusType
|
||||
|
|
|
@ -68,6 +68,7 @@ ESP8266Interface::ESP8266Interface()
|
|||
memset(_cbs, 0, sizeof(_cbs));
|
||||
memset(ap_ssid, 0, sizeof(ap_ssid));
|
||||
memset(ap_pass, 0, sizeof(ap_pass));
|
||||
memset(_country_code, 0, sizeof(_country_code));
|
||||
|
||||
_esp.sigio(this, &ESP8266Interface::event);
|
||||
_esp.set_timeout();
|
||||
|
@ -97,6 +98,7 @@ ESP8266Interface::ESP8266Interface(PinName tx, PinName rx, bool debug, PinName r
|
|||
memset(_cbs, 0, sizeof(_cbs));
|
||||
memset(ap_ssid, 0, sizeof(ap_ssid));
|
||||
memset(ap_pass, 0, sizeof(ap_pass));
|
||||
memset(_country_code, 0, sizeof(_country_code));
|
||||
|
||||
_esp.sigio(this, &ESP8266Interface::event);
|
||||
_esp.set_timeout();
|
||||
|
@ -391,7 +393,15 @@ bool ESP8266Interface::_get_firmware_ok()
|
|||
|
||||
nsapi_error_t ESP8266Interface::_init(void)
|
||||
{
|
||||
|
||||
|
||||
if (!_initialized) {
|
||||
|
||||
if (!_country_code[0] || !_country_code[1] ) {
|
||||
strncpy(_country_code, MBED_CONF_ESP8266_COUNTRY_CODE, 2);
|
||||
_country_code[2] = '\0';
|
||||
}
|
||||
|
||||
if (_reset() != NSAPI_ERROR_OK) {
|
||||
return NSAPI_ERROR_DEVICE_ERROR;
|
||||
}
|
||||
|
@ -407,6 +417,9 @@ nsapi_error_t ESP8266Interface::_init(void)
|
|||
if (!_esp.set_default_wifi_mode(ESP8266::WIFIMODE_STATION)) {
|
||||
return NSAPI_ERROR_DEVICE_ERROR;
|
||||
}
|
||||
if (!_esp.set_country_code_policy(true, _country_code, MBED_CONF_ESP8266_CHANNEL_START, MBED_CONF_ESP8266_CHANNELS)) {
|
||||
return NSAPI_ERROR_DEVICE_ERROR;
|
||||
}
|
||||
if (!_esp.cond_enable_tcp_passive_mode()) {
|
||||
return NSAPI_ERROR_DEVICE_ERROR;
|
||||
}
|
||||
|
|
|
@ -44,6 +44,18 @@
|
|||
#endif
|
||||
#endif /* TARGET_FF_ARDUINO */
|
||||
|
||||
#ifndef MBED_CONF_ESP8266_COUNTRY_CODE
|
||||
#define MBED_CONF_ESP8266_COUNTRY_CODE "CN"
|
||||
#endif
|
||||
|
||||
#ifndef MBED_CONF_ESP8266_CHANNEL_START
|
||||
#define MBED_CONF_ESP8266_CHANNEL_START 1
|
||||
#endif
|
||||
|
||||
#ifndef MBED_CONF_ESP8266_CHANNELS
|
||||
#define MBED_CONF_ESP8266_CHANNELS 13
|
||||
#endif
|
||||
|
||||
/** ESP8266Interface class
|
||||
* Implementation of the NetworkStack for the ESP8266
|
||||
*/
|
||||
|
@ -350,6 +362,9 @@ private:
|
|||
char ap_pass[ESP8266_PASSPHRASE_MAX_LENGTH + 1]; /* The longest possible passphrase; +1 for the \0 */
|
||||
nsapi_security_t _ap_sec;
|
||||
|
||||
// Country code
|
||||
char _country_code[3]; /* ISO 3166-1 Alpha-2 coded country code plus, +1 for the \0 */
|
||||
|
||||
bool _if_blocking; // NetworkInterface, blocking or not
|
||||
rtos::ConditionVariable _if_connected;
|
||||
|
||||
|
|
Loading…
Reference in New Issue