IoTKitV3 / IoTKit

Dependencies:   wifi-ism43362

Dependents:   DigitalOut DigitalOut

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers network-helper.h Source File

network-helper.h

00001 #ifndef __NETWORK_HELPER_H_
00002 #define _NETWORK_HELPER_H_
00003 
00004 #include "mbed.h"
00005 
00006 #ifdef TARGET_K64F
00007 #include "ESP8266Interface.h"
00008 ESP8266Interface wifi(MBED_CONF_APP_WIFI_TX, MBED_CONF_APP_WIFI_RX);
00009 #endif
00010 
00011 #ifdef TARGET_DISCO_L475VG_IOT01A
00012 #include "ISM43362Interface.h"
00013 ISM43362Interface wifi( false );
00014 #endif
00015 
00016 #if defined( TARGET_NUCLEO_F303RE  ) || defined( TARGET_NUCLEO_F411RE ) || defined( TARGET_NUCLEO_F103RB )
00017 #include "ESP8266Interface.h"
00018 ESP8266Interface wifi( MBED_CONF_IOTKIT_ESP8266_TX, MBED_CONF_IOTKIT_ESP8266_RX );
00019 #endif
00020 
00021 /**
00022  * Connect to the network using the default networking interface,
00023  * you can also swap this out with a driver for a different networking interface
00024  * if you use WiFi: see mbed_app.json for the credentials
00025  */
00026 NetworkInterface *connect_to_default_network_interface() 
00027 {
00028     printf("[NWKH] Connecting to network...\n");
00029 
00030 #ifdef TARGET_NUCLEO_F746ZG
00031     NetworkInterface* network = NetworkInterface::get_default_instance();
00032     nsapi_error_t connect_status = network->connect();
00033 #else
00034     NetworkInterface* network = &wifi;
00035     nsapi_error_t connect_status = wifi.connect(MBED_CONF_APP_WIFI_SSID, MBED_CONF_APP_WIFI_PASSWORD, NSAPI_SECURITY_WPA_WPA2);
00036 #endif 
00037 
00038     if (connect_status != NSAPI_ERROR_OK) 
00039     {
00040         printf("[NWKH] Failed to connect to network (%d)\n", connect_status);
00041         return NULL;
00042     }
00043 
00044     printf("[NWKH] Connected to the network\n");
00045     printf("[NWKH] IP address: %s\n", network->get_ip_address());
00046     return network;
00047 }
00048 
00049 #endif _NETWORK_HELPER_H_