This example demonstrates using the GattClient API to control BLE client devices. The canonical source for this example lives at https://github.com/ARMmbed/mbed-os-example-ble/tree/master/BLE_LEDBlinker

Committer:
sayhuthut
Date:
Thu Mar 07 09:38:15 2019 +0000
Revision:
81:816977af0b75
This an example show Central and Peripheral working concurrently.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sayhuthut 81:816977af0b75 1 /* mbed Microcontroller Library
sayhuthut 81:816977af0b75 2 * Copyright (c) 2006-2013 ARM Limited
sayhuthut 81:816977af0b75 3 *
sayhuthut 81:816977af0b75 4 * Licensed under the Apache License, Version 2.0 (the "License");
sayhuthut 81:816977af0b75 5 * you may not use this file except in compliance with the License.
sayhuthut 81:816977af0b75 6 * You may obtain a copy of the License at
sayhuthut 81:816977af0b75 7 *
sayhuthut 81:816977af0b75 8 * http://www.apache.org/licenses/LICENSE-2.0
sayhuthut 81:816977af0b75 9 *
sayhuthut 81:816977af0b75 10 * Unless required by applicable law or agreed to in writing, software
sayhuthut 81:816977af0b75 11 * distributed under the License is distributed on an "AS IS" BASIS,
sayhuthut 81:816977af0b75 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
sayhuthut 81:816977af0b75 13 * See the License for the specific language governing permissions and
sayhuthut 81:816977af0b75 14 * limitations under the License.
sayhuthut 81:816977af0b75 15 */
sayhuthut 81:816977af0b75 16
sayhuthut 81:816977af0b75 17 #ifndef __BLE_LED_SERVICE_H__
sayhuthut 81:816977af0b75 18 #define __BLE_LED_SERVICE_H__
sayhuthut 81:816977af0b75 19
sayhuthut 81:816977af0b75 20 class LEDService {
sayhuthut 81:816977af0b75 21 public:
sayhuthut 81:816977af0b75 22 const static uint16_t LED_SERVICE_UUID = 0xA000;
sayhuthut 81:816977af0b75 23 const static uint16_t LED_STATE_CHARACTERISTIC_UUID = 0xA001;
sayhuthut 81:816977af0b75 24
sayhuthut 81:816977af0b75 25 LEDService(BLEDevice &_ble, bool initialValueForLEDCharacteristic) :
sayhuthut 81:816977af0b75 26 ble(_ble), ledState(LED_STATE_CHARACTERISTIC_UUID, &initialValueForLEDCharacteristic)
sayhuthut 81:816977af0b75 27 {
sayhuthut 81:816977af0b75 28 GattCharacteristic *charTable[] = {&ledState};
sayhuthut 81:816977af0b75 29 GattService ledService(LED_SERVICE_UUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *));
sayhuthut 81:816977af0b75 30
sayhuthut 81:816977af0b75 31 ble.gattServer().addService(ledService);
sayhuthut 81:816977af0b75 32 }
sayhuthut 81:816977af0b75 33
sayhuthut 81:816977af0b75 34 GattAttribute::Handle_t getValueHandle() const
sayhuthut 81:816977af0b75 35 {
sayhuthut 81:816977af0b75 36 return ledState.getValueHandle();
sayhuthut 81:816977af0b75 37 }
sayhuthut 81:816977af0b75 38
sayhuthut 81:816977af0b75 39 private:
sayhuthut 81:816977af0b75 40 BLEDevice &ble;
sayhuthut 81:816977af0b75 41 ReadWriteGattCharacteristic<bool> ledState;
sayhuthut 81:816977af0b75 42 };
sayhuthut 81:816977af0b75 43
sayhuthut 81:816977af0b75 44 #endif /* #ifndef __BLE_LED_SERVICE_H__ */