Experimental BLE Blinky Application using a LED and button service server. This is a small custom service that is used to toggle LEDs and receive button status from wirelessly connected Bluetooth Smart development boards.

For information on the GATT service UUID, characteristic UUIDs, or what to expect when manipulating them, please refer to:

http://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk5.v13.0.0%2Fble_sdk_app_blinky.html http://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk5.v11.0.0%2Fgroup__ble__sdk__srv__lbs.html http://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk5.v11.0.0%2Fgroup__ble__sdk__srv__lbs__c.html

Good luck with that.

For an easy 5 minute tour of how Bluetooth Smart works, program a developer kit (nRF52-DK for example) with this application. Once it starts to run it will indicate advertising by blinking LED1. At this time, install a corresponding client application like the nRF Blinky Android app [1] and watch it detect the developer kit. Click on the 'Lightsw' identifier to connect with the GATT service and wait until the developer kit LED1 stops blinking to indicate a connected state. Now, illuminate LED2 by clicking on the lightbulb. Pressing one of the developer kit's buttons will cause the Android app's background to illuminate illustrating bidirectional communication over Bluetooth Smart.

[1] https://play.google.com/store/apps/details?id=no.nordicsemi.android.nrfblinky

Committer:
michaesc
Date:
Tue Mar 28 15:57:46 2017 +0000
Revision:
2:204381095967
Implemented Blinkyserv class and GATT derived service and characteristic logic.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
michaesc 2:204381095967 1 /* Blinky service application
michaesc 2:204381095967 2 *
michaesc 2:204381095967 3 * Licensed under the Apache License, Version 2.0 (the "License");
michaesc 2:204381095967 4 * you may not use this file except in compliance with the License.
michaesc 2:204381095967 5 * You may obtain a copy of the License at
michaesc 2:204381095967 6 *
michaesc 2:204381095967 7 * http://www.apache.org/licenses/LICENSE-2.0
michaesc 2:204381095967 8 *
michaesc 2:204381095967 9 * Unless required by applicable law or agreed to in writing, software
michaesc 2:204381095967 10 * distributed under the License is distributed on an "AS IS" BASIS,
michaesc 2:204381095967 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
michaesc 2:204381095967 12 * See the License for the specific language governing permissions and
michaesc 2:204381095967 13 * limitations under the License.
michaesc 2:204381095967 14 */
michaesc 2:204381095967 15
michaesc 2:204381095967 16 #ifndef __BLE_BUTLED_SERVICE_H__
michaesc 2:204381095967 17 #define __BLE_BUTLED_SERVICE_H__
michaesc 2:204381095967 18
michaesc 2:204381095967 19 class Blinkyserv {
michaesc 2:204381095967 20 public:
michaesc 2:204381095967 21 // These are stale UUIDs, not corresponding to Nordic
michaesc 2:204381095967 22 //const static uint16_t LED_SERVICE_UUID = 0xA002;
michaesc 2:204381095967 23 //const static uint16_t LED_STATE_CHARACTERISTIC_UUID = 0xA004;
michaesc 2:204381095967 24 //const static uint16_t BUT_STATE_CHARACTERISTIC_UUID = 0xA005;
michaesc 2:204381095967 25
michaesc 2:204381095967 26 // https://github.com/NordicSemiconductor/Android-nRF-Blinky/tree/master/app/src/main/java/no/nordicsemi/android/blinky/service/BlinkyManager.java
michaesc 2:204381095967 27 // BaseUUID = {0x23, 0xd1, 0xbc, 0xea, 0x5f, 0x78, 0x23, 0x15, 0xde, 0xef, 0x12, 0x12, 0x23, 0x15, 0x00, 0x00};
michaesc 2:204381095967 28 //const static UUID *LED_SERVICE_UUID = new UUID("00001523-1212-efde-1523-785feabcd123");
michaesc 2:204381095967 29 //std::shared_ptr<UUID> LED_SERVICE_UUID;
michaesc 2:204381095967 30 const UUID *LED_SERVICE_UUID;
michaesc 2:204381095967 31
michaesc 2:204381095967 32 Blinkyserv(BLEDevice &_ble, bool initialValueForLEDCharacteristic, bool initialValueForButCharacteristic) :
michaesc 2:204381095967 33 ble(_ble), ledState(UUID("00001525-1212-efde-1523-785feabcd123"), &initialValueForLEDCharacteristic),
michaesc 2:204381095967 34 butState(UUID("00001524-1212-efde-1523-785feabcd123"), &initialValueForButCharacteristic, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY)
michaesc 2:204381095967 35 {
michaesc 2:204381095967 36 // Service definition logic
michaesc 2:204381095967 37 GattCharacteristic *charTable[] = {&ledState, &butState};
michaesc 2:204381095967 38 LED_SERVICE_UUID = new UUID("00001523-1212-efde-1523-785feabcd123");
michaesc 2:204381095967 39
michaesc 2:204381095967 40 GattService GATTServ(static_cast<UUID>(*LED_SERVICE_UUID), charTable, sizeof(charTable) / sizeof(GattCharacteristic *));
michaesc 2:204381095967 41 ble.addService(GATTServ);
michaesc 2:204381095967 42 }
michaesc 2:204381095967 43
michaesc 2:204381095967 44 // FIXME: Does this need a butState equivalent?
michaesc 2:204381095967 45 GattAttribute::Handle_t getValueHandle() const {
michaesc 2:204381095967 46 return ledState.getValueHandle();
michaesc 2:204381095967 47 }
michaesc 2:204381095967 48
michaesc 2:204381095967 49 void updateButtonState(bool newState) { // Sets button state characteristic appropriately
michaesc 2:204381095967 50 //ble.gattServer().write(butState.getValueHandle(), (uint8_t *)&newState, sizeof(bool));
michaesc 2:204381095967 51 ble.updateCharacteristicValue(butState.getValueHandle(), (uint8_t *)&newState, sizeof(bool));
michaesc 2:204381095967 52 }
michaesc 2:204381095967 53
michaesc 2:204381095967 54 private:
michaesc 2:204381095967 55 BLEDevice &ble;
michaesc 2:204381095967 56 ReadWriteGattCharacteristic<bool> ledState;
michaesc 2:204381095967 57 ReadOnlyGattCharacteristic<bool> butState;
michaesc 2:204381095967 58 ~Blinkyserv() {
michaesc 2:204381095967 59 delete LED_SERVICE_UUID;
michaesc 2:204381095967 60 }
michaesc 2:204381095967 61 };
michaesc 2:204381095967 62
michaesc 2:204381095967 63 #endif /* #ifndef __BLE_BUTLED_SERVICE_H__ */