Reading and sending sensor data over BLE

Dependencies:   BSP_B-L475E-IOT01

Committer:
Vincent Coubard
Date:
Tue Jul 26 14:47:19 2016 +0100
Revision:
0:c6a8f2b3efb6
Child:
2:864ddfb70a9c
Update example at tag mbed-os-5.0.1-rc1

Who changed what in which revision?

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