Reading SenseAir LP8 CO2 sensor over bluetooth low energy
Dependencies: BLE_API mbed nRF51822
LP8_Service.h
- Committer:
- jony1401
- Date:
- 2017-04-21
- Revision:
- 0:ee3787c8e209
- Child:
- 2:d02255d8c36f
File content as of revision 0:ee3787c8e209:
#ifndef LP8_SERVICE_H #define LP8_SERVICE_H /* LP8 Gatt Service Class */ class LP8_Service { public: const static uint16_t LP8_SERVICE_UUID = 0xA000; //set custom UUID´s const static uint16_t LP8_STATE_CHARACTERISTIC_UUID = 0xA001; // //constructor setup for Gatt Service LP8_Service(BLE &_ble, int co2ValueInitial): /* Passes a refrence to ble stack object and the lp8State copy to the private members */ ble(_ble), lp8State(LP8_STATE_CHARACTERISTIC_UUID, &co2ValueInitial, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) { GattCharacteristic *charTable[] = {&lp8State }; //create an 1 element array with lp8 Gatt characteristic GattService lp8Service(LP8_SERVICE_UUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *)); //create an LP8 GattService ble.addService(lp8Service); //add gatt service to the ble stack }; void updateCo2Value(int co2Value) { ble.gattServer().write(lp8State.getValueAttribute().getHandle(),(uint8_t *) &co2Value, sizeof(co2Value)); //update the Gatt Server with new CO2 value }; private: BLE &ble; //reference to ble object ReadOnlyGattCharacteristic<int> lp8State; // }; #endif