A cute tiny piece of code implementing an IoT NAND device, demonstrating how to setup and advertise a cute GATT (NAND) service. The code has been tested on a Nordic nRF51822-DK.

Dependencies:   BLE_API mbed nRF51822

Fork of BLE_HeartRate_IDB0XA1 by ST

Revision:
26:dce30a5341bb
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bricks/init.h	Sat May 19 14:10:17 2018 +0000
@@ -0,0 +1,90 @@
+// init.h - initialize BLE system
+//
+// Synopsis:
+//
+//    void init(Blob &o, void (*scb)(Blob&),void (*ecb)(Blob&))  // init BLE
+//    void init(Blob &o, void (*scb)(Blob&))                     // init BLE
+//
+// Arguments:
+//
+//    o:        Blob object (to avoid name clashes)
+//    scb:      setup callback
+//    ecb:      error callback
+//
+// Description:
+//
+//    Initialize BLE system, providing a setup callback and optionally an error
+//    callback. The actual initializing happens in the setup callback. If an
+//    error occurs during initializin, the error callback will be consulted. If
+//    no error callback is provided an implicit error callback will be called.
+//
+// Example 1: simple BLE system setup
+//
+//    void cbSetup(Blob &o)
+//    {
+//       device(o,"IoT node");         // setup device name
+//       name(o,"Node #1");            // setup advertising name
+//       advertise("C:ng");            // start advertising
+//    }
+//
+//    main(void)
+//    {
+//       Blob o;                       // our Blob object
+//       init(o,cbSetup);              // init BLE base layer, always do first
+//       while (true)                  // Infinite loop waiting for BLE events
+//          sleep(o);                  // low energy waiting
+//    }
+//
+// Example 2: Provide also error handler
+//
+//    void cbError(Blob &o)
+//    {
+//       trace(0,"init error!");    
+//    }
+//
+//    void cbSetup(Blob &o)
+//    {
+//       device(o,"IoT node");         // setup device name
+//       name(o,"Node #1");            // setup advertising name
+//       advertise("C:ng");            // start advertising
+//    }
+//
+//    main(void)
+//    {
+//       Blob o;                       // our Blob object
+//       init(o,cbSetup,cbError);      // init BLE base layer, always do first
+//       while (true)                  // Infinite loop waiting for BLE events
+//          sleep(o);                  // low energy waiting
+//    }
+//
+// Example 3: Without Callbacks (busy waiting until initialized)
+//
+//    main(void)
+//    {
+//       Blob o;                       // our Blob object
+//       init(o);                      // init BLE base layer, always do first
+//
+//       device(o,"IoT node");         // setup device name
+//       name(o,"Node #1");            // setup advertising name
+//       advertise("C:ng");            // start advertising
+//
+//       while (true)                  // Infinite loop waiting for BLE events
+//          sleep(o);                  // low energy waiting
+//    }
+//
+// See also: BLOB, INIT
+//
+#ifndef _INIT_H_
+#define _INIT_H_
+
+#include "bricks/o.h"
+
+//==============================================================================
+// Initializing
+//==============================================================================
+
+   void init(O&o, void (*scb)(O&o),void (*ecb)(O&o));  // init BLE system
+   void init(O&o, void (*scb)(O&o));                   // init BLE system
+   void init(O&o);                                     // init BLE system
+
+#endif // _INIT_H_
\ No newline at end of file