An example hot to register a network connection state change callback. Possible state changes are listed on the example.

Supported in Mbed OS version 5.8

Revision:
0:bc6951bb0712
Child:
3:a0e64683327b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Feb 06 07:27:48 2018 +0000
@@ -0,0 +1,43 @@
+
+#include "EthernetInterface.h"
+#include "mbed.h"
+#include "nsapi_types.h"
+
+// Network interface
+EthernetInterface eth;
+
+void status_callback(nsapi_event_t status, intptr_t param)
+{
+    printf("Connection status changed!\r\n");
+    switch(param) {
+        case NSAPI_STATUS_LOCAL_UP:
+            printf("Local IP address set!\r\n");
+            break;
+        case NSAPI_STATUS_GLOBAL_UP:
+            printf("Global IP address set!\r\n");
+            break;
+        case NSAPI_STATUS_DISCONNECTED:
+            printf("No connection to network!\r\n");
+            break;
+        case NSAPI_STATUS_CONNECTING:
+            printf("Connecting to network!\r\n");
+            break;
+        default:
+            printf("Not supported");
+            break;
+    }
+}
+
+int main()
+{
+    printf("Status callback example!\r\n");
+
+    eth.attach(&status_callback);
+    printf("Connecting...\n");
+    eth.connect();
+    wait(10);
+    printf("Disconnect\n");
+    eth.disconnect();
+
+    printf("Done\n");
+}
\ No newline at end of file