![](/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
DHT11_BLEService.h@0:d2c18f736df1, 2017-04-07 (annotated)
- Committer:
- ledonger
- Date:
- Fri Apr 07 11:36:47 2017 +0000
- Revision:
- 0:d2c18f736df1
- Child:
- 1:023e1eae2048
Working version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ledonger | 0:d2c18f736df1 | 1 | #ifndef __BLE_DHT11_SERVICE_H__ |
ledonger | 0:d2c18f736df1 | 2 | #define __BLE_DHT11_SERVICE_H__ |
ledonger | 0:d2c18f736df1 | 3 | |
ledonger | 0:d2c18f736df1 | 4 | |
ledonger | 0:d2c18f736df1 | 5 | class DHT11Service { |
ledonger | 0:d2c18f736df1 | 6 | public: |
ledonger | 0:d2c18f736df1 | 7 | const static uint16_t DHT11_UUID = 0x2A61;//False UUID does not exists |
ledonger | 0:d2c18f736df1 | 8 | const static uint16_t TEMPERATURE_CHARACTERISTIC_UUID = 0x2A6E; |
ledonger | 0:d2c18f736df1 | 9 | const static uint16_t HUMIDITY_CHARACTERISTIC_UUID = 0x2A6F; |
ledonger | 0:d2c18f736df1 | 10 | |
ledonger | 0:d2c18f736df1 | 11 | DHT11Service(BLEDevice &_ble, uint8_t initialTempValue, uint8_t initialHumiValue) : |
ledonger | 0:d2c18f736df1 | 12 | ble(_ble), |
ledonger | 0:d2c18f736df1 | 13 | /*temperatureValue(TEMPERATURE_CHARACTERISTIC_UUID,&initialTempValue),*/ |
ledonger | 0:d2c18f736df1 | 14 | temperatureValue(TEMPERATURE_CHARACTERISTIC_UUID, |
ledonger | 0:d2c18f736df1 | 15 | &initialTempValue, |
ledonger | 0:d2c18f736df1 | 16 | sizeof(uint32_t), |
ledonger | 0:d2c18f736df1 | 17 | sizeof(uint32_t), |
ledonger | 0:d2c18f736df1 | 18 | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY), |
ledonger | 0:d2c18f736df1 | 19 | humidityValue(HUMIDITY_CHARACTERISTIC_UUID, |
ledonger | 0:d2c18f736df1 | 20 | &initialHumiValue, |
ledonger | 0:d2c18f736df1 | 21 | sizeof(uint32_t), |
ledonger | 0:d2c18f736df1 | 22 | sizeof(uint32_t), |
ledonger | 0:d2c18f736df1 | 23 | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) |
ledonger | 0:d2c18f736df1 | 24 | /*humidityValue(HUMIDITY_CHARACTERISTIC_UUID,&initialHumiValue)*/ |
ledonger | 0:d2c18f736df1 | 25 | { |
ledonger | 0:d2c18f736df1 | 26 | GattCharacteristic *charTable[] = {&temperatureValue,&humidityValue}; |
ledonger | 0:d2c18f736df1 | 27 | GattService service(DHT11_UUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *)); |
ledonger | 0:d2c18f736df1 | 28 | ble.addService(service); |
ledonger | 0:d2c18f736df1 | 29 | |
ledonger | 0:d2c18f736df1 | 30 | } |
ledonger | 0:d2c18f736df1 | 31 | |
ledonger | 0:d2c18f736df1 | 32 | /*GattAttribute::Handle_t getValueHandle() const { |
ledonger | 0:d2c18f736df1 | 33 | return temperatureValue.getValueHandle(); |
ledonger | 0:d2c18f736df1 | 34 | }*/ |
ledonger | 0:d2c18f736df1 | 35 | |
ledonger | 0:d2c18f736df1 | 36 | void updateTemperatureValue(uint32_t value) { |
ledonger | 0:d2c18f736df1 | 37 | ble.gattServer().write(temperatureValue.getValueHandle(), (uint8_t *)&value, sizeof(uint32_t)); |
ledonger | 0:d2c18f736df1 | 38 | } |
ledonger | 0:d2c18f736df1 | 39 | void updateHumidityValue(uint32_t value) { |
ledonger | 0:d2c18f736df1 | 40 | ble.gattServer().write(humidityValue.getValueHandle(), (uint8_t *)&value, sizeof(uint32_t)); |
ledonger | 0:d2c18f736df1 | 41 | } |
ledonger | 0:d2c18f736df1 | 42 | |
ledonger | 0:d2c18f736df1 | 43 | private: |
ledonger | 0:d2c18f736df1 | 44 | BLEDevice &ble; |
ledonger | 0:d2c18f736df1 | 45 | GattCharacteristic temperatureValue; |
ledonger | 0:d2c18f736df1 | 46 | GattCharacteristic humidityValue; |
ledonger | 0:d2c18f736df1 | 47 | }; |
ledonger | 0:d2c18f736df1 | 48 | |
ledonger | 0:d2c18f736df1 | 49 | #endif |