Okundu Omeni
/
wifi-https-ble-sm-uart-atcmd-5-13-1
this is using the mbed os version 5-13-1
source/WiFiManager.h@88:7ffa053be662, 2019-03-31 (annotated)
- Committer:
- ocomeni
- Date:
- Sun Mar 31 22:09:45 2019 +0000
- Revision:
- 88:7ffa053be662
- Parent:
- 87:99b37d26ff2a
- Child:
- 90:ed0267eca7b5
tls connection now working.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ocomeni | 78:07bb86e3ce14 | 1 | #ifndef __WIFI_MANAGER_H__ |
ocomeni | 78:07bb86e3ce14 | 2 | #define __WIFI_MANAGER_H__ |
ocomeni | 79:a2187bbfa407 | 3 | #ifndef __MBED_H__ |
ocomeni | 79:a2187bbfa407 | 4 | #define __MBED_H__ |
ocomeni | 79:a2187bbfa407 | 5 | #include "mbed.h" |
ocomeni | 79:a2187bbfa407 | 6 | #endif |
ocomeni | 79:a2187bbfa407 | 7 | |
ocomeni | 79:a2187bbfa407 | 8 | #include "mbed_trace.h" |
ocomeni | 79:a2187bbfa407 | 9 | #include "https_request.h" |
ocomeni | 79:a2187bbfa407 | 10 | #include "http_request.h" |
ocomeni | 79:a2187bbfa407 | 11 | /* List of trusted root CA certificates |
ocomeni | 79:a2187bbfa407 | 12 | * currently two: GlobalSign, the CA for os.mbed.com and Let's Encrypt, the CA for httpbin.org |
ocomeni | 79:a2187bbfa407 | 13 | * |
ocomeni | 79:a2187bbfa407 | 14 | * To add more root certificates, just concatenate them. |
ocomeni | 79:a2187bbfa407 | 15 | */ |
ocomeni | 79:a2187bbfa407 | 16 | #include "https_certificates.h" |
ocomeni | 78:07bb86e3ce14 | 17 | #include "common_types.h" |
ocomeni | 78:07bb86e3ce14 | 18 | |
ocomeni | 87:99b37d26ff2a | 19 | extern void print_memory_info(); |
ocomeni | 78:07bb86e3ce14 | 20 | class WiFiManager { |
ocomeni | 78:07bb86e3ce14 | 21 | public: |
ocomeni | 79:a2187bbfa407 | 22 | WiFiManager(wifi_config_t wifi_config, WiFiInterface *wifi, |
ocomeni | 79:a2187bbfa407 | 23 | MemoryPool<wifi_cmd_message_t, 16> *aT2WiFimPool, |
ocomeni | 80:e8f0e92e3ac9 | 24 | Queue<wifi_cmd_message_t, 16> *aT2WiFiCmdQueue, |
ocomeni | 81:637a87eb8170 | 25 | MemoryPool<at_resp_message_t, 16> *wiFi2ATmPool, |
ocomeni | 81:637a87eb8170 | 26 | Queue<at_resp_message_t, 16> *wiFi2ATCmdQueue, |
ocomeni | 87:99b37d26ff2a | 27 | MemoryPool<wifi_data_msg_t, PQDSZ> *aT2WiFiDatamPool, |
ocomeni | 87:99b37d26ff2a | 28 | Queue<wifi_data_msg_t, PQDSZ> *aT2WiFiDataQueue, |
ocomeni | 87:99b37d26ff2a | 29 | MemoryPool<at_data_msg_t, PQDSZ> *wiFi2ATDatamPool, |
ocomeni | 87:99b37d26ff2a | 30 | Queue<at_data_msg_t, PQDSZ> *wiFi2ATDataQueue); |
ocomeni | 78:07bb86e3ce14 | 31 | ~WiFiManager(); |
ocomeni | 81:637a87eb8170 | 32 | void runMain(); |
ocomeni | 81:637a87eb8170 | 33 | void status_callback(nsapi_event_t status, intptr_t param); |
ocomeni | 81:637a87eb8170 | 34 | |
ocomeni | 81:637a87eb8170 | 35 | |
ocomeni | 81:637a87eb8170 | 36 | |
ocomeni | 81:637a87eb8170 | 37 | private: |
ocomeni | 88:7ffa053be662 | 38 | Mutex _wmutex; // Protect wifi thread |
ocomeni | 81:637a87eb8170 | 39 | wifi_config_t wifi_config; |
ocomeni | 81:637a87eb8170 | 40 | internet_config_t internet_config; |
ocomeni | 81:637a87eb8170 | 41 | WiFiInterface *network; |
ocomeni | 81:637a87eb8170 | 42 | HttpsRequest* https_request; |
ocomeni | 81:637a87eb8170 | 43 | HttpRequest* http_request; |
ocomeni | 81:637a87eb8170 | 44 | HttpResponse* http_response; |
ocomeni | 84:7c7add00f4bf | 45 | http_request_t *http_req_cfg; |
ocomeni | 81:637a87eb8170 | 46 | nsapi_size_or_error_t lastScanCount; |
ocomeni | 88:7ffa053be662 | 47 | bool https_connection_active; |
ocomeni | 88:7ffa053be662 | 48 | TLSSocket* socket; |
ocomeni | 81:637a87eb8170 | 49 | wifi_cmd_t wifiCmd; |
ocomeni | 84:7c7add00f4bf | 50 | //at_data_msg_t *at_data_resp; |
ocomeni | 84:7c7add00f4bf | 51 | int chunkNum; |
ocomeni | 81:637a87eb8170 | 52 | /* Queue and memory pool for AT to Wifi commands */ |
ocomeni | 81:637a87eb8170 | 53 | MemoryPool<wifi_cmd_message_t, 16> *_aT2WiFimPool; |
ocomeni | 81:637a87eb8170 | 54 | Queue<wifi_cmd_message_t, 16> *_aT2WiFiCmdQueue; |
ocomeni | 81:637a87eb8170 | 55 | |
ocomeni | 81:637a87eb8170 | 56 | /* Queue and memory pool for WiFi to AT commands */ |
ocomeni | 81:637a87eb8170 | 57 | MemoryPool<at_resp_message_t, 16> *_wiFi2ATmPool; |
ocomeni | 81:637a87eb8170 | 58 | Queue<at_resp_message_t, 16> *_wiFi2ATCmdQueue; |
ocomeni | 81:637a87eb8170 | 59 | |
ocomeni | 81:637a87eb8170 | 60 | /* Queue and memory pool for AT to WiFi data */ |
ocomeni | 87:99b37d26ff2a | 61 | MemoryPool<wifi_data_msg_t, PQDSZ> *_aT2WiFiDatamPool; |
ocomeni | 87:99b37d26ff2a | 62 | Queue<wifi_data_msg_t, PQDSZ> *_aT2WiFiDataQueue; |
ocomeni | 81:637a87eb8170 | 63 | wifi_data_msg_t *data_msg; |
ocomeni | 81:637a87eb8170 | 64 | |
ocomeni | 81:637a87eb8170 | 65 | /* Queue and memory pool for WiFi to AT data */ |
ocomeni | 87:99b37d26ff2a | 66 | MemoryPool<at_data_msg_t, PQDSZ> *_wiFi2ATDatamPool; |
ocomeni | 87:99b37d26ff2a | 67 | Queue<at_data_msg_t, PQDSZ> *_wiFi2ATDataQueue; |
ocomeni | 81:637a87eb8170 | 68 | |
ocomeni | 81:637a87eb8170 | 69 | bool is_connected; |
ocomeni | 81:637a87eb8170 | 70 | |
ocomeni | 79:a2187bbfa407 | 71 | nsapi_size_or_error_t scanNetworks(); |
ocomeni | 81:637a87eb8170 | 72 | nsapi_size_or_error_t getAvailableAPs(nsapi_size_t count); |
ocomeni | 79:a2187bbfa407 | 73 | void set_WIFI_SSID(char * wifi_ssid); |
ocomeni | 79:a2187bbfa407 | 74 | void set_WIFI_PASSWORD(char * wifi_pass); |
ocomeni | 79:a2187bbfa407 | 75 | void set_WIFI_SECURITY(nsapi_security_t wifi_security); |
ocomeni | 81:637a87eb8170 | 76 | void set_WIFI_CONFIG(); |
ocomeni | 81:637a87eb8170 | 77 | void set_internet_config(); |
ocomeni | 79:a2187bbfa407 | 78 | nsapi_error_t connect(); |
ocomeni | 79:a2187bbfa407 | 79 | nsapi_error_t disconnect(); |
ocomeni | 84:7c7add00f4bf | 80 | void createHttpsRequest(); |
ocomeni | 79:a2187bbfa407 | 81 | void createHttpRequest(http_method method, |
ocomeni | 79:a2187bbfa407 | 82 | const char* url, |
ocomeni | 79:a2187bbfa407 | 83 | Callback<void(const char *at, uint32_t length)> body_callback = 0 |
ocomeni | 79:a2187bbfa407 | 84 | ); |
ocomeni | 79:a2187bbfa407 | 85 | void setHttpHeader(string key, string value); |
ocomeni | 79:a2187bbfa407 | 86 | void setHttpsHeader(string key, string value); |
ocomeni | 79:a2187bbfa407 | 87 | void sendHttpsRequest(const char * body, int bodyLen); |
ocomeni | 79:a2187bbfa407 | 88 | void sendHttpRequest(const char * body, int bodyLen); |
ocomeni | 79:a2187bbfa407 | 89 | bool setNextCommand(wifi_cmd_t cmd); |
ocomeni | 79:a2187bbfa407 | 90 | bool dequeueWiFiCommands(); |
ocomeni | 81:637a87eb8170 | 91 | bool queueATresponse(at_cmd_resp_t resp); |
ocomeni | 81:637a87eb8170 | 92 | bool dequeueATdataResponse(); |
ocomeni | 81:637a87eb8170 | 93 | bool queueWiFiDataResponse(at_data_msg_t at_resp); |
ocomeni | 81:637a87eb8170 | 94 | const char * sec2str(nsapi_security_t sec); |
ocomeni | 81:637a87eb8170 | 95 | void free_DataMsg(); |
ocomeni | 84:7c7add00f4bf | 96 | void body_callback(const char *at, uint32_t length); |
ocomeni | 84:7c7add00f4bf | 97 | void return_response(HttpResponse* res); |
ocomeni | 88:7ffa053be662 | 98 | void sendResponseDownloadData(at_cmd_resp_t at_cmd, |
ocomeni | 88:7ffa053be662 | 99 | const uint8_t * buf, |
ocomeni | 88:7ffa053be662 | 100 | int bufLen); |
ocomeni | 88:7ffa053be662 | 101 | bool createTLSconnection(const char *hostName); |
ocomeni | 78:07bb86e3ce14 | 102 | |
ocomeni | 78:07bb86e3ce14 | 103 | /** |
ocomeni | 78:07bb86e3ce14 | 104 | * Allows timeout to be changed between commands |
ocomeni | 78:07bb86e3ce14 | 105 | * |
ocomeni | 78:07bb86e3ce14 | 106 | * @param timeout_ms timeout of the connection |
ocomeni | 78:07bb86e3ce14 | 107 | */ |
ocomeni | 78:07bb86e3ce14 | 108 | //void set_timeout(uint32_t timeout_ms = UBLOX_ODIN_W2_MISC_TIMEOUT); |
ocomeni | 78:07bb86e3ce14 | 109 | }; |
ocomeni | 78:07bb86e3ce14 | 110 | #endif // __WIFI_MANAGER_H__ |