Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: X_NUCLEO_IKS01A2
Diff: source/ESS.h
- Revision:
- 0:9c0e0ac79e75
- Child:
- 1:b12ac7b02a21
diff -r 000000000000 -r 9c0e0ac79e75 source/ESS.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/source/ESS.h Wed Apr 29 10:42:44 2020 +0000 @@ -0,0 +1,82 @@ +/* ARM University Program Microcontroller Library + * + * Environmental Sensing Service + * + * This software is distributed under an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + */ + +#ifndef __BLE_ENVIRONMENTAL_SENSING_SERVICE_H__ +#define __BLE_ENVIRONMENTAL_SENSING_SERVICE_H__ + +#include "mbed.h" +#include "blecommon.h" +#include "Gap.h" +#include "GattServer.h" +#include "BLEDeviceInstanceBase.h" + +//#include "BLEDevice.h" + +/* Environmental Sensing Service */ +/* Service: https://developer.bluetooth.org/gatt/services/Pages/ServiceViewer.aspx?u=org.bluetooth.service.environmental_sensing.xml */ +/* Humidity characteristic: https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.humidity.xml */ +/* Temperature: https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.temperature.xml */ + +class EnvironmentalSensingService { + +public: + /** + * Constructor. + * + * param[in] _ble + * Reference to the underlying BLEDevice. + * param[in] humidity percentage (16-bit unsigned, 2 decimals). + * initial value for the humidity value. + * param[in] temperature in degrees Celsius (16-bit signed, 2 decimals). + * initial value for the temperature + */ + EnvironmentalSensingService(BLEDevice &_ble, uint16_t humidity, int16_t temperature) : + ble(_ble), + + humiditychar(GattCharacteristic::UUID_HUMIDITY_CHAR, (uint8_t *)&humidity, + sizeof(uint16_t), sizeof(uint16_t), + GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY), + + temperaturechar(GattCharacteristic::UUID_TEMPERATURE_CHAR, (uint8_t *)&temperature, + sizeof(int16_t), sizeof(int16_t), + GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) + + + { // Setup Service + + GattCharacteristic *charTable[] = {&humiditychar, &temperaturechar, }; // 2 services. humidity and temp + + GattService EnvironmentalService(0x181A, charTable, sizeof(charTable) / sizeof(GattCharacteristic *)); + + ble.addService(EnvironmentalService); + } + + + /* Set a new 16-bit value for the humidity measurement. */ + void updateHumidity(uint16_t humidity) { + ble.updateCharacteristicValue(humiditychar.getValueAttribute().getHandle(), (uint8_t *)&humidity, sizeof(uint16_t)); + } + + /* Set a new 16-bit value for the temperature measurement. */ + void updateTemperature(int16_t temperature) { + ble.updateCharacteristicValue(temperaturechar.getValueAttribute().getHandle(), (uint8_t *)&temperature, sizeof(int16_t)); + } + + + +private: + BLEDevice &ble; + GattCharacteristic humiditychar; + GattCharacteristic temperaturechar; + +}; + +#endif /* #ifndef __BLE_ENVIRONMENTAL_SENSING_SERVICE_H__*/ + + +// *******************************ARM University Program Copyright © ARM Ltd 2015*************************************//