Okundu Omeni
/
wifi-https-ble-sm-uart-atcmd-5-13-1
this is using the mbed os version 5-13-1
source/ATCmdManager.cpp@80:e8f0e92e3ac9, 2019-03-21 (annotated)
- Committer:
- ocomeni
- Date:
- Thu Mar 21 22:17:28 2019 +0000
- Revision:
- 80:e8f0e92e3ac9
- Parent:
- 79:a2187bbfa407
- Child:
- 81:637a87eb8170
implemented queue and memory pools for command and data passing between ATCmdManager and WiFiManager classes
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ocomeni | 74:f26e846adfe9 | 1 | #include "ATCmdManager.h" |
ocomeni | 74:f26e846adfe9 | 2 | #include "common_config.h" |
ocomeni | 79:a2187bbfa407 | 3 | #include "common_types.h" |
ocomeni | 79:a2187bbfa407 | 4 | |
ocomeni | 74:f26e846adfe9 | 5 | |
ocomeni | 78:07bb86e3ce14 | 6 | ATCmdManager::ATCmdManager(PinName tx, PinName rx, SMDevicePeripheral *blePeripheral, |
ocomeni | 79:a2187bbfa407 | 7 | events::EventQueue &event_queue, WiFiManager *wifi, |
ocomeni | 79:a2187bbfa407 | 8 | MemoryPool<wifi_cmd_message_t, 16> *aT2WiFimPool, |
ocomeni | 80:e8f0e92e3ac9 | 9 | Queue<wifi_cmd_message_t, 16> *aT2WiFiCmdQueue, |
ocomeni | 80:e8f0e92e3ac9 | 10 | MemoryPool<wifi_cmd_message_t, 16> *wiFi2ATmPool, |
ocomeni | 80:e8f0e92e3ac9 | 11 | Queue<wifi_cmd_message_t, 16> *wiFi2ATCmdQueue, |
ocomeni | 80:e8f0e92e3ac9 | 12 | MemoryPool<wifi_data_msg_t, 4> *aT2WiFiDatamPool, |
ocomeni | 80:e8f0e92e3ac9 | 13 | Queue<wifi_data_msg_t, 4> *aT2WiFiDataQueue, |
ocomeni | 80:e8f0e92e3ac9 | 14 | MemoryPool<wifi_data_msg_t, 4> *wiFi2ATDatamPool, |
ocomeni | 80:e8f0e92e3ac9 | 15 | Queue<wifi_data_msg_t, 4> *wiFi2ATDataQueue, |
ocomeni | 79:a2187bbfa407 | 16 | bool debug) |
ocomeni | 74:f26e846adfe9 | 17 | : |
ocomeni | 74:f26e846adfe9 | 18 | _serial(tx, rx, DEFAULT_BAUD_RATE), |
ocomeni | 78:07bb86e3ce14 | 19 | blePeripheral(blePeripheral), |
ocomeni | 79:a2187bbfa407 | 20 | _event_queue(event_queue), |
ocomeni | 79:a2187bbfa407 | 21 | wiFiManager(wiFiManager), |
ocomeni | 79:a2187bbfa407 | 22 | _aT2WiFimPool(aT2WiFimPool), |
ocomeni | 80:e8f0e92e3ac9 | 23 | _aT2WiFiCmdQueue(aT2WiFiCmdQueue), |
ocomeni | 80:e8f0e92e3ac9 | 24 | |
ocomeni | 80:e8f0e92e3ac9 | 25 | _wiFi2ATmPool(wiFi2ATmPool), |
ocomeni | 80:e8f0e92e3ac9 | 26 | _wiFi2ATCmdQueue(wiFi2ATCmdQueue), |
ocomeni | 80:e8f0e92e3ac9 | 27 | |
ocomeni | 80:e8f0e92e3ac9 | 28 | _aT2WiFiDatamPool(aT2WiFiDatamPool), |
ocomeni | 80:e8f0e92e3ac9 | 29 | _aT2WiFiDataQueue(aT2WiFiDataQueue), |
ocomeni | 80:e8f0e92e3ac9 | 30 | |
ocomeni | 80:e8f0e92e3ac9 | 31 | _wiFi2ATDatamPool(wiFi2ATDatamPool), |
ocomeni | 80:e8f0e92e3ac9 | 32 | _wiFi2ATDataQueue(wiFi2ATDataQueue), |
ocomeni | 80:e8f0e92e3ac9 | 33 | |
ocomeni | 80:e8f0e92e3ac9 | 34 | _parser(&_serial) |
ocomeni | 80:e8f0e92e3ac9 | 35 | |
ocomeni | 74:f26e846adfe9 | 36 | |
ocomeni | 74:f26e846adfe9 | 37 | { |
ocomeni | 74:f26e846adfe9 | 38 | // constructor |
ocomeni | 74:f26e846adfe9 | 39 | _serial.set_baud(DEFAULT_BAUD_RATE); |
ocomeni | 74:f26e846adfe9 | 40 | _parser.debug_on(debug); |
ocomeni | 74:f26e846adfe9 | 41 | _parser.set_delimiter("\r\n"); |
ocomeni | 75:08eff6258e1b | 42 | _parser.send("+STARTUP"); |
ocomeni | 75:08eff6258e1b | 43 | _parser.oob("ATE0", callback(this, &ATCmdManager::_oob_echo_off)); |
ocomeni | 75:08eff6258e1b | 44 | _parser.oob("ATE1", callback(this, &ATCmdManager::_oob_echo_on)); |
ocomeni | 75:08eff6258e1b | 45 | _parser.oob("AT+UMRS", callback(this, &ATCmdManager::_oob_uart_setup)); |
ocomeni | 75:08eff6258e1b | 46 | |
ocomeni | 75:08eff6258e1b | 47 | _parser.oob("ATO", callback(this, &ATCmdManager::_oob_data_mode)); |
ocomeni | 75:08eff6258e1b | 48 | _parser.oob("AT+UMLA", callback(this, &ATCmdManager::_oob_get_mac_addr)); |
ocomeni | 75:08eff6258e1b | 49 | _parser.oob("AT+UBTLE?", callback(this, &ATCmdManager::_oob_get_ble_role)); |
ocomeni | 75:08eff6258e1b | 50 | _parser.oob("AT+UBTLE=2", callback(this, &ATCmdManager::_oob_ena_ble_peri)); |
ocomeni | 75:08eff6258e1b | 51 | _parser.oob("AT+CPWROFF", callback(this, &ATCmdManager::_oob_reboot)); |
ocomeni | 75:08eff6258e1b | 52 | _parser.oob("AT+CGMR", callback(this, &ATCmdManager::_oob_get_fw_ver)); |
ocomeni | 79:a2187bbfa407 | 53 | _parser.oob("AT+UWSC=", callback(this, &ATCmdManager::_oob_scanWiFiNetworks)); |
ocomeni | 79:a2187bbfa407 | 54 | _parser.oob("AT+UWSCA=", callback(this, &ATCmdManager::_oob_connect2WiFiNetwork)); |
ocomeni | 75:08eff6258e1b | 55 | |
ocomeni | 75:08eff6258e1b | 56 | |
ocomeni | 75:08eff6258e1b | 57 | //_parser.oob("ATE0", callback(this, &ATCmdManager::_oob_startup_hdlr)); |
ocomeni | 74:f26e846adfe9 | 58 | printf("\n --- ATCmdManager constructor completed ---\n"); |
ocomeni | 75:08eff6258e1b | 59 | |
ocomeni | 75:08eff6258e1b | 60 | //AT+UMRS=230400,2,8,1,1,1 |
ocomeni | 74:f26e846adfe9 | 61 | // AT+UBTLE |
ocomeni | 74:f26e846adfe9 | 62 | } |
ocomeni | 74:f26e846adfe9 | 63 | |
ocomeni | 74:f26e846adfe9 | 64 | |
ocomeni | 74:f26e846adfe9 | 65 | void ATCmdManager::runMain(){ |
ocomeni | 74:f26e846adfe9 | 66 | while(true){ |
ocomeni | 74:f26e846adfe9 | 67 | _process_oob(UBLOX_ODIN_W2_RECV_TIMEOUT, true); |
ocomeni | 74:f26e846adfe9 | 68 | wait_ms(MAIN_LOOP_WAIT_TIME_MS); // allow BTLE to be |
ocomeni | 74:f26e846adfe9 | 69 | } |
ocomeni | 74:f26e846adfe9 | 70 | |
ocomeni | 74:f26e846adfe9 | 71 | } |
ocomeni | 74:f26e846adfe9 | 72 | |
ocomeni | 74:f26e846adfe9 | 73 | |
ocomeni | 74:f26e846adfe9 | 74 | // OOB processing |
ocomeni | 74:f26e846adfe9 | 75 | void ATCmdManager::_process_oob(uint32_t timeout, bool all){ |
ocomeni | 74:f26e846adfe9 | 76 | set_timeout(timeout); |
ocomeni | 74:f26e846adfe9 | 77 | // Poll for inbound packets |
ocomeni | 74:f26e846adfe9 | 78 | while (_parser.process_oob() && all) { |
ocomeni | 74:f26e846adfe9 | 79 | } |
ocomeni | 74:f26e846adfe9 | 80 | set_timeout(); |
ocomeni | 74:f26e846adfe9 | 81 | } |
ocomeni | 74:f26e846adfe9 | 82 | |
ocomeni | 74:f26e846adfe9 | 83 | |
ocomeni | 74:f26e846adfe9 | 84 | // OOB message handlers |
ocomeni | 74:f26e846adfe9 | 85 | void ATCmdManager::_oob_startup_hdlr(){ |
ocomeni | 74:f26e846adfe9 | 86 | } |
ocomeni | 74:f26e846adfe9 | 87 | |
ocomeni | 74:f26e846adfe9 | 88 | |
ocomeni | 74:f26e846adfe9 | 89 | void ATCmdManager::_oob_bleRole_hdlr(){ |
ocomeni | 74:f26e846adfe9 | 90 | } |
ocomeni | 74:f26e846adfe9 | 91 | |
ocomeni | 74:f26e846adfe9 | 92 | |
ocomeni | 74:f26e846adfe9 | 93 | void ATCmdManager::_oob_wifiMode_err(){ |
ocomeni | 74:f26e846adfe9 | 94 | } |
ocomeni | 74:f26e846adfe9 | 95 | |
ocomeni | 74:f26e846adfe9 | 96 | |
ocomeni | 74:f26e846adfe9 | 97 | void ATCmdManager::_oob_conn_already(){ |
ocomeni | 74:f26e846adfe9 | 98 | } |
ocomeni | 74:f26e846adfe9 | 99 | |
ocomeni | 74:f26e846adfe9 | 100 | |
ocomeni | 74:f26e846adfe9 | 101 | void ATCmdManager::_oob_err(){ |
ocomeni | 74:f26e846adfe9 | 102 | } |
ocomeni | 74:f26e846adfe9 | 103 | |
ocomeni | 79:a2187bbfa407 | 104 | void ATCmdManager::_oob_get_fw_ver() |
ocomeni | 79:a2187bbfa407 | 105 | { |
ocomeni | 79:a2187bbfa407 | 106 | } |
ocomeni | 79:a2187bbfa407 | 107 | |
ocomeni | 79:a2187bbfa407 | 108 | |
ocomeni | 75:08eff6258e1b | 109 | void ATCmdManager::_oob_uart_setup(){ |
ocomeni | 75:08eff6258e1b | 110 | int uOpts[NUM_UART_OPTIONS]; |
ocomeni | 75:08eff6258e1b | 111 | //if(_parser.recv("=%d,%d,%d,%d,%d,%d", &uOpts[0], &uOpts[1], &uOpts[2], &uOpts[3], &uOpts[4], &uOpts[5])) { |
ocomeni | 75:08eff6258e1b | 112 | if(_parser.scanf("=%d,%d,%d,%d,%d,%d", &uOpts[0], &uOpts[1], &uOpts[2], &uOpts[3], &uOpts[4], &uOpts[5]) >0) { |
ocomeni | 75:08eff6258e1b | 113 | printf("\nATCmdParser: Uart Options=%d,%d,%d,%d,%d,%d\n", uOpts[0], uOpts[1], uOpts[2], uOpts[3], uOpts[4], uOpts[5]); |
ocomeni | 75:08eff6258e1b | 114 | } else { |
ocomeni | 75:08eff6258e1b | 115 | printf("\nATCmdParser: Retrieving Uart Options failed"); |
ocomeni | 75:08eff6258e1b | 116 | } |
ocomeni | 75:08eff6258e1b | 117 | } |
ocomeni | 75:08eff6258e1b | 118 | |
ocomeni | 74:f26e846adfe9 | 119 | void ATCmdManager::set_timeout(uint32_t timeout_ms) |
ocomeni | 74:f26e846adfe9 | 120 | { |
ocomeni | 74:f26e846adfe9 | 121 | _parser.set_timeout(timeout_ms); |
ocomeni | 74:f26e846adfe9 | 122 | } |
ocomeni | 74:f26e846adfe9 | 123 | |
ocomeni | 75:08eff6258e1b | 124 | |
ocomeni | 75:08eff6258e1b | 125 | void ATCmdManager::_oob_echo_off() |
ocomeni | 75:08eff6258e1b | 126 | { |
ocomeni | 75:08eff6258e1b | 127 | _smutex.lock(); |
ocomeni | 75:08eff6258e1b | 128 | printf("\n Received ATEO OOB command!!\n"); |
ocomeni | 75:08eff6258e1b | 129 | printf("\n turning echo OFF!!\n"); |
ocomeni | 75:08eff6258e1b | 130 | _parser.debug_on(false); |
ocomeni | 75:08eff6258e1b | 131 | _parser.send("OK\n"); |
ocomeni | 75:08eff6258e1b | 132 | _smutex.unlock(); |
ocomeni | 75:08eff6258e1b | 133 | } |
ocomeni | 75:08eff6258e1b | 134 | |
ocomeni | 75:08eff6258e1b | 135 | |
ocomeni | 75:08eff6258e1b | 136 | void ATCmdManager::_oob_echo_on() |
ocomeni | 75:08eff6258e1b | 137 | { |
ocomeni | 75:08eff6258e1b | 138 | _smutex.lock(); |
ocomeni | 75:08eff6258e1b | 139 | printf("\n Received ATE1 OOB command!!\n"); |
ocomeni | 75:08eff6258e1b | 140 | printf("\n turning echo ON!!\n"); |
ocomeni | 75:08eff6258e1b | 141 | _parser.debug_on(true); |
ocomeni | 75:08eff6258e1b | 142 | _parser.send("OK\n"); |
ocomeni | 75:08eff6258e1b | 143 | _smutex.unlock(); |
ocomeni | 75:08eff6258e1b | 144 | } |
ocomeni | 75:08eff6258e1b | 145 | |
ocomeni | 75:08eff6258e1b | 146 | |
ocomeni | 75:08eff6258e1b | 147 | void ATCmdManager::_oob_data_mode(){ |
ocomeni | 75:08eff6258e1b | 148 | int dataMode; |
ocomeni | 75:08eff6258e1b | 149 | _smutex.lock(); |
ocomeni | 75:08eff6258e1b | 150 | printf("\n Received EDM mode command!!\n"); |
ocomeni | 75:08eff6258e1b | 151 | if(_parser.scanf("%d", &dataMode) >0) { |
ocomeni | 75:08eff6258e1b | 152 | printf("\nATCmdParser: Data mode=%d\n", dataMode); |
ocomeni | 75:08eff6258e1b | 153 | switch(dataMode) |
ocomeni | 75:08eff6258e1b | 154 | { |
ocomeni | 75:08eff6258e1b | 155 | case 0: |
ocomeni | 75:08eff6258e1b | 156 | printf("\nATCmdParser: Command Mode request received"); |
ocomeni | 75:08eff6258e1b | 157 | break; |
ocomeni | 75:08eff6258e1b | 158 | case 1: |
ocomeni | 75:08eff6258e1b | 159 | printf("\nATCmdParser: Data Mode request received"); |
ocomeni | 75:08eff6258e1b | 160 | break; |
ocomeni | 75:08eff6258e1b | 161 | case 2: |
ocomeni | 75:08eff6258e1b | 162 | printf("\nATCmdParser: Extended data Mode request received"); |
ocomeni | 75:08eff6258e1b | 163 | break; |
ocomeni | 75:08eff6258e1b | 164 | default: |
ocomeni | 75:08eff6258e1b | 165 | printf("\nATCmdParser: ERROR - UNKNOWN DATA MODE RECEIVED!!! \n"); |
ocomeni | 75:08eff6258e1b | 166 | break; |
ocomeni | 75:08eff6258e1b | 167 | } |
ocomeni | 75:08eff6258e1b | 168 | } else { |
ocomeni | 75:08eff6258e1b | 169 | printf("\nATCmdParser: Retrieving Uart Options failed"); |
ocomeni | 75:08eff6258e1b | 170 | } |
ocomeni | 75:08eff6258e1b | 171 | _parser.send("OK\n"); |
ocomeni | 75:08eff6258e1b | 172 | _smutex.unlock(); |
ocomeni | 75:08eff6258e1b | 173 | } |
ocomeni | 75:08eff6258e1b | 174 | |
ocomeni | 75:08eff6258e1b | 175 | void ATCmdManager::_oob_get_mac_addr(){ |
ocomeni | 75:08eff6258e1b | 176 | int bleOrWifi; |
ocomeni | 75:08eff6258e1b | 177 | _smutex.lock(); |
ocomeni | 75:08eff6258e1b | 178 | if(_parser.scanf("=%d", &bleOrWifi) >0) { |
ocomeni | 75:08eff6258e1b | 179 | switch(bleOrWifi) |
ocomeni | 75:08eff6258e1b | 180 | { |
ocomeni | 75:08eff6258e1b | 181 | case 1: |
ocomeni | 75:08eff6258e1b | 182 | printf("\nATCmdParser: BLE MAC Address request received"); |
ocomeni | 75:08eff6258e1b | 183 | break; |
ocomeni | 75:08eff6258e1b | 184 | case 2: |
ocomeni | 75:08eff6258e1b | 185 | printf("\nATCmdParser: WiFi MAC Address request received"); |
ocomeni | 75:08eff6258e1b | 186 | break; |
ocomeni | 75:08eff6258e1b | 187 | default: |
ocomeni | 75:08eff6258e1b | 188 | printf("\nATCmdParser: ERROR - UNKNOWN MAC ADDRESS REQUEST RECEIVED!!! \n"); |
ocomeni | 75:08eff6258e1b | 189 | break; |
ocomeni | 75:08eff6258e1b | 190 | } |
ocomeni | 75:08eff6258e1b | 191 | } else { |
ocomeni | 75:08eff6258e1b | 192 | printf("\nATCmdParser: Retrieving Uart Options failed"); |
ocomeni | 75:08eff6258e1b | 193 | } |
ocomeni | 75:08eff6258e1b | 194 | _parser.send("OK\n"); |
ocomeni | 75:08eff6258e1b | 195 | _smutex.unlock(); |
ocomeni | 75:08eff6258e1b | 196 | } |
ocomeni | 75:08eff6258e1b | 197 | |
ocomeni | 75:08eff6258e1b | 198 | void ATCmdManager::_oob_get_ble_role(){ |
ocomeni | 75:08eff6258e1b | 199 | _smutex.lock(); |
ocomeni | 75:08eff6258e1b | 200 | printf("\n Received get BLE role command!!\n"); |
ocomeni | 75:08eff6258e1b | 201 | _parser.send("OK\n"); |
ocomeni | 75:08eff6258e1b | 202 | _smutex.unlock(); |
ocomeni | 75:08eff6258e1b | 203 | } |
ocomeni | 75:08eff6258e1b | 204 | |
ocomeni | 75:08eff6258e1b | 205 | void ATCmdManager::_oob_ena_ble_peri(){ |
ocomeni | 75:08eff6258e1b | 206 | _smutex.lock(); |
ocomeni | 75:08eff6258e1b | 207 | printf("\n Received enable BLE Peripheral command!!\n"); |
ocomeni | 75:08eff6258e1b | 208 | _parser.send("OK\n"); |
ocomeni | 75:08eff6258e1b | 209 | _smutex.unlock(); |
ocomeni | 75:08eff6258e1b | 210 | } |
ocomeni | 75:08eff6258e1b | 211 | |
ocomeni | 75:08eff6258e1b | 212 | void ATCmdManager::_oob_reboot(){ |
ocomeni | 75:08eff6258e1b | 213 | _smutex.lock(); |
ocomeni | 75:08eff6258e1b | 214 | printf("\n Received reboot command!!\n"); |
ocomeni | 75:08eff6258e1b | 215 | _parser.send("OK\n"); |
ocomeni | 75:08eff6258e1b | 216 | _parser.send("System Resetting....\n"); |
ocomeni | 75:08eff6258e1b | 217 | system_reset(); |
ocomeni | 75:08eff6258e1b | 218 | _smutex.unlock(); |
ocomeni | 75:08eff6258e1b | 219 | } |
ocomeni | 75:08eff6258e1b | 220 | |
ocomeni | 79:a2187bbfa407 | 221 | const char * ATCmdManager::sec2str(nsapi_security_t sec) |
ocomeni | 79:a2187bbfa407 | 222 | { |
ocomeni | 79:a2187bbfa407 | 223 | switch (sec) { |
ocomeni | 79:a2187bbfa407 | 224 | case NSAPI_SECURITY_NONE: |
ocomeni | 79:a2187bbfa407 | 225 | return "None"; |
ocomeni | 79:a2187bbfa407 | 226 | case NSAPI_SECURITY_WEP: |
ocomeni | 79:a2187bbfa407 | 227 | return "WEP"; |
ocomeni | 79:a2187bbfa407 | 228 | case NSAPI_SECURITY_WPA: |
ocomeni | 79:a2187bbfa407 | 229 | return "WPA"; |
ocomeni | 79:a2187bbfa407 | 230 | case NSAPI_SECURITY_WPA2: |
ocomeni | 79:a2187bbfa407 | 231 | return "WPA2"; |
ocomeni | 79:a2187bbfa407 | 232 | case NSAPI_SECURITY_WPA_WPA2: |
ocomeni | 79:a2187bbfa407 | 233 | return "WPA/WPA2"; |
ocomeni | 79:a2187bbfa407 | 234 | case NSAPI_SECURITY_UNKNOWN: |
ocomeni | 79:a2187bbfa407 | 235 | default: |
ocomeni | 79:a2187bbfa407 | 236 | return "Unknown"; |
ocomeni | 79:a2187bbfa407 | 237 | } |
ocomeni | 79:a2187bbfa407 | 238 | } |
ocomeni | 79:a2187bbfa407 | 239 | bool ATCmdManager::queueWiFiCommand(wifi_cmd_t cmd){ |
ocomeni | 79:a2187bbfa407 | 240 | wifi_cmd_message_t *wifiCmd = _aT2WiFimPool->alloc(); |
ocomeni | 79:a2187bbfa407 | 241 | wifiCmd->wifi_cmd = cmd; |
ocomeni | 79:a2187bbfa407 | 242 | _aT2WiFiCmdQueue->put(wifiCmd); |
ocomeni | 79:a2187bbfa407 | 243 | return true; |
ocomeni | 79:a2187bbfa407 | 244 | } |
ocomeni | 79:a2187bbfa407 | 245 | |
ocomeni | 79:a2187bbfa407 | 246 | void ATCmdManager::_oob_scanWiFiNetworks(){ |
ocomeni | 75:08eff6258e1b | 247 | _smutex.lock(); |
ocomeni | 79:a2187bbfa407 | 248 | printf("\n Received scanWiFiNetworks command!!\n"); |
ocomeni | 75:08eff6258e1b | 249 | _parser.send("OK\n"); |
ocomeni | 75:08eff6258e1b | 250 | _smutex.unlock(); |
ocomeni | 79:a2187bbfa407 | 251 | wifi_cmd_t cmd = WIFI_CMD_SCAN; |
ocomeni | 79:a2187bbfa407 | 252 | // queue next command |
ocomeni | 79:a2187bbfa407 | 253 | queueWiFiCommand(cmd); |
ocomeni | 79:a2187bbfa407 | 254 | bool success; |
ocomeni | 79:a2187bbfa407 | 255 | success = wiFiManager->setNextCommand(cmd); |
ocomeni | 79:a2187bbfa407 | 256 | if(success){ |
ocomeni | 79:a2187bbfa407 | 257 | printf("\n scan command successfully sent to wiFiManager!!\n"); |
ocomeni | 79:a2187bbfa407 | 258 | } |
ocomeni | 79:a2187bbfa407 | 259 | else { |
ocomeni | 79:a2187bbfa407 | 260 | printf("\n ERROR: Failed to send scan command wiFiManager!!\n"); |
ocomeni | 79:a2187bbfa407 | 261 | } |
ocomeni | 79:a2187bbfa407 | 262 | return; |
ocomeni | 79:a2187bbfa407 | 263 | /* call WiFi Scan in 20 ms */ |
ocomeni | 79:a2187bbfa407 | 264 | //_event_queue.call_in( |
ocomeni | 79:a2187bbfa407 | 265 | // 20, wiFiManager, |
ocomeni | 79:a2187bbfa407 | 266 | // &WiFiManager::scanNetworks); |
ocomeni | 79:a2187bbfa407 | 267 | //return; |
ocomeni | 79:a2187bbfa407 | 268 | WiFiAccessPoint *ap; |
ocomeni | 79:a2187bbfa407 | 269 | nsapi_size_or_error_t count; |
ocomeni | 79:a2187bbfa407 | 270 | //count = wiFiManager->scanNetworks(); |
ocomeni | 79:a2187bbfa407 | 271 | if (count <= 0) { |
ocomeni | 79:a2187bbfa407 | 272 | _smutex.lock(); |
ocomeni | 79:a2187bbfa407 | 273 | printf("scan() failed with return value: %d\n", count); |
ocomeni | 79:a2187bbfa407 | 274 | _smutex.unlock(); |
ocomeni | 79:a2187bbfa407 | 275 | return; |
ocomeni | 79:a2187bbfa407 | 276 | } |
ocomeni | 79:a2187bbfa407 | 277 | /* Limit number of network arbitrary to 15 */ |
ocomeni | 79:a2187bbfa407 | 278 | count = count < 15 ? count : 15; |
ocomeni | 79:a2187bbfa407 | 279 | ap = new WiFiAccessPoint[count]; |
ocomeni | 79:a2187bbfa407 | 280 | count = wiFiManager->getAvailableAPs(ap, count); |
ocomeni | 79:a2187bbfa407 | 281 | if (count <= 0) { |
ocomeni | 79:a2187bbfa407 | 282 | printf("scan() failed with return value: %d\n", count); |
ocomeni | 79:a2187bbfa407 | 283 | return; |
ocomeni | 79:a2187bbfa407 | 284 | } |
ocomeni | 79:a2187bbfa407 | 285 | |
ocomeni | 79:a2187bbfa407 | 286 | for (int i = 0; i < count; i++) { |
ocomeni | 79:a2187bbfa407 | 287 | printf("Network: %s secured: %s BSSID: %hhX:%hhX:%hhX:%hhx:%hhx:%hhx RSSI: %hhd Ch: %hhd\n", ap[i].get_ssid(), |
ocomeni | 79:a2187bbfa407 | 288 | sec2str(ap[i].get_security()), ap[i].get_bssid()[0], ap[i].get_bssid()[1], ap[i].get_bssid()[2], |
ocomeni | 79:a2187bbfa407 | 289 | ap[i].get_bssid()[3], ap[i].get_bssid()[4], ap[i].get_bssid()[5], ap[i].get_rssi(), ap[i].get_channel()); |
ocomeni | 79:a2187bbfa407 | 290 | } |
ocomeni | 79:a2187bbfa407 | 291 | printf("%d networks available.\n", count); |
ocomeni | 79:a2187bbfa407 | 292 | |
ocomeni | 79:a2187bbfa407 | 293 | delete[] ap; |
ocomeni | 79:a2187bbfa407 | 294 | |
ocomeni | 75:08eff6258e1b | 295 | } |
ocomeni | 75:08eff6258e1b | 296 | |
ocomeni | 79:a2187bbfa407 | 297 | void ATCmdManager::_oob_connect2WiFiNetwork() |
ocomeni | 79:a2187bbfa407 | 298 | { |
ocomeni | 79:a2187bbfa407 | 299 | wiFiManager->connect(); |
ocomeni | 79:a2187bbfa407 | 300 | } |
ocomeni | 79:a2187bbfa407 | 301 | |
ocomeni | 79:a2187bbfa407 | 302 | |
ocomeni | 79:a2187bbfa407 | 303 | void ATCmdManager::_oob_disconnectWiFiNetwork() |
ocomeni | 79:a2187bbfa407 | 304 | { |
ocomeni | 79:a2187bbfa407 | 305 | wiFiManager->disconnect(); |
ocomeni | 79:a2187bbfa407 | 306 | } |