this is using the mbed os version 5-13-1

Dependencies:   mbed-http

Revision:
77:0b505d1e15f4
Parent:
76:6afda865fbf8
Child:
78:07bb86e3ce14
--- a/source/BleManager.cpp	Fri Mar 15 14:26:44 2019 +0000
+++ b/source/BleManager.cpp	Fri Mar 15 23:25:30 2019 +0000
@@ -81,6 +81,11 @@
     /* to show we're running we'll blink every 500ms */
     _event_queue.call_every(500, this, &SMDevice::blink);
 
+    /* to show we're advertising we'll print status every minute */
+    _event_queue.call_every(60000, this, &SMDevice::reportGapState);
+
+
+
     if (_ble.hasInitialized()) {
         printf("Ble instance already initialised.\r\n");
         return;
@@ -105,9 +110,20 @@
     }
 
     /* this will not return until shutdown */
-    _event_queue.dispatch_forever();
+    //_event_queue.dispatch_forever();
 }
 
+
+void SMDevice::shutDown()
+{
+    if (_ble.hasInitialized()) {
+        _ble.shutdown();
+        printf("Shutting down BLE Instance...\r\n");
+        _event_queue.break_dispatch();
+    }
+}
+
+
 /* event handler functions */
 
 /** Respond to a pairing request. This will be called by the stack
@@ -246,7 +262,12 @@
 void SMDevice::on_disconnect(const Gap::DisconnectionCallbackParams_t *event)
 {
     printf("Disconnected\r\n");
+#ifndef DEMO_BLE_SECURITY
+    printf("Restarting advertising...\r\n");
+    _ble.gap().startAdvertising();
+#else
     _event_queue.break_dispatch();
+#endif
 }
 
 /** End demonstration unexpectedly. Called if timeout is reached during advertising,
@@ -310,6 +331,33 @@
 }
 
 
+void SMDevice::reportGapState()
+{
+     Gap::GapState_t gapState = _ble.gap().getState();
+     char connStr[20] = " Not Connected ";
+     char advStr[20] = " Not Advertising ";
+     char devName[20] = "";
+     if(gapState.advertising){
+         strncpy(advStr, " Advertising ", 20);
+     }
+     if(gapState.connected){
+         strncpy(connStr, " Connected ", 20);
+     }
+     printf("\n Advertising Status = %s\n Connection Status = %s\n", advStr, connStr);
+     unsigned nLen;
+     ble_error_t error;
+     error =  _ble.gap().getDeviceName((uint8_t *) devName, &nLen);
+     if(error != BLE_ERROR_NONE)
+     {
+        printf("\n Error Reading BLE device Name \n");
+        return;
+     }
+     devName[nLen] = NULL;
+     printf("\n BLE Device name = %s : Name Len %d\n", devName, nLen);
+     
+}
+
+
 /** A peripheral device will advertise, accept the connection and request
  * a change in link security. */
 SMDevicePeripheral::SMDevicePeripheral(BLE &ble, events::EventQueue &event_queue, BLEProtocol::AddressBytes_t &peer_address)
@@ -413,8 +461,38 @@
         printf("Error during SM::setLinkSecurity %d\r\n", error);
         return;
     }
+    printf("SM::setLinkSecurity setup\r\n");
 }
 
+void SMDevicePeripheral::stopAdvertising()
+{
+    if (_ble.hasInitialized()) {
+        ble_error_t error;
+        error = _ble.gap().stopAdvertising();;
+        if(error){
+            printf(" Error stopping advertising...\r\n");
+            return;
+        }
+        printf("Stopping advertising...\r\n");
+        //_event_queue.break_dispatch();
+    }
+}
+void SMDevicePeripheral::startAdvertising()
+{
+    if (_ble.hasInitialized()) {
+        ble_error_t error;
+        error = _ble.gap().startAdvertising();
+        if(error){
+            printf(" Error Restarting advertising...\r\n");
+            return;
+        }
+        printf("Restarting advertising...\r\n");
+        //_event_queue.break_dispatch();
+    }
+}
+
+
+
 /** A central device will scan, connect to a peer and request pairing. */
 
 SMDeviceCentral::SMDeviceCentral(BLE &ble, events::EventQueue &event_queue, BLEProtocol::AddressBytes_t &peer_address)