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
ESS.h
00001 /* ARM University Program Microcontroller Library 00002 * 00003 * Environmental Sensing Service 00004 * 00005 * This software is distributed under an "AS IS" BASIS, 00006 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00007 */ 00008 00009 #ifndef __BLE_ENVIRONMENTAL_SENSING_SERVICE_H__ 00010 #define __BLE_ENVIRONMENTAL_SENSING_SERVICE_H__ 00011 00012 #include <mbed.h> 00013 #include "blecommon.h" 00014 #include "Gap.h" 00015 #include "GattServer.h" 00016 #include "BLEDeviceInstanceBase.h" 00017 00018 //#include "BLEDevice.h" 00019 00020 /* Environmental Sensing Service */ 00021 /* Service: https://developer.bluetooth.org/gatt/services/Pages/ServiceViewer.aspx?u=org.bluetooth.service.environmental_sensing.xml */ 00022 /* Humidity characteristic: https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.humidity.xml */ 00023 /* Temperature: https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.temperature.xml */ 00024 00025 class EnvironmentalSensingService { 00026 00027 public: 00028 /** 00029 * Constructor. 00030 * 00031 * param[in] _ble 00032 * Reference to the underlying BLEDevice. 00033 * param[in] humidity percentage (16-bit unsigned, 2 decimals). 00034 * initial value for the humidity value. 00035 * param[in] temperature in degrees Celsius (16-bit signed, 2 decimals). 00036 * initial value for the temperature 00037 */ 00038 EnvironmentalSensingService(BLEDevice &_ble, uint16_t humidity, int16_t temperature) : 00039 ble(_ble), 00040 00041 humiditychar(GattCharacteristic::UUID_HUMIDITY_CHAR, (uint8_t *)&humidity, 00042 sizeof(uint16_t), sizeof(uint16_t), 00043 GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY), 00044 00045 temperaturechar(GattCharacteristic::UUID_TEMPERATURE_CHAR, (uint8_t *)&temperature, 00046 sizeof(int16_t), sizeof(int16_t), 00047 GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) 00048 00049 00050 { // Setup Service 00051 00052 GattCharacteristic *charTable[] = {&humiditychar, &temperaturechar, }; // 2 services. humidity and temp 00053 00054 GattService EnvironmentalService(0x181A, charTable, sizeof(charTable) / sizeof(GattCharacteristic *)); 00055 00056 ble.gattServer().addService(EnvironmentalService); 00057 } 00058 00059 00060 /* Set a new 16-bit value for the humidity measurement. */ 00061 void updateHumidity(uint16_t humidity) { 00062 ble.gattServer().write(humiditychar.getValueAttribute().getHandle(), (uint8_t *)&humidity, sizeof(uint16_t)); 00063 } 00064 00065 /* Set a new 16-bit value for the temperature measurement. */ 00066 void updateTemperature(int16_t temperature) { 00067 ble.gattServer().write(temperaturechar.getValueAttribute().getHandle(), (uint8_t *)&temperature, sizeof(int16_t)); 00068 } 00069 00070 00071 00072 private: 00073 BLEDevice &ble; 00074 GattCharacteristic humiditychar; 00075 GattCharacteristic temperaturechar; 00076 00077 }; 00078 00079 #endif /* #ifndef __BLE_ENVIRONMENTAL_SENSING_SERVICE_H__*/ 00080 00081 00082 // *******************************ARM University Program Copyright © ARM Ltd 2015*************************************//
Generated on Sun Aug 7 2022 14:13:24 by
1.7.2