The easy-connect library for GR-PEACH.
Dependencies: LWIPBP3595Interface_STA_for_mbed-os
Dependents: GR-PEACH_HVC-P2_sample_client GR-PEACH_HVC-P2_IoTPlatform_http GR-PEACH_IoT_Platform_HTTP_sample
Specifying connectivity method
Add the following to your mbed_app.json file:
mbed_app.json
{ "config": { "network-interface":{ "help": "Options are ETHERNET, WIFI_ESP8266, WIFI_BP3595", "value": "ETHERNET" } } }
To specify MAC address, add fllowing function to main.cpp. (When using Wifi, setting of MAC address is not necessary.)
Specify MAC address
// set mac address void mbed_mac_address(char *mac) { mac[0] = 0x00; mac[1] = 0x02; mac[2] = 0xF7; mac[3] = 0xF0; mac[4] = 0x00; mac[5] = 0x00; }
Wifi settings
If you choose BP3595, you'll also need to add the WiFi SSID, password and security type:
mbed_app.json
{ "config": { "network-interface":{ "help": "Options are ETHERNET, WIFI_ESP8266, WIFI_BP3595", "value": "WIFI_BP3595" }, "wifi-ssid": { "help": "WiFi SSID", "value": "\"SSID\"" }, "wifi-password": { "help": "WIFI Password", "value": "\"Password\"" }, "wifi-security":{ "help": "Options are NSAPI_SECURITY_WEP, NSAPI_SECURITY_WPA, NSAPI_SECURITY_WPA2, NSAPI_SECURITY_WPA_WPA2", "value": "NSAPI_SECURITY_WPA_WPA2" } } }
Using Easy Connect from your application
Easy Connect has just one function which will either return a NetworkInterface-pointer or NULL:
main.cpp
#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 }
Diff: easy-connect.h
- Revision:
- 1:adf177867e43
- Parent:
- 0:77c289709567
--- a/easy-connect.h Wed Mar 08 07:17:06 2017 +0000 +++ b/easy-connect.h Tue Mar 14 05:41:15 2017 +0000 @@ -37,6 +37,9 @@ #define MBED_CONF_APP_WIFI_PASSWORD MBED_CONF_APP_ESP8266_PASSWORD #endif +#ifndef MBED_CONF_APP_WIFI_SECURITY +#define MBED_CONF_APP_WIFI_SECURITY NSAPI_SECURITY_WPA_WPA2 +#endif NetworkInterface* easy_connect(bool log_messages = false) { NetworkInterface* network_interface = 0; @@ -46,14 +49,14 @@ printf("[EasyConnect] Using WiFi (ESP8266) \n"); printf("[EasyConnect] Connecting to WiFi %s\n", MBED_CONF_APP_WIFI_SSID); } - connect_success = wifi.connect(MBED_CONF_APP_WIFI_SSID, MBED_CONF_APP_WIFI_PASSWORD, NSAPI_SECURITY_WPA_WPA2); + connect_success = wifi.connect(MBED_CONF_APP_WIFI_SSID, MBED_CONF_APP_WIFI_PASSWORD, MBED_CONF_APP_WIFI_SECURITY); network_interface = &wifi; #elif MBED_CONF_APP_NETWORK_INTERFACE == WIFI_BP3595 if (log_messages) { printf("[EasyConnect] Using WiFi (BP3595) \n"); printf("[EasyConnect] Connecting to WiFi %s\n", MBED_CONF_APP_WIFI_SSID); } - connect_success = wifi.connect(MBED_CONF_APP_WIFI_SSID, MBED_CONF_APP_WIFI_PASSWORD, NSAPI_SECURITY_WPA_WPA2); + connect_success = wifi.connect(MBED_CONF_APP_WIFI_SSID, MBED_CONF_APP_WIFI_PASSWORD, MBED_CONF_APP_WIFI_SECURITY); network_interface = &wifi; #elif MBED_CONF_APP_NETWORK_INTERFACE == ETHERNET if (log_messages) {