@@ -69,6 +69,7 @@ ESP8266Interface::ESP8266Interface()
69
69
memset (ap_ssid, 0 , sizeof (ap_ssid));
70
70
memset (ap_pass, 0 , sizeof (ap_pass));
71
71
memset (_country_code, 0 , sizeof (_country_code));
72
+ strncpy (_country_code, MBED_CONF_ESP8266_COUNTRY_CODE, sizeof (_country_code));
72
73
73
74
_esp.sigio (this , &ESP8266Interface::event);
74
75
_esp.set_timeout ();
@@ -99,6 +100,7 @@ ESP8266Interface::ESP8266Interface(PinName tx, PinName rx, bool debug, PinName r
99
100
memset (ap_ssid, 0 , sizeof (ap_ssid));
100
101
memset (ap_pass, 0 , sizeof (ap_pass));
101
102
memset (_country_code, 0 , sizeof (_country_code));
103
+ strncpy (_country_code, MBED_CONF_ESP8266_COUNTRY_CODE, sizeof (_country_code));
102
104
103
105
_esp.sigio (this , &ESP8266Interface::event);
104
106
_esp.set_timeout ();
@@ -393,15 +395,7 @@ bool ESP8266Interface::_get_firmware_ok()
393
395
394
396
nsapi_error_t ESP8266Interface::_init (void )
395
397
{
396
-
397
-
398
398
if (!_initialized) {
399
-
400
- if (!_country_code[0 ] || !_country_code[1 ] ) {
401
- strncpy (_country_code, MBED_CONF_ESP8266_COUNTRY_CODE, 2 );
402
- _country_code[2 ] = ' \0 ' ;
403
- }
404
-
405
399
if (_reset () != NSAPI_ERROR_OK) {
406
400
return NSAPI_ERROR_DEVICE_ERROR;
407
401
}
@@ -868,5 +862,21 @@ nsapi_error_t ESP8266Interface::set_blocking(bool blocking)
868
862
return NSAPI_ERROR_OK;
869
863
}
870
864
865
+ nsapi_error_t ESP8266Interface::set_country_code (const char *country_code, int len)
866
+ {
867
+ for (int i = 0 ; i < len; i++) {
868
+ // Validation done by firmware
869
+ if (!country_code[i]) {
870
+ tr_warning (" invalid country code" );
871
+ return NSAPI_ERROR_PARAMETER;
872
+ }
873
+ }
874
+
875
+ // Firmware takes only first three characters
876
+ strncpy (_country_code, country_code, sizeof (_country_code));
877
+ _country_code[sizeof (_country_code)-1 ] = ' \0 ' ;
878
+
879
+ return NSAPI_ERROR_OK;
880
+ }
871
881
872
882
#endif
0 commit comments