Ram Gandikota
/
IOTMetronome
FRDM K64F Metronome
easy-connect/esp8266-driver/ESP8266/ESP8266.cpp@0:dbad57390bd1, 2017-05-14 (annotated)
- Committer:
- ram54288
- Date:
- Sun May 14 18:37:05 2017 +0000
- Revision:
- 0:dbad57390bd1
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ram54288 | 0:dbad57390bd1 | 1 | /* ESP8266 Example |
ram54288 | 0:dbad57390bd1 | 2 | * Copyright (c) 2015 ARM Limited |
ram54288 | 0:dbad57390bd1 | 3 | * |
ram54288 | 0:dbad57390bd1 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
ram54288 | 0:dbad57390bd1 | 5 | * you may not use this file except in compliance with the License. |
ram54288 | 0:dbad57390bd1 | 6 | * You may obtain a copy of the License at |
ram54288 | 0:dbad57390bd1 | 7 | * |
ram54288 | 0:dbad57390bd1 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
ram54288 | 0:dbad57390bd1 | 9 | * |
ram54288 | 0:dbad57390bd1 | 10 | * Unless required by applicable law or agreed to in writing, software |
ram54288 | 0:dbad57390bd1 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
ram54288 | 0:dbad57390bd1 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
ram54288 | 0:dbad57390bd1 | 13 | * See the License for the specific language governing permissions and |
ram54288 | 0:dbad57390bd1 | 14 | * limitations under the License. |
ram54288 | 0:dbad57390bd1 | 15 | */ |
ram54288 | 0:dbad57390bd1 | 16 | |
ram54288 | 0:dbad57390bd1 | 17 | #include "ESP8266.h" |
ram54288 | 0:dbad57390bd1 | 18 | |
ram54288 | 0:dbad57390bd1 | 19 | ESP8266::ESP8266(PinName tx, PinName rx, bool debug) |
ram54288 | 0:dbad57390bd1 | 20 | : _serial(tx, rx, 1024), _parser(_serial) |
ram54288 | 0:dbad57390bd1 | 21 | , _packets(0), _packets_end(&_packets) |
ram54288 | 0:dbad57390bd1 | 22 | { |
ram54288 | 0:dbad57390bd1 | 23 | _serial.baud(115200); |
ram54288 | 0:dbad57390bd1 | 24 | _parser.debugOn(debug); |
ram54288 | 0:dbad57390bd1 | 25 | } |
ram54288 | 0:dbad57390bd1 | 26 | |
ram54288 | 0:dbad57390bd1 | 27 | bool ESP8266::startup(int mode) |
ram54288 | 0:dbad57390bd1 | 28 | { |
ram54288 | 0:dbad57390bd1 | 29 | //only 3 valid modes |
ram54288 | 0:dbad57390bd1 | 30 | if(mode < 1 || mode > 3) { |
ram54288 | 0:dbad57390bd1 | 31 | return false; |
ram54288 | 0:dbad57390bd1 | 32 | } |
ram54288 | 0:dbad57390bd1 | 33 | |
ram54288 | 0:dbad57390bd1 | 34 | bool success = reset() |
ram54288 | 0:dbad57390bd1 | 35 | && _parser.send("AT+CWMODE=%d", mode) |
ram54288 | 0:dbad57390bd1 | 36 | && _parser.recv("OK") |
ram54288 | 0:dbad57390bd1 | 37 | && _parser.send("AT+CIPMUX=1") |
ram54288 | 0:dbad57390bd1 | 38 | && _parser.recv("OK"); |
ram54288 | 0:dbad57390bd1 | 39 | |
ram54288 | 0:dbad57390bd1 | 40 | _parser.oob("+IPD", this, &ESP8266::_packet_handler); |
ram54288 | 0:dbad57390bd1 | 41 | |
ram54288 | 0:dbad57390bd1 | 42 | return success; |
ram54288 | 0:dbad57390bd1 | 43 | } |
ram54288 | 0:dbad57390bd1 | 44 | |
ram54288 | 0:dbad57390bd1 | 45 | bool ESP8266::reset(void) |
ram54288 | 0:dbad57390bd1 | 46 | { |
ram54288 | 0:dbad57390bd1 | 47 | for (int i = 0; i < 2; i++) { |
ram54288 | 0:dbad57390bd1 | 48 | if (_parser.send("AT+RST") |
ram54288 | 0:dbad57390bd1 | 49 | && _parser.recv("OK\r\nready")) { |
ram54288 | 0:dbad57390bd1 | 50 | return true; |
ram54288 | 0:dbad57390bd1 | 51 | } |
ram54288 | 0:dbad57390bd1 | 52 | } |
ram54288 | 0:dbad57390bd1 | 53 | |
ram54288 | 0:dbad57390bd1 | 54 | return false; |
ram54288 | 0:dbad57390bd1 | 55 | } |
ram54288 | 0:dbad57390bd1 | 56 | |
ram54288 | 0:dbad57390bd1 | 57 | bool ESP8266::dhcp(bool enabled, int mode) |
ram54288 | 0:dbad57390bd1 | 58 | { |
ram54288 | 0:dbad57390bd1 | 59 | //only 3 valid modes |
ram54288 | 0:dbad57390bd1 | 60 | if(mode < 0 || mode > 2) { |
ram54288 | 0:dbad57390bd1 | 61 | return false; |
ram54288 | 0:dbad57390bd1 | 62 | } |
ram54288 | 0:dbad57390bd1 | 63 | |
ram54288 | 0:dbad57390bd1 | 64 | return _parser.send("AT+CWDHCP=%d,%d", enabled?1:0, mode) |
ram54288 | 0:dbad57390bd1 | 65 | && _parser.recv("OK"); |
ram54288 | 0:dbad57390bd1 | 66 | } |
ram54288 | 0:dbad57390bd1 | 67 | |
ram54288 | 0:dbad57390bd1 | 68 | bool ESP8266::connect(const char *ap, const char *passPhrase) |
ram54288 | 0:dbad57390bd1 | 69 | { |
ram54288 | 0:dbad57390bd1 | 70 | return _parser.send("AT+CWJAP=\"%s\",\"%s\"", ap, passPhrase) |
ram54288 | 0:dbad57390bd1 | 71 | && _parser.recv("OK"); |
ram54288 | 0:dbad57390bd1 | 72 | } |
ram54288 | 0:dbad57390bd1 | 73 | |
ram54288 | 0:dbad57390bd1 | 74 | bool ESP8266::disconnect(void) |
ram54288 | 0:dbad57390bd1 | 75 | { |
ram54288 | 0:dbad57390bd1 | 76 | return _parser.send("AT+CWQAP") && _parser.recv("OK"); |
ram54288 | 0:dbad57390bd1 | 77 | } |
ram54288 | 0:dbad57390bd1 | 78 | |
ram54288 | 0:dbad57390bd1 | 79 | const char *ESP8266::getIPAddress(void) |
ram54288 | 0:dbad57390bd1 | 80 | { |
ram54288 | 0:dbad57390bd1 | 81 | if (!(_parser.send("AT+CIFSR") |
ram54288 | 0:dbad57390bd1 | 82 | && _parser.recv("+CIFSR:STAIP,\"%15[^\"]\"", _ip_buffer) |
ram54288 | 0:dbad57390bd1 | 83 | && _parser.recv("OK"))) { |
ram54288 | 0:dbad57390bd1 | 84 | return 0; |
ram54288 | 0:dbad57390bd1 | 85 | } |
ram54288 | 0:dbad57390bd1 | 86 | |
ram54288 | 0:dbad57390bd1 | 87 | return _ip_buffer; |
ram54288 | 0:dbad57390bd1 | 88 | } |
ram54288 | 0:dbad57390bd1 | 89 | |
ram54288 | 0:dbad57390bd1 | 90 | const char *ESP8266::getMACAddress(void) |
ram54288 | 0:dbad57390bd1 | 91 | { |
ram54288 | 0:dbad57390bd1 | 92 | if (!(_parser.send("AT+CIFSR") |
ram54288 | 0:dbad57390bd1 | 93 | && _parser.recv("+CIFSR:STAMAC,\"%17[^\"]\"", _mac_buffer) |
ram54288 | 0:dbad57390bd1 | 94 | && _parser.recv("OK"))) { |
ram54288 | 0:dbad57390bd1 | 95 | return 0; |
ram54288 | 0:dbad57390bd1 | 96 | } |
ram54288 | 0:dbad57390bd1 | 97 | |
ram54288 | 0:dbad57390bd1 | 98 | return _mac_buffer; |
ram54288 | 0:dbad57390bd1 | 99 | } |
ram54288 | 0:dbad57390bd1 | 100 | |
ram54288 | 0:dbad57390bd1 | 101 | const char *ESP8266::getGateway() |
ram54288 | 0:dbad57390bd1 | 102 | { |
ram54288 | 0:dbad57390bd1 | 103 | if (!(_parser.send("AT+CIPSTA?") |
ram54288 | 0:dbad57390bd1 | 104 | && _parser.recv("+CIPSTA:gateway:\"%15[^\"]\"", _gateway_buffer) |
ram54288 | 0:dbad57390bd1 | 105 | && _parser.recv("OK"))) { |
ram54288 | 0:dbad57390bd1 | 106 | return 0; |
ram54288 | 0:dbad57390bd1 | 107 | } |
ram54288 | 0:dbad57390bd1 | 108 | |
ram54288 | 0:dbad57390bd1 | 109 | return _gateway_buffer; |
ram54288 | 0:dbad57390bd1 | 110 | } |
ram54288 | 0:dbad57390bd1 | 111 | |
ram54288 | 0:dbad57390bd1 | 112 | const char *ESP8266::getNetmask() |
ram54288 | 0:dbad57390bd1 | 113 | { |
ram54288 | 0:dbad57390bd1 | 114 | if (!(_parser.send("AT+CIPSTA?") |
ram54288 | 0:dbad57390bd1 | 115 | && _parser.recv("+CIPSTA:netmask:\"%15[^\"]\"", _netmask_buffer) |
ram54288 | 0:dbad57390bd1 | 116 | && _parser.recv("OK"))) { |
ram54288 | 0:dbad57390bd1 | 117 | return 0; |
ram54288 | 0:dbad57390bd1 | 118 | } |
ram54288 | 0:dbad57390bd1 | 119 | |
ram54288 | 0:dbad57390bd1 | 120 | return _netmask_buffer; |
ram54288 | 0:dbad57390bd1 | 121 | } |
ram54288 | 0:dbad57390bd1 | 122 | |
ram54288 | 0:dbad57390bd1 | 123 | int8_t ESP8266::getRSSI() |
ram54288 | 0:dbad57390bd1 | 124 | { |
ram54288 | 0:dbad57390bd1 | 125 | int8_t rssi; |
ram54288 | 0:dbad57390bd1 | 126 | char bssid[18]; |
ram54288 | 0:dbad57390bd1 | 127 | |
ram54288 | 0:dbad57390bd1 | 128 | if (!(_parser.send("AT+CWJAP?") |
ram54288 | 0:dbad57390bd1 | 129 | && _parser.recv("+CWJAP:\"%*[^\"]\",\"%17[^\"]\"", bssid) |
ram54288 | 0:dbad57390bd1 | 130 | && _parser.recv("OK"))) { |
ram54288 | 0:dbad57390bd1 | 131 | return 0; |
ram54288 | 0:dbad57390bd1 | 132 | } |
ram54288 | 0:dbad57390bd1 | 133 | |
ram54288 | 0:dbad57390bd1 | 134 | if (!(_parser.send("AT+CWLAP=\"\",\"%s\",", bssid) |
ram54288 | 0:dbad57390bd1 | 135 | && _parser.recv("+CWLAP:(%*d,\"%*[^\"]\",%hhd,", &rssi) |
ram54288 | 0:dbad57390bd1 | 136 | && _parser.recv("OK"))) { |
ram54288 | 0:dbad57390bd1 | 137 | return 0; |
ram54288 | 0:dbad57390bd1 | 138 | } |
ram54288 | 0:dbad57390bd1 | 139 | |
ram54288 | 0:dbad57390bd1 | 140 | return rssi; |
ram54288 | 0:dbad57390bd1 | 141 | } |
ram54288 | 0:dbad57390bd1 | 142 | |
ram54288 | 0:dbad57390bd1 | 143 | bool ESP8266::isConnected(void) |
ram54288 | 0:dbad57390bd1 | 144 | { |
ram54288 | 0:dbad57390bd1 | 145 | return getIPAddress() != 0; |
ram54288 | 0:dbad57390bd1 | 146 | } |
ram54288 | 0:dbad57390bd1 | 147 | |
ram54288 | 0:dbad57390bd1 | 148 | int ESP8266::scan(WiFiAccessPoint *res, unsigned limit) |
ram54288 | 0:dbad57390bd1 | 149 | { |
ram54288 | 0:dbad57390bd1 | 150 | unsigned cnt = 0; |
ram54288 | 0:dbad57390bd1 | 151 | nsapi_wifi_ap_t ap; |
ram54288 | 0:dbad57390bd1 | 152 | |
ram54288 | 0:dbad57390bd1 | 153 | if (!_parser.send("AT+CWLAP")) { |
ram54288 | 0:dbad57390bd1 | 154 | return NSAPI_ERROR_DEVICE_ERROR; |
ram54288 | 0:dbad57390bd1 | 155 | } |
ram54288 | 0:dbad57390bd1 | 156 | |
ram54288 | 0:dbad57390bd1 | 157 | while (recv_ap(&ap)) { |
ram54288 | 0:dbad57390bd1 | 158 | if (cnt < limit) { |
ram54288 | 0:dbad57390bd1 | 159 | res[cnt] = WiFiAccessPoint(ap); |
ram54288 | 0:dbad57390bd1 | 160 | } |
ram54288 | 0:dbad57390bd1 | 161 | |
ram54288 | 0:dbad57390bd1 | 162 | cnt++; |
ram54288 | 0:dbad57390bd1 | 163 | if (limit != 0 && cnt >= limit) { |
ram54288 | 0:dbad57390bd1 | 164 | break; |
ram54288 | 0:dbad57390bd1 | 165 | } |
ram54288 | 0:dbad57390bd1 | 166 | } |
ram54288 | 0:dbad57390bd1 | 167 | |
ram54288 | 0:dbad57390bd1 | 168 | return cnt; |
ram54288 | 0:dbad57390bd1 | 169 | } |
ram54288 | 0:dbad57390bd1 | 170 | |
ram54288 | 0:dbad57390bd1 | 171 | bool ESP8266::open(const char *type, int id, const char* addr, int port) |
ram54288 | 0:dbad57390bd1 | 172 | { |
ram54288 | 0:dbad57390bd1 | 173 | //IDs only 0-4 |
ram54288 | 0:dbad57390bd1 | 174 | if(id > 4) { |
ram54288 | 0:dbad57390bd1 | 175 | return false; |
ram54288 | 0:dbad57390bd1 | 176 | } |
ram54288 | 0:dbad57390bd1 | 177 | |
ram54288 | 0:dbad57390bd1 | 178 | return _parser.send("AT+CIPSTART=%d,\"%s\",\"%s\",%d", id, type, addr, port) |
ram54288 | 0:dbad57390bd1 | 179 | && _parser.recv("OK"); |
ram54288 | 0:dbad57390bd1 | 180 | } |
ram54288 | 0:dbad57390bd1 | 181 | |
ram54288 | 0:dbad57390bd1 | 182 | bool ESP8266::send(int id, const void *data, uint32_t amount) |
ram54288 | 0:dbad57390bd1 | 183 | { |
ram54288 | 0:dbad57390bd1 | 184 | //May take a second try if device is busy |
ram54288 | 0:dbad57390bd1 | 185 | for (unsigned i = 0; i < 2; i++) { |
ram54288 | 0:dbad57390bd1 | 186 | if (_parser.send("AT+CIPSEND=%d,%d", id, amount) |
ram54288 | 0:dbad57390bd1 | 187 | && _parser.recv(">") |
ram54288 | 0:dbad57390bd1 | 188 | && _parser.write((char*)data, (int)amount) >= 0) { |
ram54288 | 0:dbad57390bd1 | 189 | return true; |
ram54288 | 0:dbad57390bd1 | 190 | } |
ram54288 | 0:dbad57390bd1 | 191 | } |
ram54288 | 0:dbad57390bd1 | 192 | |
ram54288 | 0:dbad57390bd1 | 193 | return false; |
ram54288 | 0:dbad57390bd1 | 194 | } |
ram54288 | 0:dbad57390bd1 | 195 | |
ram54288 | 0:dbad57390bd1 | 196 | void ESP8266::_packet_handler() |
ram54288 | 0:dbad57390bd1 | 197 | { |
ram54288 | 0:dbad57390bd1 | 198 | int id; |
ram54288 | 0:dbad57390bd1 | 199 | uint32_t amount; |
ram54288 | 0:dbad57390bd1 | 200 | |
ram54288 | 0:dbad57390bd1 | 201 | // parse out the packet |
ram54288 | 0:dbad57390bd1 | 202 | if (!_parser.recv(",%d,%d:", &id, &amount)) { |
ram54288 | 0:dbad57390bd1 | 203 | return; |
ram54288 | 0:dbad57390bd1 | 204 | } |
ram54288 | 0:dbad57390bd1 | 205 | |
ram54288 | 0:dbad57390bd1 | 206 | struct packet *packet = (struct packet*)malloc( |
ram54288 | 0:dbad57390bd1 | 207 | sizeof(struct packet) + amount); |
ram54288 | 0:dbad57390bd1 | 208 | if (!packet) { |
ram54288 | 0:dbad57390bd1 | 209 | return; |
ram54288 | 0:dbad57390bd1 | 210 | } |
ram54288 | 0:dbad57390bd1 | 211 | |
ram54288 | 0:dbad57390bd1 | 212 | packet->id = id; |
ram54288 | 0:dbad57390bd1 | 213 | packet->len = amount; |
ram54288 | 0:dbad57390bd1 | 214 | packet->next = 0; |
ram54288 | 0:dbad57390bd1 | 215 | |
ram54288 | 0:dbad57390bd1 | 216 | if (!(_parser.read((char*)(packet + 1), amount))) { |
ram54288 | 0:dbad57390bd1 | 217 | free(packet); |
ram54288 | 0:dbad57390bd1 | 218 | return; |
ram54288 | 0:dbad57390bd1 | 219 | } |
ram54288 | 0:dbad57390bd1 | 220 | |
ram54288 | 0:dbad57390bd1 | 221 | // append to packet list |
ram54288 | 0:dbad57390bd1 | 222 | *_packets_end = packet; |
ram54288 | 0:dbad57390bd1 | 223 | _packets_end = &packet->next; |
ram54288 | 0:dbad57390bd1 | 224 | } |
ram54288 | 0:dbad57390bd1 | 225 | |
ram54288 | 0:dbad57390bd1 | 226 | int32_t ESP8266::recv(int id, void *data, uint32_t amount) |
ram54288 | 0:dbad57390bd1 | 227 | { |
ram54288 | 0:dbad57390bd1 | 228 | while (true) { |
ram54288 | 0:dbad57390bd1 | 229 | // check if any packets are ready for us |
ram54288 | 0:dbad57390bd1 | 230 | for (struct packet **p = &_packets; *p; p = &(*p)->next) { |
ram54288 | 0:dbad57390bd1 | 231 | if ((*p)->id == id) { |
ram54288 | 0:dbad57390bd1 | 232 | struct packet *q = *p; |
ram54288 | 0:dbad57390bd1 | 233 | |
ram54288 | 0:dbad57390bd1 | 234 | if (q->len <= amount) { // Return and remove full packet |
ram54288 | 0:dbad57390bd1 | 235 | memcpy(data, q+1, q->len); |
ram54288 | 0:dbad57390bd1 | 236 | |
ram54288 | 0:dbad57390bd1 | 237 | if (_packets_end == &(*p)->next) { |
ram54288 | 0:dbad57390bd1 | 238 | _packets_end = p; |
ram54288 | 0:dbad57390bd1 | 239 | } |
ram54288 | 0:dbad57390bd1 | 240 | *p = (*p)->next; |
ram54288 | 0:dbad57390bd1 | 241 | |
ram54288 | 0:dbad57390bd1 | 242 | uint32_t len = q->len; |
ram54288 | 0:dbad57390bd1 | 243 | free(q); |
ram54288 | 0:dbad57390bd1 | 244 | return len; |
ram54288 | 0:dbad57390bd1 | 245 | } else { // return only partial packet |
ram54288 | 0:dbad57390bd1 | 246 | memcpy(data, q+1, amount); |
ram54288 | 0:dbad57390bd1 | 247 | |
ram54288 | 0:dbad57390bd1 | 248 | q->len -= amount; |
ram54288 | 0:dbad57390bd1 | 249 | memmove(q+1, (uint8_t*)(q+1) + amount, q->len); |
ram54288 | 0:dbad57390bd1 | 250 | |
ram54288 | 0:dbad57390bd1 | 251 | return amount; |
ram54288 | 0:dbad57390bd1 | 252 | } |
ram54288 | 0:dbad57390bd1 | 253 | } |
ram54288 | 0:dbad57390bd1 | 254 | } |
ram54288 | 0:dbad57390bd1 | 255 | |
ram54288 | 0:dbad57390bd1 | 256 | // Wait for inbound packet |
ram54288 | 0:dbad57390bd1 | 257 | if (!_parser.recv("OK")) { |
ram54288 | 0:dbad57390bd1 | 258 | return -1; |
ram54288 | 0:dbad57390bd1 | 259 | } |
ram54288 | 0:dbad57390bd1 | 260 | } |
ram54288 | 0:dbad57390bd1 | 261 | } |
ram54288 | 0:dbad57390bd1 | 262 | |
ram54288 | 0:dbad57390bd1 | 263 | bool ESP8266::close(int id) |
ram54288 | 0:dbad57390bd1 | 264 | { |
ram54288 | 0:dbad57390bd1 | 265 | //May take a second try if device is busy |
ram54288 | 0:dbad57390bd1 | 266 | for (unsigned i = 0; i < 2; i++) { |
ram54288 | 0:dbad57390bd1 | 267 | if (_parser.send("AT+CIPCLOSE=%d", id) |
ram54288 | 0:dbad57390bd1 | 268 | && _parser.recv("OK")) { |
ram54288 | 0:dbad57390bd1 | 269 | return true; |
ram54288 | 0:dbad57390bd1 | 270 | } |
ram54288 | 0:dbad57390bd1 | 271 | } |
ram54288 | 0:dbad57390bd1 | 272 | |
ram54288 | 0:dbad57390bd1 | 273 | return false; |
ram54288 | 0:dbad57390bd1 | 274 | } |
ram54288 | 0:dbad57390bd1 | 275 | |
ram54288 | 0:dbad57390bd1 | 276 | void ESP8266::setTimeout(uint32_t timeout_ms) |
ram54288 | 0:dbad57390bd1 | 277 | { |
ram54288 | 0:dbad57390bd1 | 278 | _parser.setTimeout(timeout_ms); |
ram54288 | 0:dbad57390bd1 | 279 | } |
ram54288 | 0:dbad57390bd1 | 280 | |
ram54288 | 0:dbad57390bd1 | 281 | bool ESP8266::readable() |
ram54288 | 0:dbad57390bd1 | 282 | { |
ram54288 | 0:dbad57390bd1 | 283 | return _serial.readable(); |
ram54288 | 0:dbad57390bd1 | 284 | } |
ram54288 | 0:dbad57390bd1 | 285 | |
ram54288 | 0:dbad57390bd1 | 286 | bool ESP8266::writeable() |
ram54288 | 0:dbad57390bd1 | 287 | { |
ram54288 | 0:dbad57390bd1 | 288 | return _serial.writeable(); |
ram54288 | 0:dbad57390bd1 | 289 | } |
ram54288 | 0:dbad57390bd1 | 290 | |
ram54288 | 0:dbad57390bd1 | 291 | void ESP8266::attach(Callback<void()> func) |
ram54288 | 0:dbad57390bd1 | 292 | { |
ram54288 | 0:dbad57390bd1 | 293 | _serial.attach(func); |
ram54288 | 0:dbad57390bd1 | 294 | } |
ram54288 | 0:dbad57390bd1 | 295 | |
ram54288 | 0:dbad57390bd1 | 296 | bool ESP8266::recv_ap(nsapi_wifi_ap_t *ap) |
ram54288 | 0:dbad57390bd1 | 297 | { |
ram54288 | 0:dbad57390bd1 | 298 | int sec; |
ram54288 | 0:dbad57390bd1 | 299 | bool ret = _parser.recv("+CWLAP:(%d,\"%32[^\"]\",%hhd,\"%hhx:%hhx:%hhx:%hhx:%hhx:%hhx\",%d", &sec, ap->ssid, |
ram54288 | 0:dbad57390bd1 | 300 | &ap->rssi, &ap->bssid[0], &ap->bssid[1], &ap->bssid[2], &ap->bssid[3], &ap->bssid[4], |
ram54288 | 0:dbad57390bd1 | 301 | &ap->bssid[5], &ap->channel); |
ram54288 | 0:dbad57390bd1 | 302 | |
ram54288 | 0:dbad57390bd1 | 303 | ap->security = sec < 5 ? (nsapi_security_t)sec : NSAPI_SECURITY_UNKNOWN; |
ram54288 | 0:dbad57390bd1 | 304 | |
ram54288 | 0:dbad57390bd1 | 305 | return ret; |
ram54288 | 0:dbad57390bd1 | 306 | } |