Skip to content

Commit

Permalink
- fixed scan (timeouts and response parsing)
Browse files Browse the repository at this point in the history
  • Loading branch information
alejandrosklar committed Sep 3, 2019
1 parent 36b148d commit 3f42df9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 21 deletions.
29 changes: 15 additions & 14 deletions ESP32/ESP32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ void ESP32::_startup_common()
}

_serial.set_baud(MBED_CONF_ESP32_WIFI_BAUDRATE);
setTimeout(10000);
if (_p_wifi_io0 != NULL) {
_p_wifi_io0->write(1);
}
Expand All @@ -196,10 +197,10 @@ void ESP32::_startup_common()
_p_wifi_en->write(1);
_parser.recv("ready");
} else {
setTimeout(100);
_parser.recv("ready");
}

setTimeout();

reset();

_init_end_common = true;
Expand Down Expand Up @@ -375,9 +376,8 @@ bool ESP32::reset(void)
if (_parser.send("AT+RST")
&& _parser.recv("OK")) {
_serial.set_baud(ESP32_DEFAULT_BAUD_RATE);
#if MBED_CONF_ESP32_WIFI_SERIAL_FC
_serial.set_flow_control(SerialBase::Disabled);
#endif

setTimeout(10000);
_parser.recv("ready");
_clear_socket_packets(ESP32_ALL_SOCKET_IDS);
Expand All @@ -403,6 +403,7 @@ bool ESP32::reset(void)
}
#endif
}
setTimeout();

_parser.send("ATE0");
_parser.recv("OK");
Expand Down Expand Up @@ -676,10 +677,12 @@ int ESP32::scan(WiFiAccessPoint *res, unsigned limit)
if (_init_end_wifi) {
_smutex.lock();
setTimeout(5000);
if (!_parser.send("AT+CWLAP")) {
_parser.send("AT+CWLAP");

/*if (!_parser.send("AT+CWLAP")) {
_smutex.unlock();
return NSAPI_ERROR_DEVICE_ERROR;
}
}*/

while (recv_ap(&ap)) {
if (cnt < limit) {
Expand All @@ -688,11 +691,11 @@ int ESP32::scan(WiFiAccessPoint *res, unsigned limit)

cnt++;
if ((limit != 0) && (cnt >= limit)) {
setTimeout(10);
setTimeout();
_parser.recv("OK");
break;
}
setTimeout(500);
setTimeout(1000);
}

setTimeout();
Expand Down Expand Up @@ -980,7 +983,7 @@ bool ESP32::recv_ap(nsapi_wifi_ap_t *ap)
const char keyword_1[6] = "\nOK\r\n";
int idx_0 = 0;
int idx_1 = 0;

while (true) {
c = _parser.getc();
if (c < 0) {
Expand All @@ -1002,12 +1005,10 @@ bool ESP32::recv_ap(nsapi_wifi_ap_t *ap)
if (idx_0 >= (int)(sizeof(keyword_0) - 1)) {
int sec;
uint8_t work_buf[6+1]; /* It needs 1 byte extra. */
int8_t work_rssi[2]; /* It needs 1 byte extra. */

ret = _parser.recv("(%d,\"%32[^\"]\",%hhd,\"%hhx:%hhx:%hhx:%hhx:%hhx:%hhx\",%hhu)", &sec, ap->ssid,
&work_rssi[0], &work_buf[0], &work_buf[1], &work_buf[2], &work_buf[3], &work_buf[4],
&work_buf[5], &ap->channel);
ap->rssi = work_rssi[0];
ret = _parser.recv("(%d,\"%32[^\"]\",%hhd,\"%hhx:%hhx:%hhx:%hhx:%hhx:%hhx\",%hhu)", &sec, ap->ssid, &ap->rssi,
&work_buf[0], &work_buf[1], &work_buf[2], &work_buf[3], &work_buf[4], &work_buf[5],&ap->channel);

memcpy(ap->bssid, work_buf, 6);
ap->security = sec < 5 ? (nsapi_security_t)sec : NSAPI_SECURITY_UNKNOWN;
break;
Expand Down
7 changes: 4 additions & 3 deletions ESP32/ESP32.h
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ class ESP32
PinName _cts;
int _flow_control;
uint32_t last_timeout_ms;
bool _debug;

std::vector<int> _accept_id;
uint32_t _id_bits;
Expand Down Expand Up @@ -353,11 +354,11 @@ class ESP32
typedef struct {
uint16_t adv_int_min; /**< minimum value of advertising interval; range: 0x0020 ~ 0x4000 */
uint16_t adv_int_max; /**< maximum value of advertising interval; range: 0x0020 ~ 0x4000 */
uint8_t adv_type; /**< 0FADV_TYPE_IND, 2FADV_TYPE_SCAN_IND, 3FADV_TYPE_NONCONN_IND */
uint8_t own_addr_type; /**< own BLE address type; 0FBLE_ADDR_TYPE_PUBLIC, 1FBLE_ADDR_TYPE_RANDOM */
uint8_t adv_type; /**< 0FADV_TYPE_IND, 2FADV_TYPE_SCAN_IND, 3FADV_TYPE_NONCONN_IND */
uint8_t own_addr_type; /**< own BLE address type; 0FBLE_ADDR_TYPE_PUBLIC, 1FBLE_ADDR_TYPE_RANDOM */
uint8_t channel_map; /**< channel of advertising; ADV_CHNL_~ */
uint8_t adv_filter_policy; /**< filter policy of advertising; ADV_FILTER_ALLOW_SCAN_~ */
uint8_t peer_addr_type; /**< remote BLE address type; 0FPUBLIC, 1FRANDOM */
uint8_t peer_addr_type; /**< remote BLE address type; 0FPUBLIC, 1FRANDOM */
uint8_t peer_addr[6]; /**< remote BLE address */
} advertising_param_t;

Expand Down
16 changes: 12 additions & 4 deletions mbed_lib.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
{
"name": "esp32",
"config": {
"wifi-ssid": {
"help": "WiFi SSID",
"value": "\"Fios-VSFJ2\""
},
"wifi-password": {
"help": "WiFi Password",
"value": "\"claw9377tag688any\""
},
"wifi-en": {
"help": "Enable pin",
"value": "NC"
Expand All @@ -19,7 +27,7 @@
},
"wifi-debug": {
"help": "Enable debugging",
"value": false
"value": true
},
"wifi-rts": {
"help": "Serial RTS pin",
Expand All @@ -35,7 +43,7 @@
},
"wifi-serial-fc": {
"help": "Serial Flow Control",
"value": false
"value": true
},
"provide-default": {
"help": "Provide default WifiInterface. [true/false]",
Expand All @@ -49,8 +57,8 @@
"esp32.wifi-tx": "D8",
"esp32.wifi-rx": "D2",
"esp32.wifi-debug": true,
"esp32.wifi-rts": "NC",
"esp32.wifi-cts": "NC"
"esp32.wifi-rts": "PA_12",
"esp32.wifi-cts": "PA_11"
},
"GR_LYCHEE": {
"esp32.wifi-en" : "P5_3",
Expand Down

0 comments on commit 3f42df9

Please sign in to comment.