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

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers DHT11_BLEService.h Source File

DHT11_BLEService.h

00001 #ifndef __BLE_DHT11_SERVICE_H__
00002 #define __BLE_DHT11_SERVICE_H__
00003 
00004 
00005 class DHT11Service {
00006 public:
00007     const static uint16_t DHT11_UUID              = 0xA100;//False UUID does not exists
00008     const static uint16_t TEMPERATURE_CHARACTERISTIC_UUID = 0x2A6E;
00009     const static uint16_t HUMIDITY_CHARACTERISTIC_UUID = 0x2A6F;
00010 
00011     DHT11Service(BLEDevice &_ble, uint8_t initialTempValue, uint8_t initialHumiValue) :
00012         ble(_ble), 
00013         /*temperatureValue(TEMPERATURE_CHARACTERISTIC_UUID,&initialTempValue),*/
00014         temperatureValue(TEMPERATURE_CHARACTERISTIC_UUID, 
00015             &initialTempValue,
00016             sizeof(uint8_t),
00017             sizeof(uint8_t),
00018             GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
00019         humidityValue(HUMIDITY_CHARACTERISTIC_UUID, 
00020             &initialHumiValue,
00021             sizeof(uint8_t),
00022             sizeof(uint8_t),
00023             GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY)
00024         /*humidityValue(HUMIDITY_CHARACTERISTIC_UUID,&initialHumiValue)*/
00025     {
00026         GattCharacteristic *charTable[] = {&temperatureValue,&humidityValue};
00027         GattService service(DHT11_UUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *));
00028         ble.addService(service);
00029         
00030     }
00031 
00032     GattAttribute::Handle_t getValueHandle() const {
00033         return temperatureValue.getValueHandle();
00034     }
00035     
00036     void updateTemperatureValue(uint8_t value) {
00037         ble.gattServer().write(temperatureValue.getValueHandle(), (uint8_t *)&value, sizeof(uint8_t));
00038     }
00039     void updateHumidityValue(uint8_t value) {
00040         ble.gattServer().write(humidityValue.getValueHandle(), (uint8_t *)&value, sizeof(uint8_t));
00041     }
00042 
00043 private:
00044     BLEDevice                         &ble;
00045     GattCharacteristic temperatureValue;
00046     GattCharacteristic humidityValue;
00047 };
00048 
00049 #endif