A nice BLE demo program which allows remote switch of an LED via GATT interface.

Dependencies:   BLE_API mbed nRF51822

Fork of BLE_Button by Bluetooth Low Energy

Committer:
hux
Date:
Sat Oct 21 19:56:15 2017 +0000
Revision:
13:0563f1aa6a75
Parent:
12:0d0ca44397dd
Switch LED via BLE GATT

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hux 12:0d0ca44397dd 1 // init.h - initialize BLE system
hux 12:0d0ca44397dd 2 //
hux 12:0d0ca44397dd 3 // Synopsis:
hux 12:0d0ca44397dd 4 //
hux 12:0d0ca44397dd 5 // void init(Blob &o, void (*scb)(Blob&),void (*ecb)(Blob&)) // init BLE
hux 12:0d0ca44397dd 6 // void init(Blob &o, void (*scb)(Blob&)) // init BLE
hux 12:0d0ca44397dd 7 //
hux 12:0d0ca44397dd 8 // Arguments:
hux 12:0d0ca44397dd 9 //
hux 12:0d0ca44397dd 10 // o: Blob object (to avoid name clashes)
hux 12:0d0ca44397dd 11 // scb: setup callback
hux 12:0d0ca44397dd 12 // ecb: error callback
hux 12:0d0ca44397dd 13 //
hux 12:0d0ca44397dd 14 // Description:
hux 12:0d0ca44397dd 15 //
hux 12:0d0ca44397dd 16 // Initialize BLE system, providing a setup callback and optionally an error
hux 12:0d0ca44397dd 17 // callback. The actual initializing happens in the setup callback. If an
hux 12:0d0ca44397dd 18 // error occurs during initializin, the error callback will be consulted. If
hux 12:0d0ca44397dd 19 // no error callback is provided an implicit error callback will be called.
hux 12:0d0ca44397dd 20 //
hux 12:0d0ca44397dd 21 // Example 1: simple BLE system setup
hux 12:0d0ca44397dd 22 //
hux 12:0d0ca44397dd 23 // void cbSetup(Blob &o)
hux 12:0d0ca44397dd 24 // {
hux 12:0d0ca44397dd 25 // device(o,"IoT node"); // setup device name
hux 12:0d0ca44397dd 26 // name(o,"Node #1"); // setup advertising name
hux 12:0d0ca44397dd 27 // advertise("C:ng"); // start advertising
hux 12:0d0ca44397dd 28 // }
hux 12:0d0ca44397dd 29 //
hux 12:0d0ca44397dd 30 // main(void)
hux 12:0d0ca44397dd 31 // {
hux 12:0d0ca44397dd 32 // Blob o; // our Blob object
hux 12:0d0ca44397dd 33 // init(o,cbSetup); // init BLE base layer, always do first
hux 12:0d0ca44397dd 34 // while (true) // Infinite loop waiting for BLE events
hux 12:0d0ca44397dd 35 // sleep(o); // low energy waiting
hux 12:0d0ca44397dd 36 // }
hux 12:0d0ca44397dd 37 //
hux 12:0d0ca44397dd 38 // Example 2: Provide also error handler
hux 12:0d0ca44397dd 39 //
hux 12:0d0ca44397dd 40 // void cbError(Blob &o)
hux 12:0d0ca44397dd 41 // {
hux 12:0d0ca44397dd 42 // trace(0,"init error!");
hux 12:0d0ca44397dd 43 // }
hux 12:0d0ca44397dd 44 //
hux 12:0d0ca44397dd 45 // void cbSetup(Blob &o)
hux 12:0d0ca44397dd 46 // {
hux 12:0d0ca44397dd 47 // device(o,"IoT node"); // setup device name
hux 12:0d0ca44397dd 48 // name(o,"Node #1"); // setup advertising name
hux 12:0d0ca44397dd 49 // advertise("C:ng"); // start advertising
hux 12:0d0ca44397dd 50 // }
hux 12:0d0ca44397dd 51 //
hux 12:0d0ca44397dd 52 // main(void)
hux 12:0d0ca44397dd 53 // {
hux 12:0d0ca44397dd 54 // Blob o; // our Blob object
hux 12:0d0ca44397dd 55 // init(o,cbSetup,cbError); // init BLE base layer, always do first
hux 12:0d0ca44397dd 56 // while (true) // Infinite loop waiting for BLE events
hux 12:0d0ca44397dd 57 // sleep(o); // low energy waiting
hux 12:0d0ca44397dd 58 // }
hux 12:0d0ca44397dd 59 //
hux 12:0d0ca44397dd 60 // See also: BLOB, INIT
hux 12:0d0ca44397dd 61 //
hux 12:0d0ca44397dd 62 #ifndef _INIT_H_
hux 12:0d0ca44397dd 63 #define _INIT_H_
hux 12:0d0ca44397dd 64
hux 12:0d0ca44397dd 65 #include "bricks/o.h"
hux 12:0d0ca44397dd 66
hux 12:0d0ca44397dd 67 //==============================================================================
hux 12:0d0ca44397dd 68 // Initializing
hux 12:0d0ca44397dd 69 //==============================================================================
hux 12:0d0ca44397dd 70
hux 12:0d0ca44397dd 71 void init(O&o, void (*scb)(O&o),void (*ecb)(O&o)); // init BLE
hux 12:0d0ca44397dd 72 void init(O&o, void (*scb)(O&o)); // init BLE system
hux 12:0d0ca44397dd 73
hux 12:0d0ca44397dd 74 #endif // _INIT_H_