this is using the mbed os version 5-13-1

Dependencies:   mbed-http

Committer:
ocomeni
Date:
Sun May 19 13:09:27 2019 +0000
Branch:
PassingRegression
Revision:
116:2296cf274661
Parent:
114:b11bb96c09f3
Child:
118:8df0e9c2ee3f
refactoring main, atcmd, BLE and WiFi. added data structures into main and replaced values with references in main. tested and works.

Who changed what in which revision?

UserRevisionLine numberNew 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 116:2296cf274661 22 WiFiManager(wifi_config_t *wifi_config, WiFiInterface *wifi,
ocomeni 116:2296cf274661 23 internet_config_t *internet_config,
ocomeni 98:65c2333a38b6 24 events::EventQueue &event_queue,
ocomeni 79:a2187bbfa407 25 MemoryPool<wifi_cmd_message_t, 16> *aT2WiFimPool,
ocomeni 80:e8f0e92e3ac9 26 Queue<wifi_cmd_message_t, 16> *aT2WiFiCmdQueue,
ocomeni 81:637a87eb8170 27 MemoryPool<at_resp_message_t, 16> *wiFi2ATmPool,
ocomeni 81:637a87eb8170 28 Queue<at_resp_message_t, 16> *wiFi2ATCmdQueue,
ocomeni 87:99b37d26ff2a 29 MemoryPool<wifi_data_msg_t, PQDSZ> *aT2WiFiDatamPool,
ocomeni 87:99b37d26ff2a 30 Queue<wifi_data_msg_t, PQDSZ> *aT2WiFiDataQueue,
ocomeni 87:99b37d26ff2a 31 MemoryPool<at_data_msg_t, PQDSZ> *wiFi2ATDatamPool,
ocomeni 87:99b37d26ff2a 32 Queue<at_data_msg_t, PQDSZ> *wiFi2ATDataQueue);
ocomeni 78:07bb86e3ce14 33 ~WiFiManager();
ocomeni 81:637a87eb8170 34 void runMain();
ocomeni 81:637a87eb8170 35 void status_callback(nsapi_event_t status, intptr_t param);
ocomeni 81:637a87eb8170 36
ocomeni 81:637a87eb8170 37
ocomeni 81:637a87eb8170 38 private:
ocomeni 88:7ffa053be662 39 Mutex _wmutex; // Protect wifi thread
ocomeni 116:2296cf274661 40 wifi_config_t *wifi_config;
ocomeni 116:2296cf274661 41 internet_config_t *internet_config;
ocomeni 98:65c2333a38b6 42 // define event queue
ocomeni 98:65c2333a38b6 43 events::EventQueue &_event_queue;
ocomeni 81:637a87eb8170 44 WiFiInterface *network;
ocomeni 81:637a87eb8170 45 HttpsRequest* https_request;
ocomeni 81:637a87eb8170 46 HttpRequest* http_request;
ocomeni 81:637a87eb8170 47 HttpResponse* http_response;
ocomeni 84:7c7add00f4bf 48 http_request_t *http_req_cfg;
ocomeni 90:ed0267eca7b5 49 at_data_msg_t *at_data_resp;
ocomeni 81:637a87eb8170 50 nsapi_size_or_error_t lastScanCount;
ocomeni 88:7ffa053be662 51 bool https_connection_active;
ocomeni 88:7ffa053be662 52 TLSSocket* socket;
ocomeni 95:290859010c8c 53 char* responseString; // response string formated for Box
ocomeni 99:05398b3184f8 54 uint8_t* responseBytes; // response bytes formated for Box
ocomeni 81:637a87eb8170 55 wifi_cmd_t wifiCmd;
ocomeni 107:f1a83fd41b17 56 bool backgroundTaskCompleted;
ocomeni 84:7c7add00f4bf 57 //at_data_msg_t *at_data_resp;
ocomeni 84:7c7add00f4bf 58 int chunkNum;
ocomeni 81:637a87eb8170 59 /* Queue and memory pool for AT to Wifi commands */
ocomeni 81:637a87eb8170 60 MemoryPool<wifi_cmd_message_t, 16> *_aT2WiFimPool;
ocomeni 81:637a87eb8170 61 Queue<wifi_cmd_message_t, 16> *_aT2WiFiCmdQueue;
ocomeni 81:637a87eb8170 62
ocomeni 81:637a87eb8170 63 /* Queue and memory pool for WiFi to AT commands */
ocomeni 81:637a87eb8170 64 MemoryPool<at_resp_message_t, 16> *_wiFi2ATmPool;
ocomeni 81:637a87eb8170 65 Queue<at_resp_message_t, 16> *_wiFi2ATCmdQueue;
ocomeni 81:637a87eb8170 66
ocomeni 81:637a87eb8170 67 /* Queue and memory pool for AT to WiFi data */
ocomeni 87:99b37d26ff2a 68 MemoryPool<wifi_data_msg_t, PQDSZ> *_aT2WiFiDatamPool;
ocomeni 87:99b37d26ff2a 69 Queue<wifi_data_msg_t, PQDSZ> *_aT2WiFiDataQueue;
ocomeni 81:637a87eb8170 70 wifi_data_msg_t *data_msg;
ocomeni 81:637a87eb8170 71
ocomeni 81:637a87eb8170 72 /* Queue and memory pool for WiFi to AT data */
ocomeni 87:99b37d26ff2a 73 MemoryPool<at_data_msg_t, PQDSZ> *_wiFi2ATDatamPool;
ocomeni 87:99b37d26ff2a 74 Queue<at_data_msg_t, PQDSZ> *_wiFi2ATDataQueue;
ocomeni 81:637a87eb8170 75
ocomeni 81:637a87eb8170 76 bool is_connected;
ocomeni 90:ed0267eca7b5 77 bool http_response_hdr_sent;
ocomeni 107:f1a83fd41b17 78 bool http_request_result;
ocomeni 104:11e9605093c9 79 int wifiBusy;
ocomeni 104:11e9605093c9 80 Timer wifiWatchdogTimer;
ocomeni 109:c274780ff609 81 Ticker watchDogTick;
ocomeni 104:11e9605093c9 82 uint32_t watchdogCnt;
ocomeni 104:11e9605093c9 83 http_result_t http_result;
ocomeni 113:888e262ff0a9 84 bool use_full_hostname;
ocomeni 111:3ab1d9644835 85 #ifdef DNANUDGE_DEBUG
ocomeni 111:3ab1d9644835 86 rtos::Semaphore callback_semaphore;
ocomeni 111:3ab1d9644835 87 #endif
ocomeni 79:a2187bbfa407 88 nsapi_size_or_error_t scanNetworks();
ocomeni 81:637a87eb8170 89 nsapi_size_or_error_t getAvailableAPs(nsapi_size_t count);
ocomeni 79:a2187bbfa407 90 void set_WIFI_SSID(char * wifi_ssid);
ocomeni 79:a2187bbfa407 91 void set_WIFI_PASSWORD(char * wifi_pass);
ocomeni 79:a2187bbfa407 92 void set_WIFI_SECURITY(nsapi_security_t wifi_security);
ocomeni 81:637a87eb8170 93 void set_WIFI_CONFIG();
ocomeni 100:80ef4bc31b7a 94 void set_internet_config();
ocomeni 114:b11bb96c09f3 95 void getWiFiInstance();
ocomeni 79:a2187bbfa407 96 nsapi_error_t connect();
ocomeni 79:a2187bbfa407 97 nsapi_error_t disconnect();
ocomeni 107:f1a83fd41b17 98 void createSendHttpsRequest();
ocomeni 98:65c2333a38b6 99 bool createHttpsRequest();
ocomeni 79:a2187bbfa407 100 void createHttpRequest(http_method method,
ocomeni 79:a2187bbfa407 101 const char* url,
ocomeni 79:a2187bbfa407 102 Callback<void(const char *at, uint32_t length)> body_callback = 0
ocomeni 79:a2187bbfa407 103 );
ocomeni 79:a2187bbfa407 104 void setHttpHeader(string key, string value);
ocomeni 79:a2187bbfa407 105 void setHttpsHeader(string key, string value);
ocomeni 79:a2187bbfa407 106 void sendHttpsRequest(const char * body, int bodyLen);
ocomeni 79:a2187bbfa407 107 void sendHttpRequest(const char * body, int bodyLen);
ocomeni 79:a2187bbfa407 108 bool setNextCommand(wifi_cmd_t cmd);
ocomeni 79:a2187bbfa407 109 bool dequeueWiFiCommands();
ocomeni 81:637a87eb8170 110 bool queueATresponse(at_cmd_resp_t resp);
ocomeni 81:637a87eb8170 111 bool dequeueATdataResponse();
ocomeni 81:637a87eb8170 112 bool queueWiFiDataResponse(at_data_msg_t at_resp);
ocomeni 81:637a87eb8170 113 const char * sec2str(nsapi_security_t sec);
ocomeni 81:637a87eb8170 114 void free_DataMsg();
ocomeni 84:7c7add00f4bf 115 void body_callback(const char *at, uint32_t length);
ocomeni 84:7c7add00f4bf 116 void return_response(HttpResponse* res);
ocomeni 88:7ffa053be662 117 void sendResponseDownloadData(at_cmd_resp_t at_cmd,
ocomeni 88:7ffa053be662 118 const uint8_t * buf,
ocomeni 88:7ffa053be662 119 int bufLen);
ocomeni 88:7ffa053be662 120 bool createTLSconnection(const char *hostName);
ocomeni 104:11e9605093c9 121 void printBufferInHex(const uint8_t *buf, int pLen);
ocomeni 102:9748f290a1a5 122 bool copyResponseHdr2Queue(const uint8_t * buf);
ocomeni 95:290859010c8c 123 void sendATresponseString(at_cmd_resp_t);
ocomeni 99:05398b3184f8 124 void sendATresponseBytes(at_cmd_resp_t at_cmd, int len);
ocomeni 95:290859010c8c 125 void getNetworkStatus();
ocomeni 95:290859010c8c 126 void getWiFiStatus();
ocomeni 98:65c2333a38b6 127 void status_callback_event(nsapi_event_t status, intptr_t param);
ocomeni 111:3ab1d9644835 128 void gethostbyname_callback(nsapi_error_t res, SocketAddress *addr);
ocomeni 100:80ef4bc31b7a 129 void gethostbyname();
ocomeni 100:80ef4bc31b7a 130 void sendSocketConnectionEvent();
ocomeni 100:80ef4bc31b7a 131 void updateRemotePeerDetails();
ocomeni 105:e5ce023eee93 132 void sendDebugMessage();
ocomeni 104:11e9605093c9 133 void callWifiWatchDog();
ocomeni 109:c274780ff609 134 void callWifiWatchDogIsr();
ocomeni 113:888e262ff0a9 135 void processGetHostByNameResult(nsapi_error_t result, SocketAddress *addr);
ocomeni 100:80ef4bc31b7a 136
ocomeni 90:ed0267eca7b5 137
ocomeni 78:07bb86e3ce14 138
ocomeni 78:07bb86e3ce14 139 /**
ocomeni 78:07bb86e3ce14 140 * Allows timeout to be changed between commands
ocomeni 78:07bb86e3ce14 141 *
ocomeni 78:07bb86e3ce14 142 * @param timeout_ms timeout of the connection
ocomeni 78:07bb86e3ce14 143 */
ocomeni 78:07bb86e3ce14 144 //void set_timeout(uint32_t timeout_ms = UBLOX_ODIN_W2_MISC_TIMEOUT);
ocomeni 78:07bb86e3ce14 145 };
ocomeni 78:07bb86e3ce14 146 #endif // __WIFI_MANAGER_H__