Reading SenseAir LP8 CO2 sensor over bluetooth low energy
Dependencies: BLE_API mbed nRF51822
Diff: LP8_Service.h
- Revision:
- 0:ee3787c8e209
- Child:
- 2:d02255d8c36f
diff -r 000000000000 -r ee3787c8e209 LP8_Service.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LP8_Service.h Fri Apr 21 13:26:06 2017 +0000 @@ -0,0 +1,35 @@ +#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 \ No newline at end of file