![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Project aiming to do a Bluetooth Low Energy IoT devices, which measure temperature and humidity. Bluetooth achieved with the IDB05A1 shield. Temperature/humidity achieved with a DHT11 sensor. Project working, tested on an STM32 L476 board.
Dependencies: BLE_API X_NUCLEO_IDB0XA1 mbed
Diff: DHT11_BLEService.h
- Revision:
- 0:d2c18f736df1
- Child:
- 1:023e1eae2048
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DHT11_BLEService.h Fri Apr 07 11:36:47 2017 +0000 @@ -0,0 +1,49 @@ +#ifndef __BLE_DHT11_SERVICE_H__ +#define __BLE_DHT11_SERVICE_H__ + + +class DHT11Service { +public: + const static uint16_t DHT11_UUID = 0x2A61;//False UUID does not exists + const static uint16_t TEMPERATURE_CHARACTERISTIC_UUID = 0x2A6E; + const static uint16_t HUMIDITY_CHARACTERISTIC_UUID = 0x2A6F; + + DHT11Service(BLEDevice &_ble, uint8_t initialTempValue, uint8_t initialHumiValue) : + ble(_ble), + /*temperatureValue(TEMPERATURE_CHARACTERISTIC_UUID,&initialTempValue),*/ + temperatureValue(TEMPERATURE_CHARACTERISTIC_UUID, + &initialTempValue, + sizeof(uint32_t), + sizeof(uint32_t), + GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY), + humidityValue(HUMIDITY_CHARACTERISTIC_UUID, + &initialHumiValue, + sizeof(uint32_t), + sizeof(uint32_t), + GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) + /*humidityValue(HUMIDITY_CHARACTERISTIC_UUID,&initialHumiValue)*/ + { + GattCharacteristic *charTable[] = {&temperatureValue,&humidityValue}; + GattService service(DHT11_UUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *)); + ble.addService(service); + + } + + /*GattAttribute::Handle_t getValueHandle() const { + return temperatureValue.getValueHandle(); + }*/ + + void updateTemperatureValue(uint32_t value) { + ble.gattServer().write(temperatureValue.getValueHandle(), (uint8_t *)&value, sizeof(uint32_t)); + } + void updateHumidityValue(uint32_t value) { + ble.gattServer().write(humidityValue.getValueHandle(), (uint8_t *)&value, sizeof(uint32_t)); + } + +private: + BLEDevice &ble; + GattCharacteristic temperatureValue; + GattCharacteristic humidityValue; +}; + +#endif