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