mbed Connector Interface simplification API on top of mbed-client

Fork of mbedConnectorInterfaceV3 by Doug Anson

NOTE:

This repo has been replaced with https://github.com/ARMmbed/mbedConnectorInterface. No further updates will occur with this repo. Please use the github repo instead. Thanks!

Revision:
94:25ce0592620f
Parent:
81:a2441163a06e
Child:
102:4eb8eff3431f
--- a/source/mbedEndpointNetwork.cpp	Fri Mar 10 17:50:52 2017 +0000
+++ b/source/mbedEndpointNetwork.cpp	Fri Mar 31 06:21:29 2017 +0000
@@ -29,23 +29,25 @@
 // Forward declarations of public functions in mbedEndpointNetwork
 #include "mbed-connector-interface/mbedEndpointNetworkImpl.h"
 
-// Network Selection
-#if MBED_CONF_APP_NETWORK_INTERFACE == WIFI
-	#define NETWORK_TYPE			(char *)"WiFi"
-	#include "ESP8266Interface.h"
-	ESP8266Interface network(MBED_CONF_APP_WIFI_TX,MBED_CONF_APP_WIFI_RX);
+// Enable/Disable easy-connect debugging
+#define EASY_CONNECT_DEBUG			false
+
+// Network Selection (via easy-connect library now...)
+#include "easy-connect.h"
+#if MBED_CONF_APP_NETWORK_INTERFACE == WIFI_ESP8266
+#define NETWORK_TYPE			(char *)"WiFi-ESP8266"
+#elif MBED_CONF_APP_NETWORK_INTERFACE == WIFI_ODIN
+#define NETWORK_TYPE			(char *)"WiFi-ODIN"
 #elif MBED_CONF_APP_NETWORK_INTERFACE == ETHERNET
-	#define NETWORK_TYPE			(char *)"Ethernet"
-	#include "EthernetInterface.h"
-	EthernetInterface network;
+#define NETWORK_TYPE			(char *)"Ethernet"
+#elif MBED_CONF_APP_NETWORK_INTERFACE == CELL
+#define NETWORK_TYPE			(char *)"Cellular"
 #elif MBED_CONF_APP_NETWORK_INTERFACE == MESH_LOWPAN_ND
-	#define NETWORK_TYPE			(char *)"6LowPAN"
-	#include "NanostackInterface.h"
-	LoWPANNDInterface network;
+#define NETWORK_TYPE			(char *)"6LowPAN"
 #elif MBED_CONF_APP_NETWORK_INTERFACE == MESH_THREAD
-	#define NETWORK_TYPE			(char *)"Thread"
-	#include "NanostackInterface.h"
-	ThreadInterface network;
+#define NETWORK_TYPE			(char *)"Thread"
+else
+#define NETWORK_TYPE			(char *)"UNKNOWN"
 #endif
 
 // Logger instance
@@ -89,11 +91,15 @@
 	
 // setup shutdown button
 #if MBED_CONF_APP_SHUTDOWN_BUTTON_ENABLE == true
+#ifdef TARGET_K64F
 InterruptIn shutdown_button(MBED_CONF_APP_SHUTDOWN_PIN);
+#endif
 void configure_deregistration_button(void) {
+#ifdef TARGET_K64F
 	logger.log("mbedEndpointNetwork(%s): configuring de-registration button...",NETWORK_TYPE); 
 	shutdown_button.fall(&net_shutdown_endpoint);
-}	
+#endif
+}
 #endif
 
 // setup shutdown button
@@ -149,7 +155,6 @@
 // called after the endpoint is configured...
 void net_plumb_network(void *p) 
 {
-    int connected = 0;
     Connector::Endpoint *ep = NULL;
     Connector::Options *options = NULL;
     
@@ -161,48 +166,22 @@
 		ep = (Connector::Endpoint *)p;
 		options = ep->getOptions();
 	}
-    
-#if MBED_CONF_APP_NETWORK_INTERFACE == WIFI
-	// map security types
-    nsapi_security_t security_opt = NSAPI_SECURITY_NONE;
-    if  (options->getWiFiAuthType() == WIFI_WPA_PERSONAL) {
-    	security_opt = NSAPI_SECURITY_WPA;
-    }
-    if  (options->getWiFiAuthType() == WIFI_WPA2_PERSONAL) {
-    	security_opt = NSAPI_SECURITY_WPA2;
-    }
-    if  (options->getWiFiAuthType() == WIFI_WEP) {
-    	security_opt = NSAPI_SECURITY_WEP;
-    }
-    
-	// Network Init (WIFI)...
-    connected = network.connect(options->getWiFiSSID().c_str(),options->getWiFiAuthKey().c_str(),security_opt);
-#elif MBED_CONF_APP_NETWORK_INTERFACE == MESH_LOWPAN_ND || MBED_CONF_APP_NETWORK_INTERFACE == MESH_THREAD
-	// Set the IP Address type to IPV6
-	((Connector::OptionsBuilder *)options)->setIPAddressType(IP_ADDRESS_TYPE_IPV6);
-	
-	// Network Init (Mesh)
-	connected = network.connect();
-#else
-	// not used... just removes a compiler warning...
-    options->getConnectorURL();
-    
-    // Network Init (Ethernet)
-    connected = network.connect();
-#endif
+
+    // connect (use easy-connect now...)
+    __network_interface = easy_connect(EASY_CONNECT_DEBUG);
 
 	// check the connection status..
-	if (connected == 0) {
+	if (__network_interface != NULL) {
 		// success
-    	__network_interface = (NetworkInterface *)&network;
     	if (ep != NULL) {
     		ep->isConnected(true);
     	
     		// Debug
-   			logger.log("mbedEndpointNetwork(%s): IP Address: %s",NETWORK_TYPE,network.get_ip_address());
+   			logger.log("mbedEndpointNetwork(%s): IP Address: %s",NETWORK_TYPE,__network_interface->get_ip_address());
    		}
    	}
    	else {
+   		// connection error
    		__network_interface = NULL;
     	if (ep != NULL) {
     		ep->isConnected(false);