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

Dependencies:   mbed-http

Committer:
ocomeni
Date:
Thu Mar 21 22:17:28 2019 +0000
Revision:
80:e8f0e92e3ac9
Parent:
79:a2187bbfa407
Child:
81:637a87eb8170
implemented queue and memory pools for command and data passing between ATCmdManager and WiFiManager classes

Who changed what in which revision?

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 79:a2187bbfa407 19
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 80:e8f0e92e3ac9 25 MemoryPool<wifi_cmd_message_t, 16> *wiFi2ATmPool,
ocomeni 80:e8f0e92e3ac9 26 Queue<wifi_cmd_message_t, 16> *wiFi2ATCmdQueue,
ocomeni 80:e8f0e92e3ac9 27 MemoryPool<wifi_data_msg_t, 4> *aT2WiFiDatamPool,
ocomeni 80:e8f0e92e3ac9 28 Queue<wifi_data_msg_t, 4> *aT2WiFiDataQueue,
ocomeni 80:e8f0e92e3ac9 29 MemoryPool<wifi_data_msg_t, 4> *wiFi2ATDatamPool,
ocomeni 80:e8f0e92e3ac9 30 Queue<wifi_data_msg_t, 4> *wiFi2ATDataQueue);
ocomeni 78:07bb86e3ce14 31 ~WiFiManager();
ocomeni 79:a2187bbfa407 32 nsapi_size_or_error_t scanNetworks();
ocomeni 79:a2187bbfa407 33 nsapi_size_or_error_t getAvailableAPs(WiFiAccessPoint * res,
ocomeni 79:a2187bbfa407 34 nsapi_size_t count);
ocomeni 79:a2187bbfa407 35 void set_WIFI_SSID(char * wifi_ssid);
ocomeni 79:a2187bbfa407 36 void set_WIFI_PASSWORD(char * wifi_pass);
ocomeni 79:a2187bbfa407 37 void set_WIFI_SECURITY(nsapi_security_t wifi_security);
ocomeni 79:a2187bbfa407 38 nsapi_error_t connect();
ocomeni 79:a2187bbfa407 39 nsapi_error_t disconnect();
ocomeni 79:a2187bbfa407 40 void createHttpsRequest(http_method method,
ocomeni 79:a2187bbfa407 41 const char* url,
ocomeni 79:a2187bbfa407 42 Callback<void(const char *at, uint32_t length)> body_callback = 0
ocomeni 79:a2187bbfa407 43 );
ocomeni 79:a2187bbfa407 44 void createHttpRequest(http_method method,
ocomeni 79:a2187bbfa407 45 const char* url,
ocomeni 79:a2187bbfa407 46 Callback<void(const char *at, uint32_t length)> body_callback = 0
ocomeni 79:a2187bbfa407 47 );
ocomeni 79:a2187bbfa407 48 void setHttpHeader(string key, string value);
ocomeni 79:a2187bbfa407 49 void setHttpsHeader(string key, string value);
ocomeni 79:a2187bbfa407 50 void sendHttpsRequest(const char * body, int bodyLen);
ocomeni 79:a2187bbfa407 51 void sendHttpRequest(const char * body, int bodyLen);
ocomeni 79:a2187bbfa407 52 bool setNextCommand(wifi_cmd_t cmd);
ocomeni 79:a2187bbfa407 53 bool dequeueWiFiCommands();
ocomeni 79:a2187bbfa407 54 void runMain();
ocomeni 79:a2187bbfa407 55
ocomeni 78:07bb86e3ce14 56
ocomeni 78:07bb86e3ce14 57
ocomeni 78:07bb86e3ce14 58 private:
ocomeni 78:07bb86e3ce14 59 wifi_config_t wifi_config;
ocomeni 78:07bb86e3ce14 60 WiFiInterface *network;
ocomeni 79:a2187bbfa407 61 HttpsRequest* https_request;
ocomeni 79:a2187bbfa407 62 HttpRequest* http_request;
ocomeni 79:a2187bbfa407 63 HttpResponse* http_response;
ocomeni 79:a2187bbfa407 64 nsapi_size_or_error_t lastScanCount;
ocomeni 79:a2187bbfa407 65 wifi_cmd_t wifiCmd;
ocomeni 80:e8f0e92e3ac9 66 /* Queue and memory pool for AT to Wifi commands */
ocomeni 79:a2187bbfa407 67 MemoryPool<wifi_cmd_message_t, 16> *_aT2WiFimPool;
ocomeni 79:a2187bbfa407 68 Queue<wifi_cmd_message_t, 16> *_aT2WiFiCmdQueue;
ocomeni 79:a2187bbfa407 69
ocomeni 80:e8f0e92e3ac9 70 /* Queue and memory pool for WiFi to AT commands */
ocomeni 80:e8f0e92e3ac9 71 MemoryPool<wifi_cmd_message_t, 16> *_wiFi2ATmPool;
ocomeni 80:e8f0e92e3ac9 72 Queue<wifi_cmd_message_t, 16> *_wiFi2ATCmdQueue;
ocomeni 80:e8f0e92e3ac9 73
ocomeni 80:e8f0e92e3ac9 74 /* Queue and memory pool for AT to WiFi data */
ocomeni 80:e8f0e92e3ac9 75 MemoryPool<wifi_data_msg_t, 4> *_aT2WiFiDatamPool;
ocomeni 80:e8f0e92e3ac9 76 Queue<wifi_data_msg_t, 4> *_aT2WiFiDataQueue;
ocomeni 80:e8f0e92e3ac9 77
ocomeni 80:e8f0e92e3ac9 78
ocomeni 80:e8f0e92e3ac9 79 /* Queue and memory pool for WiFi to AT data */
ocomeni 80:e8f0e92e3ac9 80 MemoryPool<wifi_data_msg_t, 4> wiFi2ATDatamPool;
ocomeni 80:e8f0e92e3ac9 81 Queue<wifi_data_msg_t, 4> wiFi2ATDataQueue;
ocomeni 80:e8f0e92e3ac9 82
ocomeni 80:e8f0e92e3ac9 83
ocomeni 78:07bb86e3ce14 84 /**
ocomeni 78:07bb86e3ce14 85 * Allows timeout to be changed between commands
ocomeni 78:07bb86e3ce14 86 *
ocomeni 78:07bb86e3ce14 87 * @param timeout_ms timeout of the connection
ocomeni 78:07bb86e3ce14 88 */
ocomeni 78:07bb86e3ce14 89 //void set_timeout(uint32_t timeout_ms = UBLOX_ODIN_W2_MISC_TIMEOUT);
ocomeni 78:07bb86e3ce14 90 };
ocomeni 78:07bb86e3ce14 91 #endif // __WIFI_MANAGER_H__