this is using the mbed os version 5-13-1
source/WiFiManager.cpp@109:c274780ff609, 2019-05-08 (annotated)
- Committer:
- ocomeni
- Date:
- Wed May 08 19:38:35 2019 +0000
- Branch:
- PassingRegression
- Revision:
- 109:c274780ff609
- Parent:
- 108:3c8fb2c6e7bf
- Child:
- 110:c722dda4f2ff
1. updated HTTP packet state to monitor for multiple packets; 2. fixed bug causing crash (was canceling an active task on event queue); 2. updates to watchdog. added ticker.;
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| ocomeni | 103:7b566b522427 | 1 | #include "debug.h" |
| ocomeni | 78:07bb86e3ce14 | 2 | #include "WiFiManager.h" |
| ocomeni | 78:07bb86e3ce14 | 3 | #include "common_config.h" |
| ocomeni | 103:7b566b522427 | 4 | #define FILE_CODE "wifi" |
| ocomeni | 108:3c8fb2c6e7bf | 5 | #define USE_EVENTS_FOR_HTTPS_REQUESTS |
| ocomeni | 78:07bb86e3ce14 | 6 | |
| ocomeni | 79:a2187bbfa407 | 7 | WiFiManager::WiFiManager(wifi_config_t wifi_config, WiFiInterface *wifi, |
| ocomeni | 98:65c2333a38b6 | 8 | events::EventQueue &event_queue, |
| ocomeni | 80:e8f0e92e3ac9 | 9 | MemoryPool<wifi_cmd_message_t, 16> *aT2WiFimPool, |
| ocomeni | 80:e8f0e92e3ac9 | 10 | Queue<wifi_cmd_message_t, 16> *aT2WiFiCmdQueue, |
| ocomeni | 81:637a87eb8170 | 11 | MemoryPool<at_resp_message_t, 16> *wiFi2ATmPool, |
| ocomeni | 81:637a87eb8170 | 12 | Queue<at_resp_message_t, 16> *wiFi2ATCmdQueue, |
| ocomeni | 87:99b37d26ff2a | 13 | MemoryPool<wifi_data_msg_t, PQDSZ> *aT2WiFiDatamPool, |
| ocomeni | 87:99b37d26ff2a | 14 | Queue<wifi_data_msg_t, PQDSZ> *aT2WiFiDataQueue, |
| ocomeni | 87:99b37d26ff2a | 15 | MemoryPool<at_data_msg_t, PQDSZ> *wiFi2ATDatamPool, |
| ocomeni | 87:99b37d26ff2a | 16 | Queue<at_data_msg_t, PQDSZ> *wiFi2ATDataQueue) |
| ocomeni | 78:07bb86e3ce14 | 17 | : |
| ocomeni | 81:637a87eb8170 | 18 | wifi_config(wifi_config), |
| ocomeni | 81:637a87eb8170 | 19 | network(wifi), |
| ocomeni | 98:65c2333a38b6 | 20 | _event_queue(event_queue), |
| ocomeni | 81:637a87eb8170 | 21 | _aT2WiFimPool(aT2WiFimPool), |
| ocomeni | 81:637a87eb8170 | 22 | _aT2WiFiCmdQueue(aT2WiFiCmdQueue), |
| ocomeni | 81:637a87eb8170 | 23 | |
| ocomeni | 81:637a87eb8170 | 24 | _wiFi2ATmPool(wiFi2ATmPool), |
| ocomeni | 81:637a87eb8170 | 25 | _wiFi2ATCmdQueue(wiFi2ATCmdQueue), |
| ocomeni | 81:637a87eb8170 | 26 | |
| ocomeni | 81:637a87eb8170 | 27 | _aT2WiFiDatamPool(aT2WiFiDatamPool), |
| ocomeni | 81:637a87eb8170 | 28 | _aT2WiFiDataQueue(aT2WiFiDataQueue), |
| ocomeni | 81:637a87eb8170 | 29 | |
| ocomeni | 81:637a87eb8170 | 30 | _wiFi2ATDatamPool(wiFi2ATDatamPool), |
| ocomeni | 81:637a87eb8170 | 31 | _wiFi2ATDataQueue(wiFi2ATDataQueue) |
| ocomeni | 78:07bb86e3ce14 | 32 | |
| ocomeni | 78:07bb86e3ce14 | 33 | { |
| ocomeni | 104:11e9605093c9 | 34 | lastScanCount = 0; |
| ocomeni | 104:11e9605093c9 | 35 | wifiCmd = WIFI_CMD_NONE; |
| ocomeni | 104:11e9605093c9 | 36 | internet_config.connectionScheme = ALWAYS_CONNECTED; // set default connection scheme |
| ocomeni | 104:11e9605093c9 | 37 | is_connected = false; |
| ocomeni | 104:11e9605093c9 | 38 | http_response = NULL; |
| ocomeni | 104:11e9605093c9 | 39 | chunkNum = 0; |
| ocomeni | 104:11e9605093c9 | 40 | socket = NULL; |
| ocomeni | 104:11e9605093c9 | 41 | https_connection_active = false; |
| ocomeni | 104:11e9605093c9 | 42 | wifiBusy = 0; |
| ocomeni | 104:11e9605093c9 | 43 | wifiWatchdogTimer.start(); |
| ocomeni | 104:11e9605093c9 | 44 | watchdogCnt = 0; |
| ocomeni | 109:c274780ff609 | 45 | //_event_queue.call_every(10000, this, &WiFiManager::callWifiWatchDog); |
| ocomeni | 109:c274780ff609 | 46 | watchDogTick.attach(this, &WiFiManager::callWifiWatchDogIsr, 10000.0); // call flip function every 2 seconds |
| ocomeni | 78:07bb86e3ce14 | 47 | } |
| ocomeni | 78:07bb86e3ce14 | 48 | |
| ocomeni | 78:07bb86e3ce14 | 49 | WiFiManager::~WiFiManager() |
| ocomeni | 78:07bb86e3ce14 | 50 | { |
| ocomeni | 78:07bb86e3ce14 | 51 | } |
| ocomeni | 105:e5ce023eee93 | 52 | //#define DISABLE_WATCHDOG |
| ocomeni | 109:c274780ff609 | 53 | |
| ocomeni | 109:c274780ff609 | 54 | void WiFiManager::callWifiWatchDogIsr() |
| ocomeni | 109:c274780ff609 | 55 | { |
| ocomeni | 109:c274780ff609 | 56 | _event_queue.call(this, &WiFiManager::callWifiWatchDog); |
| ocomeni | 109:c274780ff609 | 57 | } |
| ocomeni | 104:11e9605093c9 | 58 | void WiFiManager::callWifiWatchDog() |
| ocomeni | 104:11e9605093c9 | 59 | { |
| ocomeni | 105:e5ce023eee93 | 60 | #ifdef DISABLE_WATCHDOG |
| ocomeni | 105:e5ce023eee93 | 61 | return; |
| ocomeni | 105:e5ce023eee93 | 62 | #else |
| ocomeni | 104:11e9605093c9 | 63 | static int inactivity_monitor = 0; |
| ocomeni | 104:11e9605093c9 | 64 | watchdogCnt++; |
| ocomeni | 104:11e9605093c9 | 65 | if(watchdogCnt >= 6 && responseString==NULL) // every minute |
| ocomeni | 104:11e9605093c9 | 66 | { |
| ocomeni | 107:f1a83fd41b17 | 67 | responseString = (char *) malloc(120); |
| ocomeni | 107:f1a83fd41b17 | 68 | sprintf(responseString, "\r\n[WiFi-MAN] WiFi Manager Alive : state = %d busy = %d httpsConnActive = %d\r\n", |
| ocomeni | 107:f1a83fd41b17 | 69 | wifiCmd, wifiBusy, https_connection_active); |
| ocomeni | 104:11e9605093c9 | 70 | sendATresponseString(WIFI_WATCH_DOG); |
| ocomeni | 104:11e9605093c9 | 71 | watchdogCnt = 0; |
| ocomeni | 104:11e9605093c9 | 72 | } |
| ocomeni | 104:11e9605093c9 | 73 | else if(wifiWatchdogTimer.read() > 30.0 && responseString==NULL) |
| ocomeni | 104:11e9605093c9 | 74 | { |
| ocomeni | 104:11e9605093c9 | 75 | if(wifiCmd == WIFI_CMD_NONE) |
| ocomeni | 104:11e9605093c9 | 76 | inactivity_monitor++; |
| ocomeni | 107:f1a83fd41b17 | 77 | responseString = (char *) malloc(120); |
| ocomeni | 104:11e9605093c9 | 78 | sprintf(responseString, "\r\n[WiFi-MAN] Main Loop InActive : state = %d busy = %d httpsConnActive = %d\r\n", |
| ocomeni | 104:11e9605093c9 | 79 | wifiCmd, wifiBusy, https_connection_active); |
| ocomeni | 104:11e9605093c9 | 80 | sendATresponseString(WIFI_WATCH_DOG); |
| ocomeni | 104:11e9605093c9 | 81 | if(inactivity_monitor >= 3) |
| ocomeni | 104:11e9605093c9 | 82 | { |
| ocomeni | 104:11e9605093c9 | 83 | free_DataMsg(); |
| ocomeni | 104:11e9605093c9 | 84 | inactivity_monitor = 0; |
| ocomeni | 104:11e9605093c9 | 85 | } |
| ocomeni | 104:11e9605093c9 | 86 | } |
| ocomeni | 105:e5ce023eee93 | 87 | #endif |
| ocomeni | 104:11e9605093c9 | 88 | } |
| ocomeni | 79:a2187bbfa407 | 89 | |
| ocomeni | 81:637a87eb8170 | 90 | bool WiFiManager::queueATresponse(at_cmd_resp_t resp){ |
| ocomeni | 92:ec9550034276 | 91 | #ifndef USE_MALLOC_FOR_COMMAND_MEMORY_POOL |
| ocomeni | 81:637a87eb8170 | 92 | at_resp_message_t *atResp = _wiFi2ATmPool->alloc(); |
| ocomeni | 92:ec9550034276 | 93 | #else |
| ocomeni | 92:ec9550034276 | 94 | at_resp_message_t *atResp = (at_resp_message_t *) malloc(sizeof(at_resp_message_t)); |
| ocomeni | 92:ec9550034276 | 95 | #endif |
| ocomeni | 88:7ffa053be662 | 96 | if(atResp == NULL) return false; // queue full; |
| ocomeni | 81:637a87eb8170 | 97 | atResp->at_resp = resp; |
| ocomeni | 81:637a87eb8170 | 98 | _wiFi2ATCmdQueue->put(atResp); |
| ocomeni | 81:637a87eb8170 | 99 | return true; |
| ocomeni | 81:637a87eb8170 | 100 | } |
| ocomeni | 81:637a87eb8170 | 101 | |
| ocomeni | 81:637a87eb8170 | 102 | |
| ocomeni | 81:637a87eb8170 | 103 | bool WiFiManager::queueWiFiDataResponse(at_data_msg_t at_resp){ |
| ocomeni | 81:637a87eb8170 | 104 | at_data_msg_t *atData = _wiFi2ATDatamPool->alloc(); |
| ocomeni | 88:7ffa053be662 | 105 | if(atData == NULL) return false; // queue full; |
| ocomeni | 81:637a87eb8170 | 106 | atData->at_resp = at_resp.at_resp; |
| ocomeni | 81:637a87eb8170 | 107 | atData->dataLen = at_resp.dataLen; |
| ocomeni | 81:637a87eb8170 | 108 | memcpy(atData->buffer, at_resp.buffer, at_resp.dataLen); |
| ocomeni | 81:637a87eb8170 | 109 | _wiFi2ATDataQueue->put(atData); |
| ocomeni | 103:7b566b522427 | 110 | dbg_printf(LOG, "[WIFI MAN] queued data size = %d : at_resp = %d\n", at_resp.dataLen, at_resp.at_resp); |
| ocomeni | 81:637a87eb8170 | 111 | return true; |
| ocomeni | 81:637a87eb8170 | 112 | } |
| ocomeni | 81:637a87eb8170 | 113 | |
| ocomeni | 79:a2187bbfa407 | 114 | |
| ocomeni | 79:a2187bbfa407 | 115 | |
| ocomeni | 79:a2187bbfa407 | 116 | void WiFiManager::runMain(){ |
| ocomeni | 81:637a87eb8170 | 117 | nsapi_error_t error; |
| ocomeni | 99:05398b3184f8 | 118 | bool result; |
| ocomeni | 103:7b566b522427 | 119 | dbg_printf(LOG, "\r\n [WIFI MAN] Thread Id = %X\r\n", (uint32_t)ThisThread::get_id()); |
| ocomeni | 79:a2187bbfa407 | 120 | while(true){ |
| ocomeni | 79:a2187bbfa407 | 121 | dequeueWiFiCommands(); |
| ocomeni | 81:637a87eb8170 | 122 | dequeueATdataResponse(); |
| ocomeni | 104:11e9605093c9 | 123 | wifiWatchdogTimer.reset(); |
| ocomeni | 79:a2187bbfa407 | 124 | switch(wifiCmd){ |
| ocomeni | 79:a2187bbfa407 | 125 | case WIFI_CMD_NONE: |
| ocomeni | 79:a2187bbfa407 | 126 | // IDLE STATE |
| ocomeni | 79:a2187bbfa407 | 127 | break; |
| ocomeni | 79:a2187bbfa407 | 128 | case WIFI_CMD_SCAN: |
| ocomeni | 104:11e9605093c9 | 129 | wifiBusy = 1; |
| ocomeni | 79:a2187bbfa407 | 130 | error = scanNetworks(); |
| ocomeni | 79:a2187bbfa407 | 131 | wifiCmd = WIFI_CMD_NONE; |
| ocomeni | 81:637a87eb8170 | 132 | queueATresponse(AT_SCAN_RESP); |
| ocomeni | 104:11e9605093c9 | 133 | wifiBusy = 0; |
| ocomeni | 81:637a87eb8170 | 134 | break; |
| ocomeni | 81:637a87eb8170 | 135 | case WIFI_CMD_DETAILED_SCAN: |
| ocomeni | 98:65c2333a38b6 | 136 | { |
| ocomeni | 104:11e9605093c9 | 137 | wifiBusy = 1; |
| ocomeni | 81:637a87eb8170 | 138 | nsapi_size_or_error_t cnt_err; |
| ocomeni | 81:637a87eb8170 | 139 | cnt_err = getAvailableAPs(lastScanCount); |
| ocomeni | 81:637a87eb8170 | 140 | wifiCmd = WIFI_CMD_NONE; |
| ocomeni | 81:637a87eb8170 | 141 | queueATresponse(AT_DETAILED_SCAN_RESP); |
| ocomeni | 104:11e9605093c9 | 142 | wifiBusy = 0; |
| ocomeni | 79:a2187bbfa407 | 143 | break; |
| ocomeni | 98:65c2333a38b6 | 144 | } |
| ocomeni | 79:a2187bbfa407 | 145 | case WIFI_CMD_CONNECT: |
| ocomeni | 98:65c2333a38b6 | 146 | { |
| ocomeni | 104:11e9605093c9 | 147 | wifiBusy = 1; |
| ocomeni | 81:637a87eb8170 | 148 | error = connect(); |
| ocomeni | 93:06e755a80187 | 149 | int secCount = 0; |
| ocomeni | 93:06e755a80187 | 150 | while(secCount++ < WIFI_CONNECT_TIMEOUT_SECS || is_connected==false){ |
| ocomeni | 93:06e755a80187 | 151 | wait(1); // wait 1 sec |
| ocomeni | 93:06e755a80187 | 152 | } |
| ocomeni | 81:637a87eb8170 | 153 | wifiCmd = WIFI_CMD_NONE; |
| ocomeni | 93:06e755a80187 | 154 | if(is_connected==false){ |
| ocomeni | 103:7b566b522427 | 155 | dbg_printf(LOG, "[WIFI MAN] +++ WIFI CONNECTION TIMEOUT +++ \r\n"); |
| ocomeni | 95:290859010c8c | 156 | //queueATresponse(AT_COMMAND_FAILED); |
| ocomeni | 95:290859010c8c | 157 | responseString = (char *) malloc(100); |
| ocomeni | 95:290859010c8c | 158 | sprintf(responseString, "\r\n+UUTIMEOUT\r\n"); |
| ocomeni | 95:290859010c8c | 159 | sendATresponseString(AT_COMMAND_FAILED); |
| ocomeni | 93:06e755a80187 | 160 | } |
| ocomeni | 93:06e755a80187 | 161 | else { |
| ocomeni | 95:290859010c8c | 162 | sendATresponseString(AT_CONNECT_RESP); |
| ocomeni | 93:06e755a80187 | 163 | } |
| ocomeni | 104:11e9605093c9 | 164 | wifiBusy = 0; |
| ocomeni | 79:a2187bbfa407 | 165 | break; |
| ocomeni | 98:65c2333a38b6 | 166 | } |
| ocomeni | 79:a2187bbfa407 | 167 | case WIFI_CMD_DISCONNECT: |
| ocomeni | 104:11e9605093c9 | 168 | wifiBusy = 1; |
| ocomeni | 81:637a87eb8170 | 169 | error = disconnect(); |
| ocomeni | 81:637a87eb8170 | 170 | wifiCmd = WIFI_CMD_NONE; |
| ocomeni | 81:637a87eb8170 | 171 | queueATresponse(AT_DISCONNECT_RESP); |
| ocomeni | 104:11e9605093c9 | 172 | wifiBusy = 0; |
| ocomeni | 81:637a87eb8170 | 173 | break; |
| ocomeni | 81:637a87eb8170 | 174 | case WIFI_CMD_CONFIG: |
| ocomeni | 104:11e9605093c9 | 175 | wifiBusy = 1; |
| ocomeni | 81:637a87eb8170 | 176 | set_WIFI_CONFIG(); |
| ocomeni | 81:637a87eb8170 | 177 | wifiCmd = WIFI_CMD_NONE; |
| ocomeni | 81:637a87eb8170 | 178 | queueATresponse(AT_CONFIG_RESP); |
| ocomeni | 104:11e9605093c9 | 179 | wifiBusy = 0; |
| ocomeni | 82:10072c1794d3 | 180 | break; |
| ocomeni | 81:637a87eb8170 | 181 | case WIFI_CMD_INTERNET_CONFIG: |
| ocomeni | 107:f1a83fd41b17 | 182 | { |
| ocomeni | 104:11e9605093c9 | 183 | wifiBusy = 1; |
| ocomeni | 107:f1a83fd41b17 | 184 | backgroundTaskCompleted = false; |
| ocomeni | 100:80ef4bc31b7a | 185 | set_internet_config(); |
| ocomeni | 107:f1a83fd41b17 | 186 | int msecCount = 0; |
| ocomeni | 107:f1a83fd41b17 | 187 | while(!backgroundTaskCompleted && msecCount < 1000) |
| ocomeni | 107:f1a83fd41b17 | 188 | { |
| ocomeni | 107:f1a83fd41b17 | 189 | msecCount++; |
| ocomeni | 107:f1a83fd41b17 | 190 | wait_ms(10); |
| ocomeni | 107:f1a83fd41b17 | 191 | } |
| ocomeni | 107:f1a83fd41b17 | 192 | if(backgroundTaskCompleted) |
| ocomeni | 107:f1a83fd41b17 | 193 | { |
| ocomeni | 107:f1a83fd41b17 | 194 | queueATresponse(AT_INTERNET_CONFIG_RESP); |
| ocomeni | 107:f1a83fd41b17 | 195 | } |
| ocomeni | 107:f1a83fd41b17 | 196 | backgroundTaskCompleted = false; |
| ocomeni | 81:637a87eb8170 | 197 | wifiCmd = WIFI_CMD_NONE; |
| ocomeni | 95:290859010c8c | 198 | break; |
| ocomeni | 107:f1a83fd41b17 | 199 | } |
| ocomeni | 95:290859010c8c | 200 | case WIFI_CMD_NETWORK_STATUS: |
| ocomeni | 104:11e9605093c9 | 201 | wifiBusy = 1; |
| ocomeni | 95:290859010c8c | 202 | getNetworkStatus(); |
| ocomeni | 95:290859010c8c | 203 | sendATresponseString(AT_NETWORK_STATUS_RESP); |
| ocomeni | 95:290859010c8c | 204 | wifiCmd = WIFI_CMD_NONE; |
| ocomeni | 104:11e9605093c9 | 205 | wifiBusy = 0; |
| ocomeni | 95:290859010c8c | 206 | break; |
| ocomeni | 95:290859010c8c | 207 | case WIFI_CMD_WIFI_STATUS: |
| ocomeni | 104:11e9605093c9 | 208 | wifiBusy = 1; |
| ocomeni | 95:290859010c8c | 209 | getWiFiStatus(); |
| ocomeni | 95:290859010c8c | 210 | sendATresponseString(AT_WIFI_STATUS_RESP); |
| ocomeni | 95:290859010c8c | 211 | wifiCmd = WIFI_CMD_NONE; |
| ocomeni | 104:11e9605093c9 | 212 | wifiBusy = 0; |
| ocomeni | 79:a2187bbfa407 | 213 | break; |
| ocomeni | 79:a2187bbfa407 | 214 | case WIFI_CMD_SEND_HTTPS_REQ: |
| ocomeni | 107:f1a83fd41b17 | 215 | { |
| ocomeni | 104:11e9605093c9 | 216 | wifiBusy = 1; |
| ocomeni | 109:c274780ff609 | 217 | #ifdef SEND_DEBUG_MESSAGES |
| ocomeni | 104:11e9605093c9 | 218 | if(responseString == NULL) |
| ocomeni | 104:11e9605093c9 | 219 | { |
| ocomeni | 104:11e9605093c9 | 220 | responseString = (char *) malloc(100); |
| ocomeni | 104:11e9605093c9 | 221 | sprintf(responseString, "\r\nHTTP REQUEST RECEIVED\r\n"); |
| ocomeni | 104:11e9605093c9 | 222 | sendATresponseString(AT_EVENT); |
| ocomeni | 104:11e9605093c9 | 223 | } |
| ocomeni | 109:c274780ff609 | 224 | #endif |
| ocomeni | 103:7b566b522427 | 225 | dbg_printf(LOG, "before call to send http request \n"); |
| ocomeni | 104:11e9605093c9 | 226 | dbg_printf(LOG, "\r\n[WIFI-MAN] Received HTTPS request...\r\n"); |
| ocomeni | 88:7ffa053be662 | 227 | print_memory_info(); |
| ocomeni | 105:e5ce023eee93 | 228 | //network->attach(NULL); |
| ocomeni | 107:f1a83fd41b17 | 229 | #ifdef USE_EVENTS_FOR_HTTPS_REQUESTS |
| ocomeni | 107:f1a83fd41b17 | 230 | |
| ocomeni | 107:f1a83fd41b17 | 231 | // Events can be cancelled as long as they have not been dispatched. If the |
| ocomeni | 107:f1a83fd41b17 | 232 | // event has already expired, cancel has no side-effects. |
| ocomeni | 107:f1a83fd41b17 | 233 | int event_id = _event_queue.call(this, &WiFiManager::createSendHttpsRequest); |
| ocomeni | 107:f1a83fd41b17 | 234 | backgroundTaskCompleted = false; |
| ocomeni | 107:f1a83fd41b17 | 235 | int msecCount = 0; |
| ocomeni | 109:c274780ff609 | 236 | int oldChunkNum = chunkNum; |
| ocomeni | 109:c274780ff609 | 237 | while(!backgroundTaskCompleted && msecCount < 6000) |
| ocomeni | 107:f1a83fd41b17 | 238 | { |
| ocomeni | 107:f1a83fd41b17 | 239 | msecCount++; |
| ocomeni | 107:f1a83fd41b17 | 240 | wait_ms(10); |
| ocomeni | 109:c274780ff609 | 241 | if(oldChunkNum != chunkNum) // new payload received |
| ocomeni | 109:c274780ff609 | 242 | { |
| ocomeni | 109:c274780ff609 | 243 | oldChunkNum = chunkNum; |
| ocomeni | 109:c274780ff609 | 244 | msecCount = 0; |
| ocomeni | 109:c274780ff609 | 245 | } |
| ocomeni | 107:f1a83fd41b17 | 246 | } |
| ocomeni | 107:f1a83fd41b17 | 247 | if(backgroundTaskCompleted) |
| ocomeni | 107:f1a83fd41b17 | 248 | { |
| ocomeni | 109:c274780ff609 | 249 | //queueATresponse(AT_INTERNET_CONFIG_RESP); |
| ocomeni | 107:f1a83fd41b17 | 250 | result = true; |
| ocomeni | 107:f1a83fd41b17 | 251 | } |
| ocomeni | 107:f1a83fd41b17 | 252 | else |
| ocomeni | 107:f1a83fd41b17 | 253 | { |
| ocomeni | 109:c274780ff609 | 254 | //_event_queue.cancel(event_id); |
| ocomeni | 107:f1a83fd41b17 | 255 | result = false; |
| ocomeni | 107:f1a83fd41b17 | 256 | } |
| ocomeni | 107:f1a83fd41b17 | 257 | backgroundTaskCompleted = false; |
| ocomeni | 107:f1a83fd41b17 | 258 | #else |
| ocomeni | 99:05398b3184f8 | 259 | result = createHttpsRequest(); |
| ocomeni | 107:f1a83fd41b17 | 260 | #endif |
| ocomeni | 99:05398b3184f8 | 261 | if(result == false) |
| ocomeni | 98:65c2333a38b6 | 262 | { |
| ocomeni | 104:11e9605093c9 | 263 | responseString = (char *) malloc(100); |
| ocomeni | 104:11e9605093c9 | 264 | if(http_result==TLS_CONNECTION_FAILED) |
| ocomeni | 104:11e9605093c9 | 265 | { |
| ocomeni | 104:11e9605093c9 | 266 | sprintf(responseString, "\r\nTLS CONNECTION FAILURE\r\n"); |
| ocomeni | 104:11e9605093c9 | 267 | } |
| ocomeni | 104:11e9605093c9 | 268 | else |
| ocomeni | 104:11e9605093c9 | 269 | { |
| ocomeni | 104:11e9605093c9 | 270 | sprintf(responseString, "\r\nHTTP REQUEST FAILED\r\n"); |
| ocomeni | 104:11e9605093c9 | 271 | } |
| ocomeni | 98:65c2333a38b6 | 272 | sendATresponseString(AT_COMMAND_FAILED); |
| ocomeni | 98:65c2333a38b6 | 273 | } |
| ocomeni | 103:7b566b522427 | 274 | dbg_printf(LOG, "after call to send http request \n"); |
| ocomeni | 88:7ffa053be662 | 275 | print_memory_info(); |
| ocomeni | 84:7c7add00f4bf | 276 | wifiCmd = WIFI_CMD_NONE; |
| ocomeni | 104:11e9605093c9 | 277 | wifiBusy = 0; |
| ocomeni | 105:e5ce023eee93 | 278 | //network->attach(callback(this, &WiFiManager::status_callback)); |
| ocomeni | 79:a2187bbfa407 | 279 | break; |
| ocomeni | 107:f1a83fd41b17 | 280 | } |
| ocomeni | 79:a2187bbfa407 | 281 | case WIFI_CMD_SEND_HTTP_REQ: |
| ocomeni | 79:a2187bbfa407 | 282 | break; |
| ocomeni | 79:a2187bbfa407 | 283 | default: |
| ocomeni | 79:a2187bbfa407 | 284 | break; |
| ocomeni | 79:a2187bbfa407 | 285 | } |
| ocomeni | 105:e5ce023eee93 | 286 | wait_ms(WIFI_MAIN_LOOP_WAIT_TIME_MS); // |
| ocomeni | 79:a2187bbfa407 | 287 | } |
| ocomeni | 79:a2187bbfa407 | 288 | |
| ocomeni | 78:07bb86e3ce14 | 289 | } |
| ocomeni | 79:a2187bbfa407 | 290 | |
| ocomeni | 107:f1a83fd41b17 | 291 | void WiFiManager::createSendHttpsRequest() |
| ocomeni | 107:f1a83fd41b17 | 292 | { |
| ocomeni | 107:f1a83fd41b17 | 293 | backgroundTaskCompleted = createHttpsRequest(); |
| ocomeni | 107:f1a83fd41b17 | 294 | } |
| ocomeni | 91:d6b6319ad681 | 295 | |
| ocomeni | 95:290859010c8c | 296 | void WiFiManager::sendATresponseString(at_cmd_resp_t at_cmd) |
| ocomeni | 91:d6b6319ad681 | 297 | { |
| ocomeni | 95:290859010c8c | 298 | int strLen = strlen(responseString) + 1; |
| ocomeni | 91:d6b6319ad681 | 299 | at_data_resp = new at_data_msg_t; |
| ocomeni | 91:d6b6319ad681 | 300 | // set string length |
| ocomeni | 91:d6b6319ad681 | 301 | at_data_resp->dataLen = strLen; |
| ocomeni | 91:d6b6319ad681 | 302 | memcpy(at_data_resp->buffer, responseString, strLen); |
| ocomeni | 95:290859010c8c | 303 | free(responseString); |
| ocomeni | 99:05398b3184f8 | 304 | responseString = NULL; |
| ocomeni | 91:d6b6319ad681 | 305 | // package and send on wifi data queue |
| ocomeni | 91:d6b6319ad681 | 306 | at_data_resp->at_resp = at_cmd; |
| ocomeni | 91:d6b6319ad681 | 307 | bool queueResult = true; |
| ocomeni | 91:d6b6319ad681 | 308 | int wait_count = 0; |
| ocomeni | 91:d6b6319ad681 | 309 | do |
| ocomeni | 91:d6b6319ad681 | 310 | { |
| ocomeni | 91:d6b6319ad681 | 311 | if(!queueResult){ |
| ocomeni | 91:d6b6319ad681 | 312 | wait_count++; |
| ocomeni | 103:7b566b522427 | 313 | dbg_printf(LOG, "ATCMD Queue full waiting %d ms so far...\n", wait_count*10); |
| ocomeni | 91:d6b6319ad681 | 314 | wait_ms(10); |
| ocomeni | 91:d6b6319ad681 | 315 | } |
| ocomeni | 91:d6b6319ad681 | 316 | queueResult = queueWiFiDataResponse(*at_data_resp); |
| ocomeni | 91:d6b6319ad681 | 317 | }while(queueResult == false); |
| ocomeni | 91:d6b6319ad681 | 318 | delete at_data_resp; |
| ocomeni | 99:05398b3184f8 | 319 | at_data_resp = NULL; |
| ocomeni | 91:d6b6319ad681 | 320 | } |
| ocomeni | 91:d6b6319ad681 | 321 | |
| ocomeni | 99:05398b3184f8 | 322 | |
| ocomeni | 99:05398b3184f8 | 323 | void WiFiManager::sendATresponseBytes(at_cmd_resp_t at_cmd, int len) |
| ocomeni | 99:05398b3184f8 | 324 | { |
| ocomeni | 99:05398b3184f8 | 325 | at_data_resp = new at_data_msg_t; |
| ocomeni | 99:05398b3184f8 | 326 | // set string length |
| ocomeni | 99:05398b3184f8 | 327 | at_data_resp->dataLen = len; |
| ocomeni | 99:05398b3184f8 | 328 | memcpy(at_data_resp->buffer, responseBytes, len); |
| ocomeni | 107:f1a83fd41b17 | 329 | delete responseBytes; |
| ocomeni | 99:05398b3184f8 | 330 | responseBytes = NULL; |
| ocomeni | 99:05398b3184f8 | 331 | // package and send on wifi data queue |
| ocomeni | 99:05398b3184f8 | 332 | at_data_resp->at_resp = at_cmd; |
| ocomeni | 99:05398b3184f8 | 333 | bool queueResult = true; |
| ocomeni | 99:05398b3184f8 | 334 | int wait_count = 0; |
| ocomeni | 99:05398b3184f8 | 335 | do |
| ocomeni | 99:05398b3184f8 | 336 | { |
| ocomeni | 99:05398b3184f8 | 337 | if(!queueResult){ |
| ocomeni | 99:05398b3184f8 | 338 | wait_count++; |
| ocomeni | 99:05398b3184f8 | 339 | wait_ms(10); |
| ocomeni | 103:7b566b522427 | 340 | dbg_printf(LOG, "ATCMD Queue full waited %d ms so far...\n", wait_count*10); |
| ocomeni | 99:05398b3184f8 | 341 | } |
| ocomeni | 99:05398b3184f8 | 342 | queueResult = queueWiFiDataResponse(*at_data_resp); |
| ocomeni | 99:05398b3184f8 | 343 | }while(queueResult == false); |
| ocomeni | 99:05398b3184f8 | 344 | delete at_data_resp; |
| ocomeni | 99:05398b3184f8 | 345 | at_data_resp = NULL; |
| ocomeni | 103:7b566b522427 | 346 | dbg_printf(LOG, "[WIFI-MAN] sendATresponseBytes completed successfully\r\n"); |
| ocomeni | 99:05398b3184f8 | 347 | } |
| ocomeni | 99:05398b3184f8 | 348 | |
| ocomeni | 99:05398b3184f8 | 349 | |
| ocomeni | 99:05398b3184f8 | 350 | |
| ocomeni | 79:a2187bbfa407 | 351 | bool WiFiManager::dequeueWiFiCommands(){ |
| ocomeni | 104:11e9605093c9 | 352 | if(wifiCmd != WIFI_CMD_NONE || wifiBusy!=0) return false; // busy |
| ocomeni | 81:637a87eb8170 | 353 | osEvent evt = _aT2WiFiCmdQueue->get(0); |
| ocomeni | 79:a2187bbfa407 | 354 | if(evt.status == osEventMessage){ |
| ocomeni | 79:a2187bbfa407 | 355 | wifi_cmd_message_t *cmd = (wifi_cmd_message_t*)evt.value.p; |
| ocomeni | 79:a2187bbfa407 | 356 | setNextCommand(cmd->wifi_cmd); |
| ocomeni | 92:ec9550034276 | 357 | #ifndef USE_MALLOC_FOR_COMMAND_MEMORY_POOL |
| ocomeni | 79:a2187bbfa407 | 358 | _aT2WiFimPool->free(cmd); |
| ocomeni | 96:f5ed273881af | 359 | cmd = NULL; |
| ocomeni | 92:ec9550034276 | 360 | #else |
| ocomeni | 92:ec9550034276 | 361 | free(cmd); |
| ocomeni | 96:f5ed273881af | 362 | cmd = NULL; |
| ocomeni | 92:ec9550034276 | 363 | #endif |
| ocomeni | 79:a2187bbfa407 | 364 | } |
| ocomeni | 79:a2187bbfa407 | 365 | return true; |
| ocomeni | 79:a2187bbfa407 | 366 | } |
| ocomeni | 79:a2187bbfa407 | 367 | |
| ocomeni | 79:a2187bbfa407 | 368 | |
| ocomeni | 81:637a87eb8170 | 369 | bool WiFiManager::dequeueATdataResponse(){ |
| ocomeni | 104:11e9605093c9 | 370 | if(wifiCmd != WIFI_CMD_NONE || wifiBusy!=0) return false; // busy |
| ocomeni | 81:637a87eb8170 | 371 | osEvent evt = _aT2WiFiDataQueue->get(0); |
| ocomeni | 81:637a87eb8170 | 372 | if(evt.status == osEventMessage){ |
| ocomeni | 81:637a87eb8170 | 373 | data_msg = (wifi_data_msg_t*)evt.value.p; |
| ocomeni | 81:637a87eb8170 | 374 | setNextCommand(data_msg->wifi_cmd); |
| ocomeni | 81:637a87eb8170 | 375 | //_wiFi2ATDatamPool->free(data_msg); |
| ocomeni | 81:637a87eb8170 | 376 | } |
| ocomeni | 81:637a87eb8170 | 377 | return true; |
| ocomeni | 81:637a87eb8170 | 378 | } |
| ocomeni | 81:637a87eb8170 | 379 | |
| ocomeni | 81:637a87eb8170 | 380 | |
| ocomeni | 79:a2187bbfa407 | 381 | bool WiFiManager::setNextCommand(wifi_cmd_t cmd) |
| ocomeni | 78:07bb86e3ce14 | 382 | { |
| ocomeni | 103:7b566b522427 | 383 | dbg_printf(LOG, "\n [WIFI-MAN] About to set next WiFi manager command to %d\n", cmd); |
| ocomeni | 79:a2187bbfa407 | 384 | if(wifiCmd == WIFI_CMD_NONE){ |
| ocomeni | 79:a2187bbfa407 | 385 | wifiCmd = cmd; |
| ocomeni | 79:a2187bbfa407 | 386 | return true; // success |
| ocomeni | 79:a2187bbfa407 | 387 | } |
| ocomeni | 103:7b566b522427 | 388 | dbg_printf(LOG, "\n [WIFI-MAN] Busy : current state = %d \n", wifiCmd); |
| ocomeni | 79:a2187bbfa407 | 389 | return false; // wiFiManager busy |
| ocomeni | 78:07bb86e3ce14 | 390 | } |
| ocomeni | 79:a2187bbfa407 | 391 | |
| ocomeni | 81:637a87eb8170 | 392 | const char * WiFiManager::sec2str(nsapi_security_t sec) |
| ocomeni | 81:637a87eb8170 | 393 | { |
| ocomeni | 81:637a87eb8170 | 394 | switch (sec) { |
| ocomeni | 81:637a87eb8170 | 395 | case NSAPI_SECURITY_NONE: |
| ocomeni | 81:637a87eb8170 | 396 | return "None"; |
| ocomeni | 81:637a87eb8170 | 397 | case NSAPI_SECURITY_WEP: |
| ocomeni | 81:637a87eb8170 | 398 | return "WEP"; |
| ocomeni | 81:637a87eb8170 | 399 | case NSAPI_SECURITY_WPA: |
| ocomeni | 81:637a87eb8170 | 400 | return "WPA"; |
| ocomeni | 81:637a87eb8170 | 401 | case NSAPI_SECURITY_WPA2: |
| ocomeni | 81:637a87eb8170 | 402 | return "WPA2"; |
| ocomeni | 81:637a87eb8170 | 403 | case NSAPI_SECURITY_WPA_WPA2: |
| ocomeni | 81:637a87eb8170 | 404 | return "WPA/WPA2"; |
| ocomeni | 81:637a87eb8170 | 405 | case NSAPI_SECURITY_UNKNOWN: |
| ocomeni | 81:637a87eb8170 | 406 | default: |
| ocomeni | 81:637a87eb8170 | 407 | return "Unknown"; |
| ocomeni | 81:637a87eb8170 | 408 | } |
| ocomeni | 81:637a87eb8170 | 409 | } |
| ocomeni | 81:637a87eb8170 | 410 | |
| ocomeni | 79:a2187bbfa407 | 411 | |
| ocomeni | 79:a2187bbfa407 | 412 | nsapi_size_or_error_t WiFiManager::scanNetworks() |
| ocomeni | 79:a2187bbfa407 | 413 | { |
| ocomeni | 79:a2187bbfa407 | 414 | nsapi_error_t error; |
| ocomeni | 103:7b566b522427 | 415 | dbg_printf(LOG, "\n [WIFI-MAN] About to start scan for WiFi networks\n"); |
| ocomeni | 79:a2187bbfa407 | 416 | lastScanCount = network->scan(NULL, 0); |
| ocomeni | 103:7b566b522427 | 417 | dbg_printf(LOG, "\n [WIFI-MAN] Scan for WiFi networks completed - \n"); |
| ocomeni | 79:a2187bbfa407 | 418 | return lastScanCount; |
| ocomeni | 79:a2187bbfa407 | 419 | } |
| ocomeni | 79:a2187bbfa407 | 420 | |
| ocomeni | 79:a2187bbfa407 | 421 | |
| ocomeni | 81:637a87eb8170 | 422 | //nsapi_size_or_error_t WiFiManager::getAvailableAPs(WiFiAccessPoint * res, |
| ocomeni | 81:637a87eb8170 | 423 | // nsapi_size_t ncount) |
| ocomeni | 81:637a87eb8170 | 424 | nsapi_size_or_error_t WiFiManager::getAvailableAPs(nsapi_size_t ncount) |
| ocomeni | 79:a2187bbfa407 | 425 | { |
| ocomeni | 81:637a87eb8170 | 426 | WiFiAccessPoint *ap; |
| ocomeni | 81:637a87eb8170 | 427 | nsapi_size_or_error_t count; |
| ocomeni | 81:637a87eb8170 | 428 | count = ncount; |
| ocomeni | 81:637a87eb8170 | 429 | //count = wiFiManager->scanNetworks(); |
| ocomeni | 81:637a87eb8170 | 430 | if (count <= 0) { |
| ocomeni | 81:637a87eb8170 | 431 | //_smutex.lock(); |
| ocomeni | 103:7b566b522427 | 432 | dbg_printf(LOG, "[WIFI-MAN] scan() failed with return value: %d\n", count); |
| ocomeni | 81:637a87eb8170 | 433 | //_smutex.unlock(); |
| ocomeni | 98:65c2333a38b6 | 434 | return 0; |
| ocomeni | 81:637a87eb8170 | 435 | } |
| ocomeni | 81:637a87eb8170 | 436 | /* Limit number of network arbitrary to 15 */ |
| ocomeni | 81:637a87eb8170 | 437 | count = count < 15 ? count : 15; |
| ocomeni | 81:637a87eb8170 | 438 | ap = new WiFiAccessPoint[count]; |
| ocomeni | 81:637a87eb8170 | 439 | count = network->scan(ap, count); |
| ocomeni | 81:637a87eb8170 | 440 | if (count <= 0) { |
| ocomeni | 103:7b566b522427 | 441 | dbg_printf(LOG, "[WIFI-MAN] scan() failed with return value: %d\n", count); |
| ocomeni | 98:65c2333a38b6 | 442 | return 0; |
| ocomeni | 81:637a87eb8170 | 443 | } |
| ocomeni | 81:637a87eb8170 | 444 | |
| ocomeni | 81:637a87eb8170 | 445 | for (int i = 0; i < count; i++) { |
| ocomeni | 103:7b566b522427 | 446 | dbg_printf(LOG, "[WIFI-MAN]: %s secured: %s BSSID: %hhX:%hhX:%hhX:%hhx:%hhx:%hhx RSSI: %hhd Ch: %hhd\n", ap[i].get_ssid(), |
| ocomeni | 81:637a87eb8170 | 447 | sec2str(ap[i].get_security()), ap[i].get_bssid()[0], ap[i].get_bssid()[1], ap[i].get_bssid()[2], |
| ocomeni | 81:637a87eb8170 | 448 | ap[i].get_bssid()[3], ap[i].get_bssid()[4], ap[i].get_bssid()[5], ap[i].get_rssi(), ap[i].get_channel()); |
| ocomeni | 81:637a87eb8170 | 449 | } |
| ocomeni | 103:7b566b522427 | 450 | dbg_printf(LOG, "[WIFI-MAN] %d networks available.\n", count); |
| ocomeni | 81:637a87eb8170 | 451 | |
| ocomeni | 81:637a87eb8170 | 452 | delete[] ap; |
| ocomeni | 79:a2187bbfa407 | 453 | return count; |
| ocomeni | 79:a2187bbfa407 | 454 | } |
| ocomeni | 79:a2187bbfa407 | 455 | |
| ocomeni | 79:a2187bbfa407 | 456 | |
| ocomeni | 81:637a87eb8170 | 457 | void WiFiManager::set_WIFI_CONFIG() |
| ocomeni | 81:637a87eb8170 | 458 | { |
| ocomeni | 81:637a87eb8170 | 459 | wifi_config_t *wifi_cfg= (wifi_config_t *) data_msg->buffer; |
| ocomeni | 82:10072c1794d3 | 460 | if(wifi_cfg->ssid[0] != NULL)set_WIFI_SSID(wifi_cfg->ssid); |
| ocomeni | 82:10072c1794d3 | 461 | if(wifi_cfg->pass[0] != NULL)set_WIFI_PASSWORD(wifi_cfg->pass); |
| ocomeni | 82:10072c1794d3 | 462 | if(wifi_cfg->security != NSAPI_SECURITY_UNKNOWN)set_WIFI_SECURITY(wifi_cfg->security); |
| ocomeni | 81:637a87eb8170 | 463 | free_DataMsg(); |
| ocomeni | 81:637a87eb8170 | 464 | } |
| ocomeni | 81:637a87eb8170 | 465 | |
| ocomeni | 78:07bb86e3ce14 | 466 | void WiFiManager::set_WIFI_SSID(char * wifi_ssid) |
| ocomeni | 78:07bb86e3ce14 | 467 | { |
| ocomeni | 78:07bb86e3ce14 | 468 | strcpy(wifi_config.ssid, wifi_ssid); |
| ocomeni | 103:7b566b522427 | 469 | dbg_printf(LOG, "[WIFI-MAN] wifi_ssid set to %s\n", wifi_config.ssid); |
| ocomeni | 88:7ffa053be662 | 470 | https_connection_active = false; // reset whenever any of the security credentials change |
| ocomeni | 91:d6b6319ad681 | 471 | delete socket; |
| ocomeni | 78:07bb86e3ce14 | 472 | } |
| ocomeni | 79:a2187bbfa407 | 473 | |
| ocomeni | 79:a2187bbfa407 | 474 | |
| ocomeni | 78:07bb86e3ce14 | 475 | void WiFiManager::set_WIFI_PASSWORD(char * wifi_pass) |
| ocomeni | 78:07bb86e3ce14 | 476 | { |
| ocomeni | 78:07bb86e3ce14 | 477 | strcpy(wifi_config.pass, wifi_pass); |
| ocomeni | 103:7b566b522427 | 478 | dbg_printf(LOG, "[WIFI-MAN] wifi_pass set to %s\n", "****************"); |
| ocomeni | 88:7ffa053be662 | 479 | https_connection_active = false; // reset whenever any of the security credentials change |
| ocomeni | 91:d6b6319ad681 | 480 | delete socket; |
| ocomeni | 78:07bb86e3ce14 | 481 | } |
| ocomeni | 79:a2187bbfa407 | 482 | |
| ocomeni | 79:a2187bbfa407 | 483 | |
| ocomeni | 78:07bb86e3ce14 | 484 | void WiFiManager::set_WIFI_SECURITY(nsapi_security_t wifi_security) |
| ocomeni | 78:07bb86e3ce14 | 485 | { |
| ocomeni | 78:07bb86e3ce14 | 486 | wifi_config.security = wifi_security; |
| ocomeni | 103:7b566b522427 | 487 | dbg_printf(LOG, "[WIFI-MAN] wifi_security set to %s\n", sec2str(wifi_config.security)); |
| ocomeni | 88:7ffa053be662 | 488 | https_connection_active = false; // reset whenever any of the security credentials change |
| ocomeni | 91:d6b6319ad681 | 489 | delete socket; |
| ocomeni | 78:07bb86e3ce14 | 490 | } |
| ocomeni | 79:a2187bbfa407 | 491 | |
| ocomeni | 100:80ef4bc31b7a | 492 | void WiFiManager::gethostbyname() |
| ocomeni | 100:80ef4bc31b7a | 493 | { |
| ocomeni | 100:80ef4bc31b7a | 494 | nsapi_value_or_error_t value_or_error; |
| ocomeni | 100:80ef4bc31b7a | 495 | value_or_error = network->gethostbyname_async(internet_config.url, |
| ocomeni | 100:80ef4bc31b7a | 496 | callback(this, &WiFiManager::gethostbyname_callback), |
| ocomeni | 100:80ef4bc31b7a | 497 | NSAPI_UNSPEC); |
| ocomeni | 100:80ef4bc31b7a | 498 | if(value_or_error >= NSAPI_ERROR_OK) // success |
| ocomeni | 100:80ef4bc31b7a | 499 | { |
| ocomeni | 103:7b566b522427 | 500 | dbg_printf(LOG, "[WIFI-MAN] hostname translation successful value_or_error = %d\r\n", value_or_error); |
| ocomeni | 100:80ef4bc31b7a | 501 | //strcpy(responseString, UDDRP_WRITE_OK); |
| ocomeni | 100:80ef4bc31b7a | 502 | //printBufferInHex(responseBytes, HOSTNAME_RESPONSE_LEN); |
| ocomeni | 100:80ef4bc31b7a | 503 | //sendATresponseBytes(CONNECT_EVENT, HOSTNAME_RESPONSE_LEN); |
| ocomeni | 100:80ef4bc31b7a | 504 | } |
| ocomeni | 100:80ef4bc31b7a | 505 | else // -ve number means error |
| ocomeni | 100:80ef4bc31b7a | 506 | { |
| ocomeni | 100:80ef4bc31b7a | 507 | responseString = (char *) malloc(20); |
| ocomeni | 103:7b566b522427 | 508 | dbg_printf(LOG, "[WIFI-MAN] hostname translation failed\r\n"); |
| ocomeni | 100:80ef4bc31b7a | 509 | strcpy(responseString, UDDRP_ERROR); |
| ocomeni | 100:80ef4bc31b7a | 510 | sendATresponseString(AT_COMMAND_FAILED); |
| ocomeni | 100:80ef4bc31b7a | 511 | } |
| ocomeni | 81:637a87eb8170 | 512 | |
| ocomeni | 100:80ef4bc31b7a | 513 | } |
| ocomeni | 100:80ef4bc31b7a | 514 | |
| ocomeni | 100:80ef4bc31b7a | 515 | void WiFiManager::set_internet_config() |
| ocomeni | 81:637a87eb8170 | 516 | { |
| ocomeni | 81:637a87eb8170 | 517 | internet_config_t *internet_cfg = (internet_config_t *) data_msg->buffer; |
| ocomeni | 81:637a87eb8170 | 518 | internet_config.peer_id = internet_cfg->peer_id; |
| ocomeni | 84:7c7add00f4bf | 519 | strncpy(internet_config.url,internet_cfg->url, strlen(internet_cfg->url)+1); |
| ocomeni | 81:637a87eb8170 | 520 | internet_config.connectionScheme = internet_cfg->connectionScheme; |
| ocomeni | 81:637a87eb8170 | 521 | free_DataMsg(); |
| ocomeni | 103:7b566b522427 | 522 | dbg_printf(LOG, "[WIFI MAN] Internet configuration setup completed\n"); |
| ocomeni | 103:7b566b522427 | 523 | dbg_printf(LOG, "peer_id = %1d, url = %s, connScheme = %1d\n", internet_config.peer_id, |
| ocomeni | 84:7c7add00f4bf | 524 | internet_config.url, |
| ocomeni | 81:637a87eb8170 | 525 | internet_config.connectionScheme); |
| ocomeni | 99:05398b3184f8 | 526 | if(https_connection_active) |
| ocomeni | 99:05398b3184f8 | 527 | { |
| ocomeni | 99:05398b3184f8 | 528 | https_connection_active = false; // reset whenever any of the security credentials change |
| ocomeni | 99:05398b3184f8 | 529 | socket->close(); // close socket before deleting memory |
| ocomeni | 99:05398b3184f8 | 530 | delete socket; |
| ocomeni | 99:05398b3184f8 | 531 | socket = NULL; |
| ocomeni | 99:05398b3184f8 | 532 | } |
| ocomeni | 100:80ef4bc31b7a | 533 | _event_queue.call_in(10, this, &WiFiManager::gethostbyname); |
| ocomeni | 81:637a87eb8170 | 534 | } |
| ocomeni | 81:637a87eb8170 | 535 | |
| ocomeni | 95:290859010c8c | 536 | |
| ocomeni | 95:290859010c8c | 537 | |
| ocomeni | 95:290859010c8c | 538 | void WiFiManager::getNetworkStatus(){ |
| ocomeni | 95:290859010c8c | 539 | |
| ocomeni | 95:290859010c8c | 540 | responseString = (char *) malloc(MAX_RESPONSE_STRING_LEN); |
| ocomeni | 95:290859010c8c | 541 | net_stat_id_t status_id; |
| ocomeni | 95:290859010c8c | 542 | char * nextStrPtr = responseString; |
| ocomeni | 95:290859010c8c | 543 | for(int i=0; i< NumNetworkStatus;i++){ |
| ocomeni | 95:290859010c8c | 544 | status_id = netStatusIds[i]; // get current status id |
| ocomeni | 95:290859010c8c | 545 | switch(status_id){ |
| ocomeni | 95:290859010c8c | 546 | case IF_HW_ADDRESS: |
| ocomeni | 95:290859010c8c | 547 | sprintf(nextStrPtr, "\r\n%s%d,%d,%s\r\n", NETWORK_STATUS, |
| ocomeni | 95:290859010c8c | 548 | WIFI_CHANNEL, |
| ocomeni | 95:290859010c8c | 549 | status_id, |
| ocomeni | 95:290859010c8c | 550 | network->get_mac_address()); |
| ocomeni | 95:290859010c8c | 551 | break; |
| ocomeni | 95:290859010c8c | 552 | case NETWORK_IF_STATUS: |
| ocomeni | 95:290859010c8c | 553 | sprintf(nextStrPtr, "\r\n%s%d,%d, %d\r\n", NETWORK_STATUS, |
| ocomeni | 95:290859010c8c | 554 | WIFI_CHANNEL, |
| ocomeni | 95:290859010c8c | 555 | status_id, |
| ocomeni | 95:290859010c8c | 556 | (uint8_t)is_connected); |
| ocomeni | 95:290859010c8c | 557 | break; |
| ocomeni | 95:290859010c8c | 558 | case INTERFACE_TYPE: |
| ocomeni | 95:290859010c8c | 559 | sprintf(nextStrPtr, "\r\n%s%d,%d,%d\r\n", NETWORK_STATUS, |
| ocomeni | 95:290859010c8c | 560 | WIFI_CHANNEL, |
| ocomeni | 95:290859010c8c | 561 | status_id, |
| ocomeni | 95:290859010c8c | 562 | WIFI_STATION); |
| ocomeni | 95:290859010c8c | 563 | break; |
| ocomeni | 95:290859010c8c | 564 | case IPv4_ADDRESS: |
| ocomeni | 95:290859010c8c | 565 | sprintf(nextStrPtr, "\r\n%s%d,%d,%s\r\n", NETWORK_STATUS, |
| ocomeni | 95:290859010c8c | 566 | WIFI_CHANNEL, |
| ocomeni | 95:290859010c8c | 567 | status_id, |
| ocomeni | 95:290859010c8c | 568 | network->get_ip_address()); |
| ocomeni | 95:290859010c8c | 569 | break; |
| ocomeni | 95:290859010c8c | 570 | case SUBNET_MASK: |
| ocomeni | 95:290859010c8c | 571 | sprintf(nextStrPtr, "\r\n%s%d,%d,%s\r\n", NETWORK_STATUS, |
| ocomeni | 95:290859010c8c | 572 | WIFI_CHANNEL, |
| ocomeni | 95:290859010c8c | 573 | status_id, |
| ocomeni | 95:290859010c8c | 574 | network->get_netmask()); |
| ocomeni | 95:290859010c8c | 575 | break; |
| ocomeni | 95:290859010c8c | 576 | case GATEWAY_ADDRESS: |
| ocomeni | 95:290859010c8c | 577 | sprintf(nextStrPtr, "\r\n%s%d,%d,%s\r\n", NETWORK_STATUS, |
| ocomeni | 95:290859010c8c | 578 | WIFI_CHANNEL, |
| ocomeni | 95:290859010c8c | 579 | status_id, |
| ocomeni | 95:290859010c8c | 580 | network->get_gateway()); |
| ocomeni | 95:290859010c8c | 581 | break; |
| ocomeni | 95:290859010c8c | 582 | case PRIMARY_DNS_SERVER: |
| ocomeni | 95:290859010c8c | 583 | sprintf(nextStrPtr, "\r\n%s%d,%d,%s\r\n", NETWORK_STATUS, |
| ocomeni | 95:290859010c8c | 584 | WIFI_CHANNEL, |
| ocomeni | 95:290859010c8c | 585 | status_id, |
| ocomeni | 95:290859010c8c | 586 | DEFAULT_DNS_ADDRESS); |
| ocomeni | 95:290859010c8c | 587 | break; |
| ocomeni | 95:290859010c8c | 588 | case SECONDARY_DNS_SERVER: |
| ocomeni | 95:290859010c8c | 589 | sprintf(nextStrPtr, "\r\n%s%d,%d,%s\r\n", NETWORK_STATUS, |
| ocomeni | 95:290859010c8c | 590 | WIFI_CHANNEL, |
| ocomeni | 95:290859010c8c | 591 | status_id, |
| ocomeni | 95:290859010c8c | 592 | DEFAULT_DNS_ADDRESS); |
| ocomeni | 95:290859010c8c | 593 | break; |
| ocomeni | 95:290859010c8c | 594 | case IPv6_ADDRESS: |
| ocomeni | 95:290859010c8c | 595 | sprintf(nextStrPtr, "\r\n%s%d,%d,::\r\n", NETWORK_STATUS, |
| ocomeni | 95:290859010c8c | 596 | WIFI_CHANNEL, |
| ocomeni | 95:290859010c8c | 597 | status_id); |
| ocomeni | 95:290859010c8c | 598 | break; |
| ocomeni | 95:290859010c8c | 599 | default: |
| ocomeni | 95:290859010c8c | 600 | sprintf(nextStrPtr, "\r\n%s,::\r\n", NETWORK_STATUS); |
| ocomeni | 95:290859010c8c | 601 | break; |
| ocomeni | 95:290859010c8c | 602 | } |
| ocomeni | 103:7b566b522427 | 603 | nextStrPtr += strlen(nextStrPtr) ; // progress to end of current string |
| ocomeni | 95:290859010c8c | 604 | } |
| ocomeni | 103:7b566b522427 | 605 | sprintf(nextStrPtr, "%s", UDDRP_WRITE_OK); |
| ocomeni | 95:290859010c8c | 606 | } |
| ocomeni | 95:290859010c8c | 607 | |
| ocomeni | 95:290859010c8c | 608 | |
| ocomeni | 95:290859010c8c | 609 | |
| ocomeni | 95:290859010c8c | 610 | void WiFiManager::getWiFiStatus(){ |
| ocomeni | 95:290859010c8c | 611 | |
| ocomeni | 95:290859010c8c | 612 | responseString = (char *) malloc(MAX_RESPONSE_STRING_LEN); |
| ocomeni | 95:290859010c8c | 613 | wifi_stat_id_t status_id; |
| ocomeni | 95:290859010c8c | 614 | char * nextStrPtr = responseString; |
| ocomeni | 95:290859010c8c | 615 | for(int i=0; i< NumWiFiStatus;i++){ |
| ocomeni | 95:290859010c8c | 616 | status_id = wifiStatusIds[i]; // get current status id |
| ocomeni | 95:290859010c8c | 617 | switch(status_id){ |
| ocomeni | 95:290859010c8c | 618 | case WIFI_SSID: |
| ocomeni | 95:290859010c8c | 619 | sprintf(nextStrPtr, "\r\n%s%d,%s\r\n", WIFI_NETWORK_STATUS, |
| ocomeni | 95:290859010c8c | 620 | status_id, |
| ocomeni | 95:290859010c8c | 621 | wifi_config.ssid); |
| ocomeni | 95:290859010c8c | 622 | break; |
| ocomeni | 95:290859010c8c | 623 | case WIFI_BSSID: |
| ocomeni | 95:290859010c8c | 624 | sprintf(nextStrPtr, "\r\n%s%d,%s\r\n", WIFI_NETWORK_STATUS, |
| ocomeni | 95:290859010c8c | 625 | status_id, |
| ocomeni | 95:290859010c8c | 626 | network->get_mac_address()); |
| ocomeni | 95:290859010c8c | 627 | break; |
| ocomeni | 95:290859010c8c | 628 | case WIFI__CURRENT_CHANNEL: |
| ocomeni | 95:290859010c8c | 629 | sprintf(nextStrPtr, "\r\n%s%d,%d\r\n", WIFI_NETWORK_STATUS, |
| ocomeni | 95:290859010c8c | 630 | status_id, |
| ocomeni | 95:290859010c8c | 631 | DEFAULT_WIFI_CHANNEL); |
| ocomeni | 95:290859010c8c | 632 | break; |
| ocomeni | 95:290859010c8c | 633 | case WIFI_STA_STATUS: |
| ocomeni | 95:290859010c8c | 634 | sprintf(nextStrPtr, "\r\n%s%d,%d\r\n", WIFI_NETWORK_STATUS, |
| ocomeni | 95:290859010c8c | 635 | status_id, |
| ocomeni | 95:290859010c8c | 636 | (uint8_t)is_connected); |
| ocomeni | 95:290859010c8c | 637 | break; |
| ocomeni | 95:290859010c8c | 638 | case WIFI_RSSI: |
| ocomeni | 95:290859010c8c | 639 | sprintf(nextStrPtr, "\r\n%s%d,%d\r\n", WIFI_NETWORK_STATUS, |
| ocomeni | 95:290859010c8c | 640 | status_id, |
| ocomeni | 95:290859010c8c | 641 | network->get_rssi()); |
| ocomeni | 95:290859010c8c | 642 | break; |
| ocomeni | 95:290859010c8c | 643 | default: |
| ocomeni | 95:290859010c8c | 644 | sprintf(nextStrPtr, "\r\n%s,::\r\n", WIFI_NETWORK_STATUS); |
| ocomeni | 95:290859010c8c | 645 | break; |
| ocomeni | 95:290859010c8c | 646 | } |
| ocomeni | 103:7b566b522427 | 647 | nextStrPtr += strlen(nextStrPtr) ; // progress to end of current string |
| ocomeni | 95:290859010c8c | 648 | } |
| ocomeni | 103:7b566b522427 | 649 | sprintf(nextStrPtr, "%s", UDDRP_WRITE_OK); |
| ocomeni | 95:290859010c8c | 650 | } |
| ocomeni | 95:290859010c8c | 651 | |
| ocomeni | 95:290859010c8c | 652 | |
| ocomeni | 81:637a87eb8170 | 653 | void WiFiManager::free_DataMsg() |
| ocomeni | 81:637a87eb8170 | 654 | { |
| ocomeni | 81:637a87eb8170 | 655 | // free memory after processing |
| ocomeni | 81:637a87eb8170 | 656 | _aT2WiFiDatamPool->free(data_msg); |
| ocomeni | 96:f5ed273881af | 657 | data_msg = NULL; |
| ocomeni | 81:637a87eb8170 | 658 | } |
| ocomeni | 81:637a87eb8170 | 659 | |
| ocomeni | 81:637a87eb8170 | 660 | |
| ocomeni | 88:7ffa053be662 | 661 | |
| ocomeni | 81:637a87eb8170 | 662 | void WiFiManager::status_callback(nsapi_event_t status, intptr_t param) |
| ocomeni | 81:637a87eb8170 | 663 | { |
| ocomeni | 105:e5ce023eee93 | 664 | dbg_printf(LOG, "[WIFI-MAN] about to call status_callback_event... \r\n"); |
| ocomeni | 98:65c2333a38b6 | 665 | _event_queue.call_in(50, this, &WiFiManager::status_callback_event, status, param); |
| ocomeni | 98:65c2333a38b6 | 666 | //status_callback_event(status, param); |
| ocomeni | 98:65c2333a38b6 | 667 | } |
| ocomeni | 98:65c2333a38b6 | 668 | void WiFiManager::status_callback_event(nsapi_event_t status, intptr_t param) |
| ocomeni | 98:65c2333a38b6 | 669 | { |
| ocomeni | 81:637a87eb8170 | 670 | //if (status == NSAPI_EVENT_CONNECTION_STATUS_CHANGE) { |
| ocomeni | 81:637a87eb8170 | 671 | //} |
| ocomeni | 81:637a87eb8170 | 672 | switch(param) { |
| ocomeni | 81:637a87eb8170 | 673 | case NSAPI_STATUS_LOCAL_UP: |
| ocomeni | 103:7b566b522427 | 674 | dbg_printf(LOG, "[WIFI-MAN] Local IP address set!\r\n"); |
| ocomeni | 103:7b566b522427 | 675 | dbg_printf(LOG, "[WIFI-MAN] IP address: %s\n", network->get_ip_address()); |
| ocomeni | 81:637a87eb8170 | 676 | break; |
| ocomeni | 81:637a87eb8170 | 677 | case NSAPI_STATUS_GLOBAL_UP: |
| ocomeni | 103:7b566b522427 | 678 | dbg_printf(LOG, "Global IP address set!\r\n"); |
| ocomeni | 103:7b566b522427 | 679 | dbg_printf(LOG, "[WIFI-MAN] IP address: %s\n", network->get_ip_address()); |
| ocomeni | 103:7b566b522427 | 680 | dbg_printf(LOG, "[WIFI-MAN] Connected to the network %s\n", wifi_config.ssid); |
| ocomeni | 95:290859010c8c | 681 | responseString = (char *) malloc(MAX_RESPONSE_STRING_LEN); |
| ocomeni | 95:290859010c8c | 682 | sprintf(responseString, "\r\n%s%d,%s,%d\r\n", WIFI_LINK_ENABLED, |
| ocomeni | 95:290859010c8c | 683 | WIFI_CHANNEL, |
| ocomeni | 95:290859010c8c | 684 | network->get_mac_address(), |
| ocomeni | 95:290859010c8c | 685 | DEFAULT_WIFI_CHANNEL); |
| ocomeni | 95:290859010c8c | 686 | |
| ocomeni | 81:637a87eb8170 | 687 | is_connected = true; |
| ocomeni | 104:11e9605093c9 | 688 | wifiBusy = 0; |
| ocomeni | 81:637a87eb8170 | 689 | break; |
| ocomeni | 81:637a87eb8170 | 690 | case NSAPI_STATUS_DISCONNECTED: |
| ocomeni | 103:7b566b522427 | 691 | dbg_printf(LOG, "No connection to network!\r\n"); |
| ocomeni | 103:7b566b522427 | 692 | dbg_printf(LOG, "\n [WIFI-MAN] No connection to network!\n"); |
| ocomeni | 81:637a87eb8170 | 693 | is_connected = false; |
| ocomeni | 81:637a87eb8170 | 694 | //queueATresponse(AT_DISCONNECT_RESP); |
| ocomeni | 81:637a87eb8170 | 695 | // attempt reconnection if always connected scheme is set |
| ocomeni | 81:637a87eb8170 | 696 | if(internet_config.connectionScheme == ALWAYS_CONNECTED) |
| ocomeni | 81:637a87eb8170 | 697 | { |
| ocomeni | 104:11e9605093c9 | 698 | wifiBusy = 1; |
| ocomeni | 81:637a87eb8170 | 699 | nsapi_error_t error; |
| ocomeni | 91:d6b6319ad681 | 700 | error = connect(); |
| ocomeni | 81:637a87eb8170 | 701 | queueATresponse(WIFI_RECONNECT_INFO); |
| ocomeni | 81:637a87eb8170 | 702 | } |
| ocomeni | 81:637a87eb8170 | 703 | break; |
| ocomeni | 81:637a87eb8170 | 704 | case NSAPI_STATUS_CONNECTING: |
| ocomeni | 103:7b566b522427 | 705 | dbg_printf(LOG, "Connecting to network!\r\n"); |
| ocomeni | 81:637a87eb8170 | 706 | break; |
| ocomeni | 81:637a87eb8170 | 707 | default: |
| ocomeni | 103:7b566b522427 | 708 | dbg_printf(LOG, "Not supported"); |
| ocomeni | 81:637a87eb8170 | 709 | break; |
| ocomeni | 81:637a87eb8170 | 710 | } |
| ocomeni | 81:637a87eb8170 | 711 | } |
| ocomeni | 81:637a87eb8170 | 712 | |
| ocomeni | 81:637a87eb8170 | 713 | |
| ocomeni | 81:637a87eb8170 | 714 | |
| ocomeni | 79:a2187bbfa407 | 715 | // NSAPI_STATUS_LOCAL_UP = 0, /*!< local IP address set */ |
| ocomeni | 79:a2187bbfa407 | 716 | // NSAPI_STATUS_GLOBAL_UP = 1, /*!< global IP address set */ |
| ocomeni | 79:a2187bbfa407 | 717 | // NSAPI_STATUS_DISCONNECTED = 2, /*!< no connection to network */ |
| ocomeni | 79:a2187bbfa407 | 718 | // NSAPI_STATUS_CONNECTING = 3, /*!< connecting to network */ |
| ocomeni | 79:a2187bbfa407 | 719 | // NSAPI_STATUS_ERROR_UNSUPPORTED = NSAPI_ERROR_UNSUPPORTED |
| ocomeni | 79:a2187bbfa407 | 720 | |
| ocomeni | 79:a2187bbfa407 | 721 | nsapi_error_t WiFiManager::connect() |
| ocomeni | 79:a2187bbfa407 | 722 | { |
| ocomeni | 79:a2187bbfa407 | 723 | nsapi_error_t error; |
| ocomeni | 103:7b566b522427 | 724 | dbg_printf(LOG, "\n [WIFI-MAN] About to connect to WiFi network\n"); |
| ocomeni | 81:637a87eb8170 | 725 | network->attach(callback(this, &WiFiManager::status_callback)); |
| ocomeni | 79:a2187bbfa407 | 726 | error = network->set_blocking(false); |
| ocomeni | 79:a2187bbfa407 | 727 | if(error) |
| ocomeni | 79:a2187bbfa407 | 728 | { |
| ocomeni | 103:7b566b522427 | 729 | dbg_printf(LOG, "\n [WIFI-MAN] Could not set non-blocking mode for Wifi -- aborting!! - \n"); |
| ocomeni | 79:a2187bbfa407 | 730 | return error; |
| ocomeni | 79:a2187bbfa407 | 731 | } |
| ocomeni | 103:7b566b522427 | 732 | dbg_printf(LOG, "[WIFI-MAN] Connecting to network ssid = %s passwd = %s security = %s \r\n", |
| ocomeni | 93:06e755a80187 | 733 | wifi_config.ssid, |
| ocomeni | 96:f5ed273881af | 734 | "****************", |
| ocomeni | 93:06e755a80187 | 735 | sec2str(wifi_config.security)); |
| ocomeni | 79:a2187bbfa407 | 736 | error = network->connect(wifi_config.ssid, |
| ocomeni | 79:a2187bbfa407 | 737 | wifi_config.pass, |
| ocomeni | 79:a2187bbfa407 | 738 | wifi_config.security); |
| ocomeni | 103:7b566b522427 | 739 | dbg_printf(LOG, "[WIFI-MAN] network->connect called. error = %d\r\n", error); |
| ocomeni | 81:637a87eb8170 | 740 | return error; |
| ocomeni | 79:a2187bbfa407 | 741 | } |
| ocomeni | 79:a2187bbfa407 | 742 | |
| ocomeni | 79:a2187bbfa407 | 743 | |
| ocomeni | 99:05398b3184f8 | 744 | void WiFiManager::gethostbyname_callback(nsapi_error_t result, SocketAddress *address) |
| ocomeni | 99:05398b3184f8 | 745 | { |
| ocomeni | 103:7b566b522427 | 746 | dbg_printf(LOG, "gethostbyname_callback called... result = %d \r\n", result); |
| ocomeni | 107:f1a83fd41b17 | 747 | print_memory_info(); |
| ocomeni | 107:f1a83fd41b17 | 748 | responseBytes = new uint8_t[HOSTNAME_RESPONSE_LEN]; //malloc(HOSTNAME_RESPONSE_LEN); |
| ocomeni | 99:05398b3184f8 | 749 | int i = 0; |
| ocomeni | 99:05398b3184f8 | 750 | responseBytes[i++] = IPv4_CONNECTION; // connect type IPv4 |
| ocomeni | 99:05398b3184f8 | 751 | responseBytes[i++] = TCP_PROTOCOL; // Protocol = TCP |
| ocomeni | 107:f1a83fd41b17 | 752 | if(is_connected && result>=0) |
| ocomeni | 99:05398b3184f8 | 753 | { |
| ocomeni | 104:11e9605093c9 | 754 | memcpy(&responseBytes[i], address->get_ip_bytes(), 4); // remote IPv4 address |
| ocomeni | 104:11e9605093c9 | 755 | strcpy(internet_config.remote_IPv4Address, address->get_ip_address()); |
| ocomeni | 104:11e9605093c9 | 756 | i +=4; |
| ocomeni | 104:11e9605093c9 | 757 | uint16_t port = address->get_port(); |
| ocomeni | 104:11e9605093c9 | 758 | internet_config.remote_port = port; |
| ocomeni | 104:11e9605093c9 | 759 | memcpy(&responseBytes[i], &port, 2); // remote IPv4 port # |
| ocomeni | 104:11e9605093c9 | 760 | i +=2; |
| ocomeni | 99:05398b3184f8 | 761 | // local IPv4 address |
| ocomeni | 99:05398b3184f8 | 762 | int ipAddr[4]; |
| ocomeni | 100:80ef4bc31b7a | 763 | strcpy(internet_config.local_IPv4Address, network->get_ip_address()); |
| ocomeni | 100:80ef4bc31b7a | 764 | sscanf(internet_config.local_IPv4Address, "%d.%d.%d.%d", &ipAddr[0], &ipAddr[1], |
| ocomeni | 100:80ef4bc31b7a | 765 | &ipAddr[2], &ipAddr[3]); |
| ocomeni | 99:05398b3184f8 | 766 | responseBytes[i++] = (uint8_t) ipAddr[0]; |
| ocomeni | 99:05398b3184f8 | 767 | responseBytes[i++] = (uint8_t) ipAddr[1]; |
| ocomeni | 99:05398b3184f8 | 768 | responseBytes[i++] = (uint8_t) ipAddr[2]; |
| ocomeni | 99:05398b3184f8 | 769 | responseBytes[i++] = (uint8_t) ipAddr[3]; |
| ocomeni | 99:05398b3184f8 | 770 | // local port number |
| ocomeni | 99:05398b3184f8 | 771 | responseBytes[i++] = 0; |
| ocomeni | 99:05398b3184f8 | 772 | responseBytes[i] = 0; |
| ocomeni | 99:05398b3184f8 | 773 | printBufferInHex(responseBytes, HOSTNAME_RESPONSE_LEN); |
| ocomeni | 107:f1a83fd41b17 | 774 | _event_queue.call_in(10, this, &WiFiManager::sendATresponseBytes, |
| ocomeni | 107:f1a83fd41b17 | 775 | CONNECT_EVENT, HOSTNAME_RESPONSE_LEN); |
| ocomeni | 99:05398b3184f8 | 776 | } |
| ocomeni | 99:05398b3184f8 | 777 | else |
| ocomeni | 99:05398b3184f8 | 778 | { |
| ocomeni | 99:05398b3184f8 | 779 | // if unconnected set ip and port to zeroes |
| ocomeni | 99:05398b3184f8 | 780 | memset(&responseBytes[i], 0x00, 6); |
| ocomeni | 107:f1a83fd41b17 | 781 | delete responseBytes; |
| ocomeni | 107:f1a83fd41b17 | 782 | dbg_printf(LOG, "\r\nHOSTNAME TRANSLATION FAILURE : error code = %d \r\n", result); |
| ocomeni | 107:f1a83fd41b17 | 783 | if(responseString == NULL) |
| ocomeni | 107:f1a83fd41b17 | 784 | { |
| ocomeni | 107:f1a83fd41b17 | 785 | //responseString = (char *) malloc(100); |
| ocomeni | 107:f1a83fd41b17 | 786 | //sprintf(responseString, "\r\nHOSTNAME TRANSLATION FAILURE : error code = %d \r\n", result); |
| ocomeni | 107:f1a83fd41b17 | 787 | //sendATresponseString(AT_EVENT); |
| ocomeni | 107:f1a83fd41b17 | 788 | } |
| ocomeni | 107:f1a83fd41b17 | 789 | } |
| ocomeni | 104:11e9605093c9 | 790 | wifiBusy = 0; |
| ocomeni | 107:f1a83fd41b17 | 791 | backgroundTaskCompleted = true; |
| ocomeni | 104:11e9605093c9 | 792 | |
| ocomeni | 99:05398b3184f8 | 793 | } |
| ocomeni | 99:05398b3184f8 | 794 | |
| ocomeni | 100:80ef4bc31b7a | 795 | void WiFiManager::sendSocketConnectionEvent() |
| ocomeni | 100:80ef4bc31b7a | 796 | { |
| ocomeni | 100:80ef4bc31b7a | 797 | // |
| ocomeni | 100:80ef4bc31b7a | 798 | responseString = (char *) malloc(MAX_RESPONSE_STRING_LEN); |
| ocomeni | 100:80ef4bc31b7a | 799 | sprintf(responseString, "\r\n%s%d,%d,%d,%s,%d,%s,%d\r\n", PEER_CONNECTED_URC, |
| ocomeni | 100:80ef4bc31b7a | 800 | IP_PEER_HANDLE, |
| ocomeni | 100:80ef4bc31b7a | 801 | IPv4_CONNECTION, |
| ocomeni | 100:80ef4bc31b7a | 802 | TCP_PROTOCOL, |
| ocomeni | 100:80ef4bc31b7a | 803 | internet_config.local_IPv4Address, |
| ocomeni | 100:80ef4bc31b7a | 804 | DEFAULT_LOCAL_PORT, |
| ocomeni | 100:80ef4bc31b7a | 805 | internet_config.remote_IPv4Address, |
| ocomeni | 100:80ef4bc31b7a | 806 | internet_config.remote_port); |
| ocomeni | 100:80ef4bc31b7a | 807 | sendATresponseString(AT_EVENT); |
| ocomeni | 100:80ef4bc31b7a | 808 | } |
| ocomeni | 100:80ef4bc31b7a | 809 | |
| ocomeni | 99:05398b3184f8 | 810 | |
| ocomeni | 79:a2187bbfa407 | 811 | nsapi_error_t WiFiManager::disconnect() |
| ocomeni | 78:07bb86e3ce14 | 812 | { |
| ocomeni | 79:a2187bbfa407 | 813 | nsapi_error_t error; |
| ocomeni | 79:a2187bbfa407 | 814 | error = network->disconnect(); |
| ocomeni | 79:a2187bbfa407 | 815 | return error; |
| ocomeni | 78:07bb86e3ce14 | 816 | } |
| ocomeni | 79:a2187bbfa407 | 817 | |
| ocomeni | 98:65c2333a38b6 | 818 | #define MIX_HDR_AND_BODY |
| ocomeni | 88:7ffa053be662 | 819 | void WiFiManager::sendResponseDownloadData(at_cmd_resp_t at_cmd, const uint8_t * buf, int bufLen) |
| ocomeni | 90:ed0267eca7b5 | 820 | { |
| ocomeni | 90:ed0267eca7b5 | 821 | |
| ocomeni | 103:7b566b522427 | 822 | //dbg_printf(LOG, "before call to new at_data_msg_t \n"); |
| ocomeni | 98:65c2333a38b6 | 823 | //print_memory_info(); |
| ocomeni | 88:7ffa053be662 | 824 | at_data_resp = new at_data_msg_t; |
| ocomeni | 103:7b566b522427 | 825 | //dbg_printf(LOG, "after call to new at_data_msg_t \n"); |
| ocomeni | 98:65c2333a38b6 | 826 | //print_memory_info(); |
| ocomeni | 88:7ffa053be662 | 827 | at_data_resp->at_resp = at_cmd; |
| ocomeni | 88:7ffa053be662 | 828 | size_t bufSize = sizeof(at_data_resp->buffer); |
| ocomeni | 88:7ffa053be662 | 829 | int pos = 0; |
| ocomeni | 88:7ffa053be662 | 830 | at_data_resp->dataLen = 0; |
| ocomeni | 88:7ffa053be662 | 831 | bool queueResult = true; |
| ocomeni | 90:ed0267eca7b5 | 832 | int hdrLen = 0; |
| ocomeni | 94:fb4414aff957 | 833 | int wait_count = 0; |
| ocomeni | 88:7ffa053be662 | 834 | do { |
| ocomeni | 94:fb4414aff957 | 835 | if(!queueResult){ |
| ocomeni | 94:fb4414aff957 | 836 | wait_count++; |
| ocomeni | 103:7b566b522427 | 837 | dbg_printf(LOG, "[WIFI-MAN] ATCMD Queue full waiting %d ms so far...\n", wait_count*10); |
| ocomeni | 94:fb4414aff957 | 838 | wait_ms(10); |
| ocomeni | 90:ed0267eca7b5 | 839 | } |
| ocomeni | 90:ed0267eca7b5 | 840 | else { |
| ocomeni | 98:65c2333a38b6 | 841 | if(http_response_hdr_sent == false && chunkNum==1){ // only do this for first chunk |
| ocomeni | 102:9748f290a1a5 | 842 | bool status = copyResponseHdr2Queue(buf); |
| ocomeni | 98:65c2333a38b6 | 843 | if(status == true){ |
| ocomeni | 103:7b566b522427 | 844 | dbg_printf(LOG, "[WIFI-MAN] Http Response header copied to response buffer [bytes = %d] \r\n",at_data_resp->dataLen); |
| ocomeni | 98:65c2333a38b6 | 845 | hdrLen = at_data_resp->dataLen; |
| ocomeni | 98:65c2333a38b6 | 846 | http_response_hdr_sent = true; |
| ocomeni | 98:65c2333a38b6 | 847 | } |
| ocomeni | 98:65c2333a38b6 | 848 | else { |
| ocomeni | 103:7b566b522427 | 849 | dbg_printf(LOG, "[WIFI-MAN] Http Response header copy failed\r\n"); |
| ocomeni | 98:65c2333a38b6 | 850 | } |
| ocomeni | 90:ed0267eca7b5 | 851 | } |
| ocomeni | 94:fb4414aff957 | 852 | int cpyLen = (bufLen - pos) > bufSize? bufSize : (bufLen - pos) ; |
| ocomeni | 103:7b566b522427 | 853 | dbg_printf(LOG, "[WIFI-MAN] Http Response body [bytes = %d] \r\n",cpyLen); |
| ocomeni | 90:ed0267eca7b5 | 854 | at_data_resp->dataLen += cpyLen; |
| ocomeni | 90:ed0267eca7b5 | 855 | memcpy(&at_data_resp->buffer[hdrLen], &buf[pos], cpyLen); |
| ocomeni | 103:7b566b522427 | 856 | dbg_printf(LOG, "[WIFI-MAN] Http Response header and body copied to response buffer [bytes = %d] \r\n",at_data_resp->dataLen); |
| ocomeni | 90:ed0267eca7b5 | 857 | } |
| ocomeni | 88:7ffa053be662 | 858 | queueResult = queueWiFiDataResponse(*at_data_resp); |
| ocomeni | 90:ed0267eca7b5 | 859 | if(queueResult){ |
| ocomeni | 90:ed0267eca7b5 | 860 | pos+= at_data_resp->dataLen; |
| ocomeni | 90:ed0267eca7b5 | 861 | at_data_resp->dataLen = 0; |
| ocomeni | 90:ed0267eca7b5 | 862 | hdrLen = 0; |
| ocomeni | 90:ed0267eca7b5 | 863 | } |
| ocomeni | 88:7ffa053be662 | 864 | }while(queueResult == false || pos < bufLen); |
| ocomeni | 103:7b566b522427 | 865 | dbg_printf(LOG, "[WIFI-MAN] response data queued - deleting data memory\r\n"); |
| ocomeni | 88:7ffa053be662 | 866 | delete at_data_resp; |
| ocomeni | 100:80ef4bc31b7a | 867 | at_data_resp = NULL; |
| ocomeni | 88:7ffa053be662 | 868 | } |
| ocomeni | 79:a2187bbfa407 | 869 | |
| ocomeni | 102:9748f290a1a5 | 870 | bool WiFiManager::copyResponseHdr2Queue(const uint8_t * buf) |
| ocomeni | 90:ed0267eca7b5 | 871 | { |
| ocomeni | 102:9748f290a1a5 | 872 | const char *arbPtr = (const char *)buf - MAX_HTTP_HDR_LEN; |
| ocomeni | 102:9748f290a1a5 | 873 | const char *hdrPtr; |
| ocomeni | 102:9748f290a1a5 | 874 | int len; |
| ocomeni | 102:9748f290a1a5 | 875 | bool hdrFound = false; |
| ocomeni | 102:9748f290a1a5 | 876 | int i; |
| ocomeni | 102:9748f290a1a5 | 877 | for(i=0;i<(MAX_HTTP_HDR_LEN-50);i++) |
| ocomeni | 101:1cfd468e5009 | 878 | { |
| ocomeni | 102:9748f290a1a5 | 879 | // get location of start of the http header string |
| ocomeni | 102:9748f290a1a5 | 880 | hdrPtr = strstr(&arbPtr[i], HTTP_HEADER_START_LINE); |
| ocomeni | 102:9748f290a1a5 | 881 | len = strlen(HTTP_HEADER_START_LINE); |
| ocomeni | 102:9748f290a1a5 | 882 | // validate that header string |
| ocomeni | 102:9748f290a1a5 | 883 | if((strstr(&arbPtr[i+len], HTTP_HEADER_START_LINE) == NULL || |
| ocomeni | 102:9748f290a1a5 | 884 | (strstr(&arbPtr[i+len], HTTP_HEADER_START_LINE) > (const char*)buf)) && // |
| ocomeni | 102:9748f290a1a5 | 885 | strstr(&arbPtr[i+len], HTTP_HEADER_CONTENT_TYPE) != NULL && |
| ocomeni | 102:9748f290a1a5 | 886 | strstr(&arbPtr[i+len], HTTP_HEADER_CONTENT_LEN) != NULL && |
| ocomeni | 102:9748f290a1a5 | 887 | hdrPtr != NULL) |
| ocomeni | 102:9748f290a1a5 | 888 | { |
| ocomeni | 102:9748f290a1a5 | 889 | hdrFound = true; |
| ocomeni | 102:9748f290a1a5 | 890 | break; |
| ocomeni | 102:9748f290a1a5 | 891 | } |
| ocomeni | 101:1cfd468e5009 | 892 | } |
| ocomeni | 102:9748f290a1a5 | 893 | // calculate header length |
| ocomeni | 102:9748f290a1a5 | 894 | int hdrLen = (const char*) buf -hdrPtr; |
| ocomeni | 102:9748f290a1a5 | 895 | // copy header |
| ocomeni | 102:9748f290a1a5 | 896 | memcpy(at_data_resp->buffer, (const uint8_t *) hdrPtr, hdrLen); |
| ocomeni | 103:7b566b522427 | 897 | dbg_printf(LOG, "[i = %d] This is the header\r\n%s\r\n", i, hdrPtr); |
| ocomeni | 102:9748f290a1a5 | 898 | if(hdrFound == false) |
| ocomeni | 100:80ef4bc31b7a | 899 | { |
| ocomeni | 103:7b566b522427 | 900 | dbg_printf(LOG, "[WIFI-MAN] copy failed: HTTP header not found!!\r\n"); |
| ocomeni | 100:80ef4bc31b7a | 901 | return false; |
| ocomeni | 100:80ef4bc31b7a | 902 | } |
| ocomeni | 102:9748f290a1a5 | 903 | at_data_resp->dataLen = hdrLen; |
| ocomeni | 98:65c2333a38b6 | 904 | return true; |
| ocomeni | 90:ed0267eca7b5 | 905 | } |
| ocomeni | 90:ed0267eca7b5 | 906 | |
| ocomeni | 84:7c7add00f4bf | 907 | void WiFiManager::return_response(HttpResponse* res) { |
| ocomeni | 84:7c7add00f4bf | 908 | |
| ocomeni | 88:7ffa053be662 | 909 | at_data_resp = new at_data_msg_t; |
| ocomeni | 87:99b37d26ff2a | 910 | int numChars = 0; |
| ocomeni | 87:99b37d26ff2a | 911 | // create message pointer for response header generation |
| ocomeni | 88:7ffa053be662 | 912 | char * msgPtr = (char *)at_data_resp->buffer; |
| ocomeni | 87:99b37d26ff2a | 913 | // do status line |
| ocomeni | 87:99b37d26ff2a | 914 | numChars = sprintf(msgPtr, "HTTP/1.1 %d %s\r\n", res->get_status_code(), res->get_status_message().c_str()); |
| ocomeni | 87:99b37d26ff2a | 915 | msgPtr += numChars; |
| ocomeni | 84:7c7add00f4bf | 916 | for (size_t ix = 0; ix < res->get_headers_length(); ix++) { |
| ocomeni | 87:99b37d26ff2a | 917 | numChars = sprintf(msgPtr, "%s: %s\r\n", |
| ocomeni | 87:99b37d26ff2a | 918 | res->get_headers_fields()[ix]->c_str(), |
| ocomeni | 87:99b37d26ff2a | 919 | res->get_headers_values()[ix]->c_str()); |
| ocomeni | 87:99b37d26ff2a | 920 | msgPtr += numChars; |
| ocomeni | 84:7c7add00f4bf | 921 | } |
| ocomeni | 87:99b37d26ff2a | 922 | numChars = sprintf(msgPtr, "\r\n\r\n"); |
| ocomeni | 87:99b37d26ff2a | 923 | msgPtr += numChars; |
| ocomeni | 87:99b37d26ff2a | 924 | // print out generated header |
| ocomeni | 103:7b566b522427 | 925 | dbg_printf(LOG, "[WiFi MAN] generated response header:\n"); |
| ocomeni | 103:7b566b522427 | 926 | dbg_printf(LOG, "%s\r\n", (char *)at_data_resp->buffer); |
| ocomeni | 90:ed0267eca7b5 | 927 | // calculate header length |
| ocomeni | 89:45f6db09a76d | 928 | at_data_resp->dataLen = (msgPtr - (char *)at_data_resp->buffer); |
| ocomeni | 84:7c7add00f4bf | 929 | |
| ocomeni | 90:ed0267eca7b5 | 930 | // package and send on wifi data queue |
| ocomeni | 88:7ffa053be662 | 931 | at_data_resp->at_resp = AT_HTTPS_RESP; |
| ocomeni | 89:45f6db09a76d | 932 | bool queueResult = true; |
| ocomeni | 89:45f6db09a76d | 933 | int wait_count = 0; |
| ocomeni | 89:45f6db09a76d | 934 | do |
| ocomeni | 89:45f6db09a76d | 935 | { |
| ocomeni | 89:45f6db09a76d | 936 | if(!queueResult){ |
| ocomeni | 89:45f6db09a76d | 937 | wait_count++; |
| ocomeni | 103:7b566b522427 | 938 | dbg_printf(LOG, "ATCMD Queue full waiting %d ms so far...\n", wait_count*10); |
| ocomeni | 89:45f6db09a76d | 939 | wait_ms(10); |
| ocomeni | 89:45f6db09a76d | 940 | } |
| ocomeni | 89:45f6db09a76d | 941 | queueResult = queueWiFiDataResponse(*at_data_resp); |
| ocomeni | 89:45f6db09a76d | 942 | }while(queueResult == false); |
| ocomeni | 88:7ffa053be662 | 943 | delete at_data_resp; |
| ocomeni | 100:80ef4bc31b7a | 944 | at_data_resp = NULL; |
| ocomeni | 84:7c7add00f4bf | 945 | } |
| ocomeni | 90:ed0267eca7b5 | 946 | |
| ocomeni | 90:ed0267eca7b5 | 947 | |
| ocomeni | 104:11e9605093c9 | 948 | void WiFiManager::printBufferInHex(const uint8_t *buf, int pLen) |
| ocomeni | 90:ed0267eca7b5 | 949 | { |
| ocomeni | 104:11e9605093c9 | 950 | //for(int i =0;i<pLen;i++){ |
| ocomeni | 104:11e9605093c9 | 951 | // if(i%8==0) dbg_printf(LOG, "\n[%3d]",i); |
| ocomeni | 104:11e9605093c9 | 952 | // dbg_printf(LOG, "%02x ", buf[i]); |
| ocomeni | 104:11e9605093c9 | 953 | //} |
| ocomeni | 104:11e9605093c9 | 954 | //dbg_printf(LOG, "\n"); |
| ocomeni | 104:11e9605093c9 | 955 | print_debug_hex(buf, pLen); |
| ocomeni | 90:ed0267eca7b5 | 956 | } |
| ocomeni | 90:ed0267eca7b5 | 957 | |
| ocomeni | 88:7ffa053be662 | 958 | //#define TRY_PRINTF |
| ocomeni | 84:7c7add00f4bf | 959 | |
| ocomeni | 90:ed0267eca7b5 | 960 | void WiFiManager::body_callback(const char *at, uint32_t length) { |
| ocomeni | 103:7b566b522427 | 961 | dbg_printf(LOG, "\n Chunked response: Chunk %d : Total Bytes = %d\n", chunkNum , length); |
| ocomeni | 84:7c7add00f4bf | 962 | chunkNum++; |
| ocomeni | 105:e5ce023eee93 | 963 | dbg_printf(LOG, "This is the start when response is excluded\r\n%s\r\nend of packet \r\n", at); |
| ocomeni | 102:9748f290a1a5 | 964 | if(http_response == NULL) |
| ocomeni | 102:9748f290a1a5 | 965 | { |
| ocomeni | 103:7b566b522427 | 966 | dbg_printf(LOG, "[WIFI-MAN] response pointer NULL!!\r\n"); |
| ocomeni | 102:9748f290a1a5 | 967 | } |
| ocomeni | 102:9748f290a1a5 | 968 | else |
| ocomeni | 102:9748f290a1a5 | 969 | { |
| ocomeni | 103:7b566b522427 | 970 | dbg_printf(LOG, "[WIFI-MAN] response pointer NULL not!!\r\n"); |
| ocomeni | 102:9748f290a1a5 | 971 | } |
| ocomeni | 104:11e9605093c9 | 972 | if(responseString == NULL && chunkNum==1) |
| ocomeni | 104:11e9605093c9 | 973 | { |
| ocomeni | 104:11e9605093c9 | 974 | responseString = (char *) malloc(100); |
| ocomeni | 104:11e9605093c9 | 975 | sprintf(responseString, "\r\nHTTPS BODY CALLBACK RECEIVED\r\n"); |
| ocomeni | 104:11e9605093c9 | 976 | sendATresponseString(AT_EVENT); |
| ocomeni | 104:11e9605093c9 | 977 | } |
| ocomeni | 89:45f6db09a76d | 978 | sendResponseDownloadData(AT_HTTPS_RESP_DOWNLOAD, (uint8_t *)at, length); |
| ocomeni | 84:7c7add00f4bf | 979 | } |
| ocomeni | 84:7c7add00f4bf | 980 | |
| ocomeni | 105:e5ce023eee93 | 981 | //#define ENABLE_MBED_TRACE |
| ocomeni | 88:7ffa053be662 | 982 | bool WiFiManager::createTLSconnection(const char * hostName) |
| ocomeni | 88:7ffa053be662 | 983 | { |
| ocomeni | 93:06e755a80187 | 984 | #ifdef ENABLE_MBED_TRACE |
| ocomeni | 93:06e755a80187 | 985 | mbed_trace_init(); |
| ocomeni | 93:06e755a80187 | 986 | #endif |
| ocomeni | 88:7ffa053be662 | 987 | socket = new TLSSocket(); |
| ocomeni | 105:e5ce023eee93 | 988 | // set a 5 second timeout |
| ocomeni | 105:e5ce023eee93 | 989 | //socket->set_timeout(5000); |
| ocomeni | 105:e5ce023eee93 | 990 | //socket->set_blocking(false); |
| ocomeni | 88:7ffa053be662 | 991 | nsapi_error_t r; |
| ocomeni | 88:7ffa053be662 | 992 | // make sure to check the return values for the calls below (should return NSAPI_ERROR_OK) |
| ocomeni | 88:7ffa053be662 | 993 | r = socket->open(network); |
| ocomeni | 88:7ffa053be662 | 994 | if(r != NSAPI_ERROR_OK) |
| ocomeni | 88:7ffa053be662 | 995 | { |
| ocomeni | 103:7b566b522427 | 996 | dbg_printf(LOG, "TLS open failed!!\n"); |
| ocomeni | 88:7ffa053be662 | 997 | return false; |
| ocomeni | 88:7ffa053be662 | 998 | } |
| ocomeni | 103:7b566b522427 | 999 | dbg_printf(LOG, "TLS open passed!!\n"); |
| ocomeni | 88:7ffa053be662 | 1000 | r = socket->set_root_ca_cert(SSL_CA_PEM); |
| ocomeni | 88:7ffa053be662 | 1001 | if(r != NSAPI_ERROR_OK) |
| ocomeni | 88:7ffa053be662 | 1002 | { |
| ocomeni | 103:7b566b522427 | 1003 | dbg_printf(LOG, "TLS set_root_ca_cert failed!!\n"); |
| ocomeni | 98:65c2333a38b6 | 1004 | socket->close(); |
| ocomeni | 103:7b566b522427 | 1005 | dbg_printf(LOG, "closing TLS socket!!\n"); |
| ocomeni | 88:7ffa053be662 | 1006 | return false; |
| ocomeni | 88:7ffa053be662 | 1007 | } |
| ocomeni | 103:7b566b522427 | 1008 | dbg_printf(LOG, "TLS set_root_ca_cert passed!!\n"); |
| ocomeni | 88:7ffa053be662 | 1009 | r = socket->connect(hostName, 443); |
| ocomeni | 88:7ffa053be662 | 1010 | if(r != NSAPI_ERROR_OK) |
| ocomeni | 88:7ffa053be662 | 1011 | { |
| ocomeni | 93:06e755a80187 | 1012 | char errstr[100]; |
| ocomeni | 93:06e755a80187 | 1013 | mbedtls_strerror(r, errstr, 100); |
| ocomeni | 105:e5ce023eee93 | 1014 | dbg_printf(LOG, "TLS connect failed (err = %d) for hostname '%s' -- ERROR = %s !!\n", r, hostName, errstr); |
| ocomeni | 105:e5ce023eee93 | 1015 | //printf("TLS connect failed for hostname %s -- ERROR = %s !!\n", hostName, errstr); |
| ocomeni | 93:06e755a80187 | 1016 | socket->close(); |
| ocomeni | 88:7ffa053be662 | 1017 | return false; |
| ocomeni | 88:7ffa053be662 | 1018 | } |
| ocomeni | 103:7b566b522427 | 1019 | dbg_printf(LOG, "TLS connection successful for https site : %s\n", hostName); |
| ocomeni | 88:7ffa053be662 | 1020 | return true; |
| ocomeni | 88:7ffa053be662 | 1021 | } |
| ocomeni | 100:80ef4bc31b7a | 1022 | |
| ocomeni | 100:80ef4bc31b7a | 1023 | |
| ocomeni | 100:80ef4bc31b7a | 1024 | void WiFiManager::updateRemotePeerDetails() |
| ocomeni | 100:80ef4bc31b7a | 1025 | { |
| ocomeni | 103:7b566b522427 | 1026 | dbg_printf(LOG, "Updating internet_config... \r\n"); |
| ocomeni | 100:80ef4bc31b7a | 1027 | nsapi_error_t error; |
| ocomeni | 100:80ef4bc31b7a | 1028 | SocketAddress * address = new SocketAddress; |
| ocomeni | 104:11e9605093c9 | 1029 | error = socket->getpeername(address); |
| ocomeni | 104:11e9605093c9 | 1030 | if(error>=0) |
| ocomeni | 104:11e9605093c9 | 1031 | { |
| ocomeni | 104:11e9605093c9 | 1032 | strcpy(internet_config.remote_IPv4Address, address->get_ip_address()); |
| ocomeni | 104:11e9605093c9 | 1033 | uint16_t port = address->get_port(); |
| ocomeni | 104:11e9605093c9 | 1034 | internet_config.remote_port = port; |
| ocomeni | 104:11e9605093c9 | 1035 | } |
| ocomeni | 104:11e9605093c9 | 1036 | else |
| ocomeni | 104:11e9605093c9 | 1037 | { |
| ocomeni | 104:11e9605093c9 | 1038 | strcpy(internet_config.remote_IPv4Address, ""); |
| ocomeni | 104:11e9605093c9 | 1039 | internet_config.remote_port = 0; |
| ocomeni | 104:11e9605093c9 | 1040 | } |
| ocomeni | 100:80ef4bc31b7a | 1041 | delete address; |
| ocomeni | 100:80ef4bc31b7a | 1042 | } |
| ocomeni | 100:80ef4bc31b7a | 1043 | |
| ocomeni | 105:e5ce023eee93 | 1044 | |
| ocomeni | 105:e5ce023eee93 | 1045 | void WiFiManager::sendDebugMessage() |
| ocomeni | 105:e5ce023eee93 | 1046 | { |
| ocomeni | 107:f1a83fd41b17 | 1047 | #ifdef SEND_HTTPS_DEBUG_MESSAGES |
| ocomeni | 105:e5ce023eee93 | 1048 | sendATresponseString(AT_EVENT); |
| ocomeni | 105:e5ce023eee93 | 1049 | wait_ms(100); |
| ocomeni | 107:f1a83fd41b17 | 1050 | #else |
| ocomeni | 107:f1a83fd41b17 | 1051 | free(responseString); |
| ocomeni | 107:f1a83fd41b17 | 1052 | #endif |
| ocomeni | 105:e5ce023eee93 | 1053 | } |
| ocomeni | 88:7ffa053be662 | 1054 | #define TESTING_HTTPS |
| ocomeni | 98:65c2333a38b6 | 1055 | |
| ocomeni | 96:f5ed273881af | 1056 | //#define DONT_USE_TLS_SOCKET |
| ocomeni | 98:65c2333a38b6 | 1057 | bool WiFiManager::createHttpsRequest() |
| ocomeni | 79:a2187bbfa407 | 1058 | { |
| ocomeni | 106:e1f04c3d0647 | 1059 | int starttime; |
| ocomeni | 106:e1f04c3d0647 | 1060 | int stoptime; |
| ocomeni | 87:99b37d26ff2a | 1061 | // reset chunk #; |
| ocomeni | 87:99b37d26ff2a | 1062 | chunkNum = 0; |
| ocomeni | 96:f5ed273881af | 1063 | #ifdef MIX_HDR_AND_BODY |
| ocomeni | 90:ed0267eca7b5 | 1064 | http_response_hdr_sent = false; |
| ocomeni | 96:f5ed273881af | 1065 | #else |
| ocomeni | 96:f5ed273881af | 1066 | http_response_hdr_sent = true; |
| ocomeni | 96:f5ed273881af | 1067 | #endif |
| ocomeni | 103:7b566b522427 | 1068 | dbg_printf(LOG, "\n[WIFI MAN] Http Request received:\n"); |
| ocomeni | 84:7c7add00f4bf | 1069 | http_req_cfg = (http_request_t *) data_msg->buffer; |
| ocomeni | 105:e5ce023eee93 | 1070 | #ifdef FULL_DEBUG_ENABLED |
| ocomeni | 103:7b566b522427 | 1071 | dbg_printf(LOG, "\n[WIFI MAN] uri = %s\n", http_req_cfg->request_URI); |
| ocomeni | 103:7b566b522427 | 1072 | dbg_printf(LOG, "\n[WIFI MAN] internet cfg url = %s\n", internet_config.url); |
| ocomeni | 105:e5ce023eee93 | 1073 | #endif |
| ocomeni | 87:99b37d26ff2a | 1074 | char full_url[100]; |
| ocomeni | 88:7ffa053be662 | 1075 | char host[60] ; |
| ocomeni | 87:99b37d26ff2a | 1076 | strncpy(full_url,internet_config.url, strlen(internet_config.url)+1); |
| ocomeni | 90:ed0267eca7b5 | 1077 | strncpy(host,http_req_cfg->hostName, strlen(http_req_cfg->hostName)+1); |
| ocomeni | 90:ed0267eca7b5 | 1078 | strncat(full_url, http_req_cfg->request_URI, strlen(http_req_cfg->request_URI)+1); |
| ocomeni | 105:e5ce023eee93 | 1079 | #ifdef FULL_DEBUG_ENABLED |
| ocomeni | 103:7b566b522427 | 1080 | dbg_printf(LOG, "\n[WIFI MAN] server url+uri = %s\n", full_url); |
| ocomeni | 103:7b566b522427 | 1081 | dbg_printf(LOG, "\n[WIFI MAN] Host = %s\n", http_req_cfg->hostName); |
| ocomeni | 103:7b566b522427 | 1082 | dbg_printf(LOG, "\n[WIFI MAN] Accept = %s\n", http_req_cfg->AcceptVal); |
| ocomeni | 103:7b566b522427 | 1083 | dbg_printf(LOG, "\n[WIFI MAN] Content-Type = %s\n", http_req_cfg->contentType); |
| ocomeni | 103:7b566b522427 | 1084 | dbg_printf(LOG, "\n[WIFI MAN] contentLenstr = %s\n", http_req_cfg->contentLen); |
| ocomeni | 105:e5ce023eee93 | 1085 | #endif |
| ocomeni | 84:7c7add00f4bf | 1086 | |
| ocomeni | 84:7c7add00f4bf | 1087 | int bodyLen; |
| ocomeni | 90:ed0267eca7b5 | 1088 | sscanf(http_req_cfg->contentLen, "%d", &bodyLen); |
| ocomeni | 105:e5ce023eee93 | 1089 | #ifdef FULL_DEBUG_ENABLED |
| ocomeni | 103:7b566b522427 | 1090 | dbg_printf(LOG, "contenLenstr = %s bodyLen = %d\n", http_req_cfg->contentLen, bodyLen); |
| ocomeni | 90:ed0267eca7b5 | 1091 | if(bodyLen > 10){ |
| ocomeni | 103:7b566b522427 | 1092 | dbg_printf(LOG, "\n [WIFI MAN] Message Body:\n"); |
| ocomeni | 90:ed0267eca7b5 | 1093 | printBufferInHex(http_req_cfg->body, bodyLen); |
| ocomeni | 90:ed0267eca7b5 | 1094 | } |
| ocomeni | 105:e5ce023eee93 | 1095 | #endif |
| ocomeni | 87:99b37d26ff2a | 1096 | if(strstr(internet_config.url, "http:")!=NULL) // http request |
| ocomeni | 87:99b37d26ff2a | 1097 | { |
| ocomeni | 87:99b37d26ff2a | 1098 | http_request = new HttpRequest(network, |
| ocomeni | 90:ed0267eca7b5 | 1099 | http_req_cfg->method, |
| ocomeni | 90:ed0267eca7b5 | 1100 | full_url, |
| ocomeni | 90:ed0267eca7b5 | 1101 | callback(this, &WiFiManager::body_callback)); |
| ocomeni | 87:99b37d26ff2a | 1102 | setHttpHeader("Host", http_req_cfg->hostName); |
| ocomeni | 87:99b37d26ff2a | 1103 | setHttpHeader("Accept", http_req_cfg->AcceptVal); |
| ocomeni | 105:e5ce023eee93 | 1104 | //dbg_printf(LOG, "http_req_cfg->method = %d\n", http_req_cfg->method); |
| ocomeni | 88:7ffa053be662 | 1105 | if(http_req_cfg->method == HTTP_GET){ |
| ocomeni | 103:7b566b522427 | 1106 | dbg_printf(LOG, "HTTP_GET -- ignoring body\n"); |
| ocomeni | 88:7ffa053be662 | 1107 | //setHttpHeader("Content-Type", http_req_cfg->contentType); |
| ocomeni | 88:7ffa053be662 | 1108 | //setHttpHeader("Content-Length", http_req_cfg->contentLen); |
| ocomeni | 88:7ffa053be662 | 1109 | http_response = http_request->send(NULL, 0); |
| ocomeni | 88:7ffa053be662 | 1110 | } |
| ocomeni | 88:7ffa053be662 | 1111 | else{ |
| ocomeni | 88:7ffa053be662 | 1112 | setHttpHeader("Content-Type", http_req_cfg->contentType); |
| ocomeni | 88:7ffa053be662 | 1113 | setHttpHeader("Content-Length", http_req_cfg->contentLen); |
| ocomeni | 88:7ffa053be662 | 1114 | http_response = http_request->send(http_req_cfg->body, bodyLen); |
| ocomeni | 88:7ffa053be662 | 1115 | } |
| ocomeni | 87:99b37d26ff2a | 1116 | free_DataMsg(); |
| ocomeni | 87:99b37d26ff2a | 1117 | if (!http_response) { |
| ocomeni | 87:99b37d26ff2a | 1118 | char buf[100]; |
| ocomeni | 87:99b37d26ff2a | 1119 | mbedtls_strerror(http_request->get_error(), buf, 100); |
| ocomeni | 103:7b566b522427 | 1120 | dbg_printf(LOG, "HttpRequest failed (error code %s)\n", buf); |
| ocomeni | 103:7b566b522427 | 1121 | //dbg_printf(LOG, "HttpsRequest failed (error code %d)\n", https_request->get_error()); |
| ocomeni | 87:99b37d26ff2a | 1122 | delete http_request; // free the memory |
| ocomeni | 98:65c2333a38b6 | 1123 | return false; |
| ocomeni | 87:99b37d26ff2a | 1124 | } |
| ocomeni | 88:7ffa053be662 | 1125 | delete http_request; // free the memory |
| ocomeni | 103:7b566b522427 | 1126 | dbg_printf(LOG, "\n----- HTTP POST response -----\n"); |
| ocomeni | 84:7c7add00f4bf | 1127 | } |
| ocomeni | 87:99b37d26ff2a | 1128 | else |
| ocomeni | 87:99b37d26ff2a | 1129 | { |
| ocomeni | 105:e5ce023eee93 | 1130 | mbed_stats_heap_t heap_stats; |
| ocomeni | 105:e5ce023eee93 | 1131 | mbed_stats_heap_get(&heap_stats); |
| ocomeni | 105:e5ce023eee93 | 1132 | dbg_printf(LOG, "Heap size: %lu / %lu bytes\r\n", heap_stats.current_size, heap_stats.reserved_size); |
| ocomeni | 106:e1f04c3d0647 | 1133 | starttime = Kernel::get_ms_count(); |
| ocomeni | 90:ed0267eca7b5 | 1134 | #ifndef DONT_USE_TLS_SOCKET |
| ocomeni | 88:7ffa053be662 | 1135 | if(https_connection_active == false){ |
| ocomeni | 88:7ffa053be662 | 1136 | bool tlsResult; |
| ocomeni | 88:7ffa053be662 | 1137 | tlsResult = createTLSconnection(host); |
| ocomeni | 93:06e755a80187 | 1138 | #ifdef ENABLE_MBED_TRACE |
| ocomeni | 93:06e755a80187 | 1139 | mbed_trace_free(); // free trace memory |
| ocomeni | 93:06e755a80187 | 1140 | #endif |
| ocomeni | 106:e1f04c3d0647 | 1141 | stoptime = Kernel::get_ms_count(); |
| ocomeni | 106:e1f04c3d0647 | 1142 | dbg_printf(LOG, "\r\nTLS connection time : %d ms\r\n", (stoptime - starttime)); |
| ocomeni | 88:7ffa053be662 | 1143 | if(tlsResult == false){ |
| ocomeni | 88:7ffa053be662 | 1144 | delete socket; |
| ocomeni | 103:7b566b522427 | 1145 | dbg_printf(LOG, "TLS Socket connection failed - deleting data msg\r\n"); |
| ocomeni | 88:7ffa053be662 | 1146 | free_DataMsg(); |
| ocomeni | 103:7b566b522427 | 1147 | dbg_printf(LOG, "data msg deleted \r\n"); |
| ocomeni | 104:11e9605093c9 | 1148 | http_result = TLS_CONNECTION_FAILED; |
| ocomeni | 98:65c2333a38b6 | 1149 | return false; |
| ocomeni | 88:7ffa053be662 | 1150 | } |
| ocomeni | 100:80ef4bc31b7a | 1151 | // update remote peer details after socket connection |
| ocomeni | 100:80ef4bc31b7a | 1152 | updateRemotePeerDetails(); |
| ocomeni | 100:80ef4bc31b7a | 1153 | // send socket connection event before proceeding to send https request |
| ocomeni | 100:80ef4bc31b7a | 1154 | // give about 2 ms |
| ocomeni | 104:11e9605093c9 | 1155 | //_event_queue.call(this, &WiFiManager::sendSocketConnectionEvent); |
| ocomeni | 104:11e9605093c9 | 1156 | sendSocketConnectionEvent(); |
| ocomeni | 104:11e9605093c9 | 1157 | //https_connection_active = true; // set true whenever connection succeeds |
| ocomeni | 104:11e9605093c9 | 1158 | //return true; |
| ocomeni | 103:7b566b522427 | 1159 | //dbg_printf(LOG, "[create https] TLS connection successful for https site : %s\n", host); |
| ocomeni | 103:7b566b522427 | 1160 | //dbg_printf(LOG, "after call to createTLSconnection \n"); |
| ocomeni | 98:65c2333a38b6 | 1161 | //print_memory_info(); |
| ocomeni | 88:7ffa053be662 | 1162 | } |
| ocomeni | 88:7ffa053be662 | 1163 | // Pass in `socket`, instead of `network` as first argument, and omit the `SSL_CA_PEM` argument |
| ocomeni | 88:7ffa053be662 | 1164 | //HttpsRequest* get_req = new HttpsRequest(socket, HTTP_GET, "https://httpbin.org/status/418"); |
| ocomeni | 88:7ffa053be662 | 1165 | //_wmutex.lock(); |
| ocomeni | 106:e1f04c3d0647 | 1166 | stoptime = Kernel::get_ms_count(); |
| ocomeni | 106:e1f04c3d0647 | 1167 | dbg_printf(LOG, "\r\nTLS connection time : %d ms\r\n", (stoptime - starttime)); |
| ocomeni | 106:e1f04c3d0647 | 1168 | starttime = Kernel::get_ms_count(); |
| ocomeni | 88:7ffa053be662 | 1169 | https_request = new HttpsRequest(socket, |
| ocomeni | 87:99b37d26ff2a | 1170 | http_req_cfg->method, |
| ocomeni | 88:7ffa053be662 | 1171 | full_url, |
| ocomeni | 87:99b37d26ff2a | 1172 | callback(this, &WiFiManager::body_callback)); |
| ocomeni | 109:c274780ff609 | 1173 | #ifdef SEND_DEBUG_MESSAGES |
| ocomeni | 105:e5ce023eee93 | 1174 | responseString = (char *) malloc(100); |
| ocomeni | 105:e5ce023eee93 | 1175 | sprintf(responseString, "\r\nHTTP REQUEST OBJECT CREATED\r\n"); |
| ocomeni | 105:e5ce023eee93 | 1176 | sendDebugMessage(); |
| ocomeni | 109:c274780ff609 | 1177 | #endif |
| ocomeni | 90:ed0267eca7b5 | 1178 | #else |
| ocomeni | 90:ed0267eca7b5 | 1179 | https_request = new HttpsRequest(network, |
| ocomeni | 90:ed0267eca7b5 | 1180 | SSL_CA_PEM, |
| ocomeni | 90:ed0267eca7b5 | 1181 | http_req_cfg->method, |
| ocomeni | 90:ed0267eca7b5 | 1182 | full_url, |
| ocomeni | 90:ed0267eca7b5 | 1183 | callback(this, &WiFiManager::body_callback)); |
| ocomeni | 90:ed0267eca7b5 | 1184 | #endif |
| ocomeni | 88:7ffa053be662 | 1185 | #ifdef TESTING_HTTPS |
| ocomeni | 103:7b566b522427 | 1186 | dbg_printf(LOG, "http_req_cfg->method = %d\n", http_req_cfg->method); |
| ocomeni | 88:7ffa053be662 | 1187 | if(http_req_cfg->method == HTTP_GET){ |
| ocomeni | 103:7b566b522427 | 1188 | dbg_printf(LOG, "HTTP_GET -- ignoring body\n"); |
| ocomeni | 89:45f6db09a76d | 1189 | setHttpsHeader("Host", http_req_cfg->hostName); |
| ocomeni | 89:45f6db09a76d | 1190 | setHttpsHeader("Accept", http_req_cfg->AcceptVal); |
| ocomeni | 88:7ffa053be662 | 1191 | //setHttpHeader("Content-Type", http_req_cfg->contentType); |
| ocomeni | 88:7ffa053be662 | 1192 | //setHttpHeader("Content-Length", http_req_cfg->contentLen); |
| ocomeni | 88:7ffa053be662 | 1193 | http_response = https_request->send(NULL, 0); |
| ocomeni | 88:7ffa053be662 | 1194 | } |
| ocomeni | 88:7ffa053be662 | 1195 | else{ |
| ocomeni | 105:e5ce023eee93 | 1196 | //dbg_printf(LOG, "about to setup https headers\r\n"); |
| ocomeni | 89:45f6db09a76d | 1197 | setHttpsHeader("Host", http_req_cfg->hostName); |
| ocomeni | 89:45f6db09a76d | 1198 | setHttpsHeader("Accept", http_req_cfg->AcceptVal); |
| ocomeni | 90:ed0267eca7b5 | 1199 | setHttpsHeader("Content-Type", http_req_cfg->contentType); |
| ocomeni | 90:ed0267eca7b5 | 1200 | setHttpsHeader("Content-Length", http_req_cfg->contentLen); |
| ocomeni | 103:7b566b522427 | 1201 | dbg_printf(LOG, "https headers setup - about to send request\r\n"); |
| ocomeni | 105:e5ce023eee93 | 1202 | // Grab the heap statistics |
| ocomeni | 105:e5ce023eee93 | 1203 | //mbed_stats_heap_t heap_stats; |
| ocomeni | 105:e5ce023eee93 | 1204 | //mbed_stats_heap_get(&heap_stats); |
| ocomeni | 105:e5ce023eee93 | 1205 | dbg_printf(LOG, "Heap size: %lu / %lu bytes\r\n", heap_stats.current_size, heap_stats.reserved_size); |
| ocomeni | 109:c274780ff609 | 1206 | #ifdef SEND_DEBUG_MESSAGES |
| ocomeni | 105:e5ce023eee93 | 1207 | responseString = (char *) malloc(200); |
| ocomeni | 105:e5ce023eee93 | 1208 | sprintf(responseString, "\r\nABOUT TO SEND HTTP REQUEST\r\n"); |
| ocomeni | 105:e5ce023eee93 | 1209 | sendDebugMessage(); |
| ocomeni | 105:e5ce023eee93 | 1210 | responseString = (char *) malloc(200); |
| ocomeni | 105:e5ce023eee93 | 1211 | sprintf(responseString, "Heap size= %lu / %lu bytes\r\n", heap_stats.current_size, heap_stats.reserved_size); |
| ocomeni | 105:e5ce023eee93 | 1212 | sendDebugMessage(); |
| ocomeni | 105:e5ce023eee93 | 1213 | https_request->send(http_req_cfg->body, bodyLen); |
| ocomeni | 105:e5ce023eee93 | 1214 | responseString = (char *) malloc(100); |
| ocomeni | 105:e5ce023eee93 | 1215 | sprintf(responseString, "\r\nRETURNED FROM SENDING HTTP REQUEST\r\n"); |
| ocomeni | 105:e5ce023eee93 | 1216 | sendDebugMessage(); |
| ocomeni | 109:c274780ff609 | 1217 | #endif |
| ocomeni | 88:7ffa053be662 | 1218 | } |
| ocomeni | 88:7ffa053be662 | 1219 | #else |
| ocomeni | 89:45f6db09a76d | 1220 | setHttpsHeader("Host", http_req_cfg->hostName); |
| ocomeni | 89:45f6db09a76d | 1221 | setHttpsHeader("Accept", http_req_cfg->AcceptVal); |
| ocomeni | 96:f5ed273881af | 1222 | setHttpsHeader("Content-Type", http_req_cfg->contentType); |
| ocomeni | 96:f5ed273881af | 1223 | setHttpsHeader("Content-Length", http_req_cfg->contentLen); |
| ocomeni | 87:99b37d26ff2a | 1224 | http_response = https_request->send(http_req_cfg->body, bodyLen); |
| ocomeni | 88:7ffa053be662 | 1225 | #endif |
| ocomeni | 105:e5ce023eee93 | 1226 | nsapi_error_t error = https_request->get_error(); |
| ocomeni | 105:e5ce023eee93 | 1227 | if(error < 0) |
| ocomeni | 105:e5ce023eee93 | 1228 | { |
| ocomeni | 87:99b37d26ff2a | 1229 | char buf[100]; |
| ocomeni | 105:e5ce023eee93 | 1230 | mbedtls_strerror(error, buf, 100); |
| ocomeni | 105:e5ce023eee93 | 1231 | printf("HttpsRequest failed (error code %s)\n", buf); |
| ocomeni | 87:99b37d26ff2a | 1232 | delete https_request; // free the memory |
| ocomeni | 96:f5ed273881af | 1233 | https_request = NULL; |
| ocomeni | 88:7ffa053be662 | 1234 | https_connection_active = false; // reset true whenever connection fails |
| ocomeni | 98:65c2333a38b6 | 1235 | socket->close(); |
| ocomeni | 88:7ffa053be662 | 1236 | delete socket; |
| ocomeni | 96:f5ed273881af | 1237 | socket = NULL; |
| ocomeni | 90:ed0267eca7b5 | 1238 | free_DataMsg(); |
| ocomeni | 105:e5ce023eee93 | 1239 | http_result = HTTP_REQUEST_FAILED; |
| ocomeni | 98:65c2333a38b6 | 1240 | return false; |
| ocomeni | 87:99b37d26ff2a | 1241 | } |
| ocomeni | 88:7ffa053be662 | 1242 | https_connection_active = true; // set true whenever connection succeeds |
| ocomeni | 103:7b566b522427 | 1243 | dbg_printf(LOG, "\n----- HTTPS POST response -----\r\n"); |
| ocomeni | 90:ed0267eca7b5 | 1244 | } |
| ocomeni | 96:f5ed273881af | 1245 | free_DataMsg(); |
| ocomeni | 96:f5ed273881af | 1246 | delete https_request; // free the request & response memory |
| ocomeni | 103:7b566b522427 | 1247 | dbg_printf(LOG, "deleted https_request\r\n"); |
| ocomeni | 96:f5ed273881af | 1248 | https_request = NULL; |
| ocomeni | 104:11e9605093c9 | 1249 | http_result = RESPONSE_OK; |
| ocomeni | 106:e1f04c3d0647 | 1250 | stoptime = Kernel::get_ms_count(); |
| ocomeni | 106:e1f04c3d0647 | 1251 | dbg_printf(LOG, "\r\nhttp request to response time : %d ms\r\n", (stoptime - starttime)); |
| ocomeni | 98:65c2333a38b6 | 1252 | return true; |
| ocomeni | 79:a2187bbfa407 | 1253 | } |
| ocomeni | 79:a2187bbfa407 | 1254 | |
| ocomeni | 79:a2187bbfa407 | 1255 | void WiFiManager::createHttpRequest(http_method method, |
| ocomeni | 79:a2187bbfa407 | 1256 | const char* url, |
| ocomeni | 79:a2187bbfa407 | 1257 | Callback<void(const char *at, uint32_t length)> body_callback) |
| ocomeni | 79:a2187bbfa407 | 1258 | { |
| ocomeni | 84:7c7add00f4bf | 1259 | http_request = new HttpRequest(network, |
| ocomeni | 84:7c7add00f4bf | 1260 | method, url, body_callback);; |
| ocomeni | 79:a2187bbfa407 | 1261 | } |
| ocomeni | 79:a2187bbfa407 | 1262 | |
| ocomeni | 79:a2187bbfa407 | 1263 | void WiFiManager::setHttpHeader(string key, string value) |
| ocomeni | 79:a2187bbfa407 | 1264 | { |
| ocomeni | 79:a2187bbfa407 | 1265 | http_request->set_header(key, value); |
| ocomeni | 79:a2187bbfa407 | 1266 | } |
| ocomeni | 79:a2187bbfa407 | 1267 | |
| ocomeni | 79:a2187bbfa407 | 1268 | void WiFiManager::setHttpsHeader(string key, string value) |
| ocomeni | 79:a2187bbfa407 | 1269 | { |
| ocomeni | 79:a2187bbfa407 | 1270 | https_request->set_header(key, value); |
| ocomeni | 79:a2187bbfa407 | 1271 | } |
| ocomeni | 79:a2187bbfa407 | 1272 | |
| ocomeni | 79:a2187bbfa407 | 1273 | void WiFiManager::sendHttpsRequest(const char * body, int bodyLen) |
| ocomeni | 78:07bb86e3ce14 | 1274 | { |
| ocomeni | 78:07bb86e3ce14 | 1275 | } |
| ocomeni | 79:a2187bbfa407 | 1276 | |
| ocomeni | 79:a2187bbfa407 | 1277 | void WiFiManager::sendHttpRequest(const char * body, int bodyLen) |
| ocomeni | 78:07bb86e3ce14 | 1278 | { |
| ocomeni | 78:07bb86e3ce14 | 1279 | } |
| ocomeni | 79:a2187bbfa407 | 1280 |