Reading SenseAir LP8 CO2 sensor over bluetooth low energy

Dependencies:   BLE_API mbed nRF51822

Committer:
jony1401
Date:
Fri Apr 21 13:26:06 2017 +0000
Revision:
0:ee3787c8e209
Child:
2:d02255d8c36f
alpha v 1.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jony1401 0:ee3787c8e209 1 #ifndef LP8_SERVICE_H
jony1401 0:ee3787c8e209 2 #define LP8_SERVICE_H
jony1401 0:ee3787c8e209 3
jony1401 0:ee3787c8e209 4 /* LP8 Gatt Service Class */
jony1401 0:ee3787c8e209 5
jony1401 0:ee3787c8e209 6 class LP8_Service
jony1401 0:ee3787c8e209 7 {
jony1401 0:ee3787c8e209 8 public:
jony1401 0:ee3787c8e209 9
jony1401 0:ee3787c8e209 10 const static uint16_t LP8_SERVICE_UUID = 0xA000; //set custom UUID´s
jony1401 0:ee3787c8e209 11 const static uint16_t LP8_STATE_CHARACTERISTIC_UUID = 0xA001; //
jony1401 0:ee3787c8e209 12
jony1401 0:ee3787c8e209 13 //constructor setup for Gatt Service
jony1401 0:ee3787c8e209 14 LP8_Service(BLE &_ble, int co2ValueInitial): /* Passes a refrence to ble stack object and the lp8State copy to the private members */
jony1401 0:ee3787c8e209 15 ble(_ble),
jony1401 0:ee3787c8e209 16 lp8State(LP8_STATE_CHARACTERISTIC_UUID, &co2ValueInitial, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY)
jony1401 0:ee3787c8e209 17 {
jony1401 0:ee3787c8e209 18 GattCharacteristic *charTable[] = {&lp8State }; //create an 1 element array with lp8 Gatt characteristic
jony1401 0:ee3787c8e209 19 GattService lp8Service(LP8_SERVICE_UUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *)); //create an LP8 GattService
jony1401 0:ee3787c8e209 20 ble.addService(lp8Service); //add gatt service to the ble stack
jony1401 0:ee3787c8e209 21 };
jony1401 0:ee3787c8e209 22
jony1401 0:ee3787c8e209 23 void updateCo2Value(int co2Value)
jony1401 0:ee3787c8e209 24 {
jony1401 0:ee3787c8e209 25 ble.gattServer().write(lp8State.getValueAttribute().getHandle(),(uint8_t *) &co2Value, sizeof(co2Value)); //update the Gatt Server with new CO2 value
jony1401 0:ee3787c8e209 26 };
jony1401 0:ee3787c8e209 27
jony1401 0:ee3787c8e209 28 private:
jony1401 0:ee3787c8e209 29
jony1401 0:ee3787c8e209 30 BLE &ble; //reference to ble object
jony1401 0:ee3787c8e209 31 ReadOnlyGattCharacteristic<int> lp8State; //
jony1401 0:ee3787c8e209 32
jony1401 0:ee3787c8e209 33
jony1401 0:ee3787c8e209 34 };
jony1401 0:ee3787c8e209 35 #endif