Added support for the WNC M14A2A Cellular LTE Data Module.

Dependencies:   WNC14A2AInterface

Easy Connect

Easily add all supported connectivity methods to your mbed OS project

This project is derived from https://developer.mbed.org/teams/sandbox/code/simple-mbed-client-example/file/dd6231df71bb/easy-connect.lib. It give user the ability to switch between connectivity methods and includes support for the WNC14A2A Data Module. The `NetworkInterface` API makes this easy, but you still need a mechanism for the user to select the connection method, The selection is made by modifying the `mbed_app.json` file and using `easy_connect()` from your application.

Specifying connectivity method

To add support for the WNC14A2A, add the following to your ``mbed_app.json`` file:

mbed_app.json

{
    "config": {
        "network-interface":{
            "help": "options are ETHERNET,WIFI_ESP8266,WIFI_ODIN,MESH_LOWPAN_ND,MESH_THREAD,WNC14A2A",
            "value": "WNC14A2A"
        }
    },
}

After you choose `WNC14A2A` you'll also need to indicate if you want debug output or not by Enabling (true) or Disabling (false) WNC_DEBUG.

If WNC_DEBUG is enabled, there are 3 different levels of debug output (selected via bit settings). These debug levels are set using the following values:

ValueDescription
1Basic WNC driver debug output
2Comprehensive WNC driver debug output
4Network Layer debug output

You can have any combination of these three bit values for a total value of 0 – 7.

WNC Debug Settings

    "config": {
        "WNC_DEBUG": {
            "value": false
        },
        "WNC_DEBUG_SETTING": {
            "value": 4
        },
    }

Using Easy Connect from your application

Easy Connect has just one function which will either return a `NetworkInterface`-pointer or `NULL`:

Sample Code

#include "easy-connect.h"

int main(int, char**) {
    NetworkInterface* network = easy_connect(true); /* has 1 argument, enable_logging (pass in true to log to serial port) */
    if (!network) {
        printf("Connecting to the network failed... See serial output.\r\n");
        return 1;
    }
 
    // Rest of your program
}

Tested on

  • K64F with Ethernet.
  • AT&T Cellular IoT Starter Kit with WNC M14A2A Cellular Data Module

The WNCInterface class currently supports the following version(s):

  • MPSS: M14A2A_v11.50.164451 APSS: M14A2A_v11.53.164451

License

