This is an example based on mbed-os cellular APIs that demonstrates a TCP or UDP echo transaction with a public echo server.

Revision:
52:46406cd9c64a
Parent:
42:cab443dff75e
Child:
53:52be2af62919
--- a/main.cpp	Wed Dec 25 16:18:24 2019 +0000
+++ b/main.cpp	Thu Jan 30 06:49:19 2020 +0000
@@ -15,6 +15,7 @@
  */
 
 #include "mbed.h"
+#include "rtos.h"
 #include "common_functions.h"
 #include "CellularNonIPSocket.h"
 #include "CellularDevice.h"
@@ -28,6 +29,23 @@
 // Number of retries /
 #define RETRY_COUNT 3
 
+void BG96_Modem_PowerON(void)
+{
+    DigitalIn BG96_STATUS(D2);
+    DigitalOut BG96_PWRKEY(D3);
+
+    ThisThread::sleep_for(50);
+    BG96_PWRKEY = 1;
+    ThisThread::sleep_for(600);
+    BG96_PWRKEY = 0;
+    ThisThread::sleep_for(5000);
+    
+    if(BG96_STATUS)
+        printf("Module Power On~~\r\n");
+    else
+        printf("Check Module Power Line!!\r\n");        
+}
+
 NetworkInterface *iface;
 
 // Echo server hostname
@@ -244,6 +262,9 @@
 #endif
 
     print_function("Establishing connection\n");
+    
+    BG96_Modem_PowerON();
+    
 #if MBED_CONF_MBED_TRACE_ENABLE
     trace_open();
 #else