Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed-http
Diff: source/network-helper.h
- Revision:
- 32:5fa61ebc2689
- Parent:
- 31:66704f6f17c5
- Child:
- 35:4b847971db1b
diff -r 5ad8f931e4ff -r 5fa61ebc2689 source/network-helper.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/source/network-helper.h Tue Oct 30 11:07:46 2018 +0800
@@ -0,0 +1,35 @@
+#ifndef _MBED_HTTP_EXAMPLE_H_
+#define _MBED_HTTP_EXAMPLE_H_
+
+#include "mbed.h"
+#ifdef TARGET_SIMULATOR
+#include "EthernetInterface.h"
+#endif
+
+/**
+ * Connect to the network using the default networking interface,
+ * you can also swap this out with a driver for a different networking interface
+ * if you use WiFi: see mbed_app.json for the credentials
+ */
+NetworkInterface *connect_to_default_network_interface() {
+ printf("[NWKH] Connecting to network...\n");
+
+#ifdef TARGET_SIMULATOR
+ NetworkInterface* network = new EthernetInterface();
+#else
+ NetworkInterface* network = NetworkInterface::get_default_instance();
+#endif
+
+ nsapi_error_t connect_status = network->connect();
+
+ if (connect_status != NSAPI_ERROR_OK) {
+ printf("[NWKH] Failed to connect to network (%d)\n", connect_status);
+ return NULL;
+ }
+
+ printf("[NWKH] Connected to the network\n");
+ printf("[NWKH] IP address: %s\n", network->get_ip_address());
+ return network;
+}
+
+#endif // _MBED_HTTP_EXAMPLE_H_