this is using the mbed os version 5-13-1
Diff: source/WiFiManager.cpp
- Branch:
- PassingRegression
- Revision:
- 116:2296cf274661
- Parent:
- 114:b11bb96c09f3
- Child:
- 118:8df0e9c2ee3f
--- a/source/WiFiManager.cpp Sun May 19 11:25:28 2019 +0000
+++ b/source/WiFiManager.cpp Sun May 19 13:09:27 2019 +0000
@@ -4,7 +4,8 @@
#define FILE_CODE "wifi"
#define USE_EVENTS_FOR_HTTPS_REQUESTS
-WiFiManager::WiFiManager(wifi_config_t wifi_config, WiFiInterface *wifi,
+WiFiManager::WiFiManager(wifi_config_t *wifi_config, WiFiInterface *wifi,
+ internet_config_t *internet_config,
events::EventQueue &event_queue,
MemoryPool<wifi_cmd_message_t, 16> *aT2WiFimPool,
Queue<wifi_cmd_message_t, 16> *aT2WiFiCmdQueue,
@@ -17,6 +18,7 @@
:
wifi_config(wifi_config),
network(wifi),
+ internet_config(internet_config),
_event_queue(event_queue),
_aT2WiFimPool(aT2WiFimPool),
_aT2WiFiCmdQueue(aT2WiFiCmdQueue),
@@ -33,7 +35,7 @@
{
lastScanCount = 0;
wifiCmd = WIFI_CMD_NONE;
- internet_config.connectionScheme = ALWAYS_CONNECTED; // set default connection scheme
+ //internet_config.connectionScheme = ALWAYS_CONNECTED; // set default connection scheme
is_connected = false;
http_response = NULL;
chunkNum = 0;
@@ -487,8 +489,8 @@
void WiFiManager::set_WIFI_SSID(char * wifi_ssid)
{
- strcpy(wifi_config.ssid, wifi_ssid);
- dbg_printf(LOG, "[WIFI-MAN] wifi_ssid set to %s\n", wifi_config.ssid);
+ strcpy(wifi_config->ssid, wifi_ssid);
+ dbg_printf(LOG, "[WIFI-MAN] wifi_ssid set to %s\n", wifi_config->ssid);
https_connection_active = false; // reset whenever any of the security credentials change
delete socket;
}
@@ -496,7 +498,7 @@
void WiFiManager::set_WIFI_PASSWORD(char * wifi_pass)
{
- strcpy(wifi_config.pass, wifi_pass);
+ strcpy(wifi_config->pass, wifi_pass);
dbg_printf(LOG, "[WIFI-MAN] wifi_pass set to %s\n", "****************");
https_connection_active = false; // reset whenever any of the security credentials change
delete socket;
@@ -505,8 +507,8 @@
void WiFiManager::set_WIFI_SECURITY(nsapi_security_t wifi_security)
{
- wifi_config.security = wifi_security;
- dbg_printf(LOG, "[WIFI-MAN] wifi_security set to %s\n", sec2str(wifi_config.security));
+ wifi_config->security = wifi_security;
+ dbg_printf(LOG, "[WIFI-MAN] wifi_security set to %s\n", sec2str(wifi_config->security));
https_connection_active = false; // reset whenever any of the security credentials change
delete socket;
}
@@ -529,14 +531,14 @@
network->add_dns_server(*addr);
#endif
char * serverAddress = new char[100];
- char *p = strstr(internet_config.url, "//");
+ char *p = strstr(internet_config->url, "//");
if(p != NULL && use_full_hostname == false)
{
strcpy(serverAddress,p+2);
}
else
{
- strcpy(serverAddress,internet_config.url);
+ strcpy(serverAddress,internet_config->url);
}
value_or_error = network->gethostbyname_async(serverAddress,
callback(this, &WiFiManager::gethostbyname_callback),
@@ -562,14 +564,14 @@
void WiFiManager::set_internet_config()
{
internet_config_t *internet_cfg = (internet_config_t *) data_msg->buffer;
- internet_config.peer_id = internet_cfg->peer_id;
- strncpy(internet_config.url,internet_cfg->url, strlen(internet_cfg->url)+1);
- internet_config.connectionScheme = internet_cfg->connectionScheme;
+ internet_config->peer_id = internet_cfg->peer_id;
+ strncpy(internet_config->url,internet_cfg->url, strlen(internet_cfg->url)+1);
+ internet_config->connectionScheme = internet_cfg->connectionScheme;
free_DataMsg();
dbg_printf(LOG, "[WIFI MAN] Internet configuration setup completed\n");
- dbg_printf(LOG, "peer_id = %1d, url = %s, connScheme = %1d\n", internet_config.peer_id,
- internet_config.url,
- internet_config.connectionScheme);
+ dbg_printf(LOG, "peer_id = %1d, url = %s, connScheme = %1d\n", internet_config->peer_id,
+ internet_config->url,
+ internet_config->connectionScheme);
if(https_connection_active)
{
https_connection_active = false; // reset whenever any of the security credentials change
@@ -665,7 +667,7 @@
case WIFI_SSID:
sprintf(nextStrPtr, "\r\n%s%d,%s\r\n", WIFI_NETWORK_STATUS,
status_id,
- wifi_config.ssid);
+ wifi_config->ssid);
break;
case WIFI_BSSID:
sprintf(nextStrPtr, "\r\n%s%d,%s\r\n", WIFI_NETWORK_STATUS,
@@ -721,7 +723,7 @@
case NSAPI_STATUS_GLOBAL_UP:
dbg_printf(LOG, "Global IP address set!\r\n");
dbg_printf(LOG, "[WIFI-MAN] IP address: %s\n", network->get_ip_address());
- dbg_printf(LOG, "[WIFI-MAN] Connected to the network %s\n", wifi_config.ssid);
+ dbg_printf(LOG, "[WIFI-MAN] Connected to the network %s\n", wifi_config->ssid);
responseString = (char *) malloc(MAX_RESPONSE_STRING_LEN);
sprintf(responseString, "\r\n%s%d,%s,%d\r\n", WIFI_LINK_ENABLED,
WIFI_CHANNEL,
@@ -736,7 +738,7 @@
dbg_printf(LOG, "\n [WIFI-MAN] No connection to network!\n");
is_connected = false;
// attempt reconnection if always connected scheme is set
- if(internet_config.connectionScheme == ALWAYS_CONNECTED)
+ if(internet_config->connectionScheme == ALWAYS_CONNECTED)
{
wifiBusy = 1;
nsapi_error_t error;
@@ -774,12 +776,12 @@
return error;
}
dbg_printf(LOG, "[WIFI-MAN] Connecting to network ssid = %s passwd = %s security = %s \r\n",
- wifi_config.ssid,
+ wifi_config->ssid,
"****************",
- sec2str(wifi_config.security));
- error = network->connect(wifi_config.ssid,
- wifi_config.pass,
- wifi_config.security);
+ sec2str(wifi_config->security));
+ error = network->connect(wifi_config->ssid,
+ wifi_config->pass,
+ wifi_config->security);
dbg_printf(LOG, "[WIFI-MAN] network->connect called. error = %d\r\n", error);
return error;
}
@@ -795,16 +797,16 @@
if(is_connected && result>=0)
{
memcpy(&responseBytes[i], address->get_ip_bytes(), 4); // remote IPv4 address
- strcpy(internet_config.remote_IPv4Address, address->get_ip_address());
+ strcpy(internet_config->remote_IPv4Address, address->get_ip_address());
i +=4;
uint16_t port = address->get_port();
- internet_config.remote_port = port;
+ internet_config->remote_port = port;
memcpy(&responseBytes[i], &port, 2); // remote IPv4 port #
i +=2;
// local IPv4 address
int ipAddr[4];
- strcpy(internet_config.local_IPv4Address, network->get_ip_address());
- sscanf(internet_config.local_IPv4Address, "%d.%d.%d.%d", &ipAddr[0], &ipAddr[1],
+ strcpy(internet_config->local_IPv4Address, network->get_ip_address());
+ sscanf(internet_config->local_IPv4Address, "%d.%d.%d.%d", &ipAddr[0], &ipAddr[1],
&ipAddr[2], &ipAddr[3]);
responseBytes[i++] = (uint8_t) ipAddr[0];
responseBytes[i++] = (uint8_t) ipAddr[1];
@@ -856,10 +858,10 @@
IP_PEER_HANDLE,
IPv4_CONNECTION,
TCP_PROTOCOL,
- internet_config.local_IPv4Address,
+ internet_config->local_IPv4Address,
DEFAULT_LOCAL_PORT,
- internet_config.remote_IPv4Address,
- internet_config.remote_port);
+ internet_config->remote_IPv4Address,
+ internet_config->remote_port);
sendATresponseString(AT_EVENT);
}
@@ -1072,14 +1074,14 @@
error = socket->getpeername(address);
if(error>=0)
{
- strcpy(internet_config.remote_IPv4Address, address->get_ip_address());
+ strcpy(internet_config->remote_IPv4Address, address->get_ip_address());
uint16_t port = address->get_port();
- internet_config.remote_port = port;
+ internet_config->remote_port = port;
}
else
{
- strcpy(internet_config.remote_IPv4Address, "");
- internet_config.remote_port = 0;
+ strcpy(internet_config->remote_IPv4Address, "");
+ internet_config->remote_port = 0;
}
delete address;
}
@@ -1108,11 +1110,11 @@
http_req_cfg = (http_request_t *) data_msg->buffer;
#ifdef FULL_DEBUG_ENABLED
dbg_printf(LOG, "\n[WIFI MAN] uri = %s\n", http_req_cfg->request_URI);
- dbg_printf(LOG, "\n[WIFI MAN] internet cfg url = %s\n", internet_config.url);
+ dbg_printf(LOG, "\n[WIFI MAN] internet cfg url = %s\n", internet_config->url);
#endif
char full_url[100];
char host[60] ;
- strncpy(full_url,internet_config.url, strlen(internet_config.url)+1);
+ strncpy(full_url,internet_config->url, strlen(internet_config->url)+1);
strncpy(host,http_req_cfg->hostName, strlen(http_req_cfg->hostName)+1);
strncat(full_url, http_req_cfg->request_URI, strlen(http_req_cfg->request_URI)+1);
#ifdef FULL_DEBUG_ENABLED
@@ -1132,7 +1134,7 @@
printBufferInHex(http_req_cfg->body, bodyLen);
}
#endif
- if(strstr(internet_config.url, "http:")!=NULL) // http request
+ if(strstr(internet_config->url, "http:")!=NULL) // http request
{
http_request = new HttpRequest(network,
http_req_cfg->method,