This library is released under the Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License and may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Committer:
group-Avnet
Date:
Wed Apr 19 01:08:11 2017 +0000
Revision:
0:478cfd88041f
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
group-Avnet 0:478cfd88041f 1 #ifndef __MAGIC_CONNECT_H__
group-Avnet 0:478cfd88041f 2 #define __MAGIC_CONNECT_H__
group-Avnet 0:478cfd88041f 3
group-Avnet 0:478cfd88041f 4 #include "mbed.h"
group-Avnet 0:478cfd88041f 5
group-Avnet 0:478cfd88041f 6 #define ETHERNET 1
group-Avnet 0:478cfd88041f 7 #define WIFI_ESP8266 2
group-Avnet 0:478cfd88041f 8 #define MESH_LOWPAN_ND 3
group-Avnet 0:478cfd88041f 9 #define MESH_THREAD 4
group-Avnet 0:478cfd88041f 10 #define WIFI_ODIN 5
group-Avnet 0:478cfd88041f 11 #define WNC14A2A 6
group-Avnet 0:478cfd88041f 12
group-Avnet 0:478cfd88041f 13 #if MBED_CONF_APP_NETWORK_INTERFACE == WIFI_ESP8266
group-Avnet 0:478cfd88041f 14 #include "ESP8266Interface.h"
group-Avnet 0:478cfd88041f 15
group-Avnet 0:478cfd88041f 16 #ifdef MBED_CONF_APP_ESP8266_DEBUG
group-Avnet 0:478cfd88041f 17 ESP8266Interface wifi(MBED_CONF_APP_ESP8266_TX, MBED_CONF_APP_ESP8266_RX, MBED_CONF_APP_ESP8266_DEBUG);
group-Avnet 0:478cfd88041f 18 #else
group-Avnet 0:478cfd88041f 19 ESP8266Interface wifi(MBED_CONF_APP_ESP8266_TX, MBED_CONF_APP_ESP8266_RX);
group-Avnet 0:478cfd88041f 20 #endif
group-Avnet 0:478cfd88041f 21
group-Avnet 0:478cfd88041f 22 #elif MBED_CONF_APP_NETWORK_INTERFACE == WIFI_ODIN
group-Avnet 0:478cfd88041f 23 #include "OdinWiFiInterface.h"
group-Avnet 0:478cfd88041f 24 OdinWiFiInterface wifi;
group-Avnet 0:478cfd88041f 25
group-Avnet 0:478cfd88041f 26 #elif MBED_CONF_APP_NETWORK_INTERFACE == ETHERNET
group-Avnet 0:478cfd88041f 27 #include "EthernetInterface.h"
group-Avnet 0:478cfd88041f 28 EthernetInterface eth;
group-Avnet 0:478cfd88041f 29
group-Avnet 0:478cfd88041f 30 #elif MBED_CONF_APP_NETWORK_INTERFACE == WNC14A2A
group-Avnet 0:478cfd88041f 31 #include "WNC14A2AInterface.h"
group-Avnet 0:478cfd88041f 32 WNC14A2AInterface *wnc;
group-Avnet 0:478cfd88041f 33
group-Avnet 0:478cfd88041f 34 #if MBED_CONF_APP_WNC_DEBUG == true
group-Avnet 0:478cfd88041f 35 extern BufferedSerial pc;
group-Avnet 0:478cfd88041f 36 #define Serial BufferedSerial
group-Avnet 0:478cfd88041f 37 #endif
group-Avnet 0:478cfd88041f 38
group-Avnet 0:478cfd88041f 39 #elif MBED_CONF_APP_NETWORK_INTERFACE == MESH_LOWPAN_ND
group-Avnet 0:478cfd88041f 40 #define MESH
group-Avnet 0:478cfd88041f 41 #include "NanostackInterface.h"
group-Avnet 0:478cfd88041f 42 LoWPANNDInterface mesh;
group-Avnet 0:478cfd88041f 43 #elif MBED_CONF_APP_NETWORK_INTERFACE == MESH_THREAD
group-Avnet 0:478cfd88041f 44 #define MESH
group-Avnet 0:478cfd88041f 45 #include "NanostackInterface.h"
group-Avnet 0:478cfd88041f 46 ThreadInterface mesh;
group-Avnet 0:478cfd88041f 47 #else
group-Avnet 0:478cfd88041f 48 #error "No connectivity method chosen. Please add 'config.network-interfaces.value' to your mbed_app.json (see README.md for more information)."
group-Avnet 0:478cfd88041f 49 #endif
group-Avnet 0:478cfd88041f 50
group-Avnet 0:478cfd88041f 51 #if defined(MESH)
group-Avnet 0:478cfd88041f 52 #if MBED_CONF_APP_MESH_RADIO_TYPE == ATMEL
group-Avnet 0:478cfd88041f 53 #include "NanostackRfPhyAtmel.h"
group-Avnet 0:478cfd88041f 54 NanostackRfPhyAtmel rf_phy(ATMEL_SPI_MOSI, ATMEL_SPI_MISO, ATMEL_SPI_SCLK, ATMEL_SPI_CS,
group-Avnet 0:478cfd88041f 55 ATMEL_SPI_RST, ATMEL_SPI_SLP, ATMEL_SPI_IRQ, ATMEL_I2C_SDA, ATMEL_I2C_SCL);
group-Avnet 0:478cfd88041f 56 #elif MBED_CONF_APP_MESH_RADIO_TYPE == MCR20
group-Avnet 0:478cfd88041f 57 #include "NanostackRfPhyMcr20a.h"
group-Avnet 0:478cfd88041f 58 NanostackRfPhyMcr20a rf_phy(MCR20A_SPI_MOSI, MCR20A_SPI_MISO, MCR20A_SPI_SCLK, MCR20A_SPI_CS, MCR20A_SPI_RST, MCR20A_SPI_IRQ);
group-Avnet 0:478cfd88041f 59 #endif //MBED_CONF_APP_RADIO_TYPE
group-Avnet 0:478cfd88041f 60 #endif //MESH
group-Avnet 0:478cfd88041f 61
group-Avnet 0:478cfd88041f 62 #ifndef MESH
group-Avnet 0:478cfd88041f 63 // This is address to mbed Device Connector
group-Avnet 0:478cfd88041f 64 #define MBED_SERVER_ADDRESS "coap://api.connector.mbed.com:5684"
group-Avnet 0:478cfd88041f 65 #else
group-Avnet 0:478cfd88041f 66 // This is address to mbed Device Connector
group-Avnet 0:478cfd88041f 67 #define MBED_SERVER_ADDRESS "coaps://[2607:f0d0:2601:52::20]:5684"
group-Avnet 0:478cfd88041f 68 #endif
group-Avnet 0:478cfd88041f 69
group-Avnet 0:478cfd88041f 70 #ifdef MBED_CONF_APP_ESP8266_SSID
group-Avnet 0:478cfd88041f 71 #define MBED_CONF_APP_WIFI_SSID MBED_CONF_APP_ESP8266_SSID
group-Avnet 0:478cfd88041f 72 #endif
group-Avnet 0:478cfd88041f 73
group-Avnet 0:478cfd88041f 74 #ifdef MBED_CONF_APP_ESP8266_PASSWORD
group-Avnet 0:478cfd88041f 75 #define MBED_CONF_APP_WIFI_PASSWORD MBED_CONF_APP_ESP8266_PASSWORD
group-Avnet 0:478cfd88041f 76 #endif
group-Avnet 0:478cfd88041f 77
group-Avnet 0:478cfd88041f 78
group-Avnet 0:478cfd88041f 79 NetworkInterface* easy_connect(bool log_messages = false) {
group-Avnet 0:478cfd88041f 80 NetworkInterface* network_interface = 0;
group-Avnet 0:478cfd88041f 81 int connect_success = -1;
group-Avnet 0:478cfd88041f 82 #if MBED_CONF_APP_NETWORK_INTERFACE == WIFI_ESP8266
group-Avnet 0:478cfd88041f 83 if (log_messages) {
group-Avnet 0:478cfd88041f 84 printf("[EasyConnect] Using WiFi (ESP8266) \n");
group-Avnet 0:478cfd88041f 85 printf("[EasyConnect] Connecting to WiFi %s\n", MBED_CONF_APP_WIFI_SSID);
group-Avnet 0:478cfd88041f 86 }
group-Avnet 0:478cfd88041f 87 connect_success = wifi.connect(MBED_CONF_APP_WIFI_SSID, MBED_CONF_APP_WIFI_PASSWORD, NSAPI_SECURITY_WPA_WPA2);
group-Avnet 0:478cfd88041f 88 network_interface = &wifi;
group-Avnet 0:478cfd88041f 89 #elif MBED_CONF_APP_NETWORK_INTERFACE == WIFI_ODIN
group-Avnet 0:478cfd88041f 90 if (log_messages) {
group-Avnet 0:478cfd88041f 91 printf("[EasyConnect] Using WiFi (ODIN) \n");
group-Avnet 0:478cfd88041f 92 printf("[EasyConnect] Connecting to WiFi %s\n", MBED_CONF_APP_WIFI_SSID);
group-Avnet 0:478cfd88041f 93 }
group-Avnet 0:478cfd88041f 94 connect_success = wifi.connect(MBED_CONF_APP_WIFI_SSID, MBED_CONF_APP_WIFI_PASSWORD, NSAPI_SECURITY_WPA_WPA2);
group-Avnet 0:478cfd88041f 95 network_interface = &wifi;
group-Avnet 0:478cfd88041f 96
group-Avnet 0:478cfd88041f 97 #elif MBED_CONF_APP_NETWORK_INTERFACE == WNC14A2A
group-Avnet 0:478cfd88041f 98 if (log_messages) {
group-Avnet 0:478cfd88041f 99 printf("[EasyConnect] Using WNC14A2A\n");
group-Avnet 0:478cfd88041f 100 #if MBED_CONF_APP_WNC_DEBUG == true
group-Avnet 0:478cfd88041f 101 printf("[EasyConnect] with debug output\n");
group-Avnet 0:478cfd88041f 102 printf("[WNC Driver ] debug = %d\n",MBED_CONF_APP_WNC_DEBUG_SETTING);
group-Avnet 0:478cfd88041f 103 wnc = new WNC14A2AInterface(&pc);
group-Avnet 0:478cfd88041f 104 wnc->doDebug(MBED_CONF_APP_WNC_DEBUG_SETTING);
group-Avnet 0:478cfd88041f 105 #else
group-Avnet 0:478cfd88041f 106 wnc = new WNC14A2AInterface;
group-Avnet 0:478cfd88041f 107 #endif
group-Avnet 0:478cfd88041f 108 }
group-Avnet 0:478cfd88041f 109 connect_success = wnc->connect();
group-Avnet 0:478cfd88041f 110 network_interface = wnc;
group-Avnet 0:478cfd88041f 111 #elif MBED_CONF_APP_NETWORK_INTERFACE == ETHERNET
group-Avnet 0:478cfd88041f 112 if (log_messages) {
group-Avnet 0:478cfd88041f 113 printf("[EasyConnect] Using Ethernet\n");
group-Avnet 0:478cfd88041f 114 }
group-Avnet 0:478cfd88041f 115 connect_success = eth.connect();
group-Avnet 0:478cfd88041f 116 network_interface = ð
group-Avnet 0:478cfd88041f 117 #endif
group-Avnet 0:478cfd88041f 118 #ifdef MESH
group-Avnet 0:478cfd88041f 119 if (log_messages) {
group-Avnet 0:478cfd88041f 120 printf("[EasyConnect] Using Mesh\n");
group-Avnet 0:478cfd88041f 121 printf("[EasyConnect] Connecting to Mesh..\n");
group-Avnet 0:478cfd88041f 122 }
group-Avnet 0:478cfd88041f 123 mesh.initialize(&rf_phy);
group-Avnet 0:478cfd88041f 124 connect_success = mesh.connect();
group-Avnet 0:478cfd88041f 125 network_interface = &mesh;
group-Avnet 0:478cfd88041f 126 #endif
group-Avnet 0:478cfd88041f 127 if(connect_success == 0) {
group-Avnet 0:478cfd88041f 128 if (log_messages) {
group-Avnet 0:478cfd88041f 129 printf("[EasyConnect] Connected to Network successfully\n");
group-Avnet 0:478cfd88041f 130 }
group-Avnet 0:478cfd88041f 131 } else {
group-Avnet 0:478cfd88041f 132 if (log_messages) {
group-Avnet 0:478cfd88041f 133 printf("[EasyConnect] Connection to Network Failed %d!\n", connect_success);
group-Avnet 0:478cfd88041f 134 }
group-Avnet 0:478cfd88041f 135 return NULL;
group-Avnet 0:478cfd88041f 136 }
group-Avnet 0:478cfd88041f 137 const char *ip_addr = network_interface->get_ip_address();
group-Avnet 0:478cfd88041f 138 const char *mac_addr = network_interface->get_mac_address();
group-Avnet 0:478cfd88041f 139 if (ip_addr == NULL) {
group-Avnet 0:478cfd88041f 140 if (log_messages) {
group-Avnet 0:478cfd88041f 141 printf("[EasyConnect] ERROR - No IP address\n");
group-Avnet 0:478cfd88041f 142 }
group-Avnet 0:478cfd88041f 143 return NULL;
group-Avnet 0:478cfd88041f 144 }
group-Avnet 0:478cfd88041f 145 if (mac_addr == NULL) {
group-Avnet 0:478cfd88041f 146 if (log_messages) {
group-Avnet 0:478cfd88041f 147 printf("[EasyConnect] ERROR - No MAC address\n");
group-Avnet 0:478cfd88041f 148 }
group-Avnet 0:478cfd88041f 149 return NULL;
group-Avnet 0:478cfd88041f 150 }
group-Avnet 0:478cfd88041f 151 if (log_messages) {
group-Avnet 0:478cfd88041f 152 printf("[EasyConnect] IP address %s\n", ip_addr);
group-Avnet 0:478cfd88041f 153 printf("[EasyConnect] MAC address %s\n", mac_addr);
group-Avnet 0:478cfd88041f 154 }
group-Avnet 0:478cfd88041f 155 return network_interface;
group-Avnet 0:478cfd88041f 156 }
group-Avnet 0:478cfd88041f 157
group-Avnet 0:478cfd88041f 158 #endif // __MAGIC_CONNECT_H__