Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BLE_API X_NUCLEO_IDB0XA1 X_NUCLEO_IKS01A1 mbed
GreenBuildingService.h
00001 /************************ STM32NUCLEO IOT Contest ****************************** 00002 * 00003 * Green Building IoT Solution for 00004 * Plant Life Monitoring And Maintenance 00005 * 00006 * Authored by 00007 * Dien Hoa Truong 00008 * Muhammad Haziq Bin Kamarul Azman 00009 * 00010 * for the 00011 * eSAME 2016 STM32NUCLEO IoT Contest in Sophia-Antipolis 00012 * 00013 * 00014 * GreenBuildingService.h | Green Building Service header 00015 * 00016 * See LICENCE.txt for information on copyrights 00017 * 00018 ******************************************************************************/ 00019 00020 #ifndef __BLE_GREEN_BUILDING_SERVICE_H__ 00021 #define __BLE_GREEN_BUILDING_SERVICE_H__ 00022 00023 #include "ble/BLE.h" 00024 00025 /** 00026 * @class GreenBuildingService 00027 * @brief Custom service derived from mbed's BLE Environmental Service. This service provides air temperature, humidity and soil moisture measurement. 00028 */ 00029 class GreenBuildingService { 00030 public: 00031 00032 static const uint16_t UUID_GREEN_BUILDING_SERVICE = 0xEB00; /**< Green Building service UUID */ 00033 static const uint16_t UUID_PLANT_ENVIRONMENT_CHAR = 0xEB01; /**< Plant environment characteristic UUID */ 00034 00035 /** Plant environment data type 00036 * 00037 */ 00038 typedef struct 00039 { 00040 uint8_t airTemperature; /**< Air temperature value */ 00041 uint8_t airHumidity ; /**< Air humidity value */ 00042 uint8_t soilMoisture ; /**< Soil moisture value */ 00043 } PlantEnvironmentType_t; 00044 00045 /** 00046 * @brief GreenBuildingService constructor. 00047 * @param ble Reference to BLE device. 00048 */ 00049 GreenBuildingService(BLE& _ble) : 00050 ble(_ble), 00051 plantEnvironmentCharacteristic(GreenBuildingService::UUID_PLANT_ENVIRONMENT_CHAR, 00052 &plantEnvironment , 00053 GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) 00054 { 00055 static bool serviceAdded = false; // Ensure only single service is added 00056 if (serviceAdded) { 00057 return; 00058 } 00059 00060 GattCharacteristic *charTable[] = { &plantEnvironmentCharacteristic }; // Compile characteristics 00061 00062 GattService greenBuildingService(GreenBuildingService::UUID_GREEN_BUILDING_SERVICE, 00063 charTable , 00064 sizeof(charTable) / sizeof(GattCharacteristic *)); // Create GATT service 00065 00066 ble.gattServer().addService(greenBuildingService); // Register service with GATT server 00067 00068 serviceAdded = true; 00069 } 00070 00071 /** 00072 * @brief Update plant environment characteristic. 00073 * @param newPlantEnvironmentVal New plant environment measurement. 00074 */ 00075 void updatePlantEnvironment(PlantEnvironmentType_t newPlantEnvironmentVal) 00076 { 00077 plantEnvironment = (PlantEnvironmentType_t) (newPlantEnvironmentVal); 00078 ble.gattServer().write(plantEnvironmentCharacteristic.getValueHandle(), (uint8_t *) &plantEnvironment, sizeof(PlantEnvironmentType_t)); 00079 } 00080 00081 private: 00082 BLE& ble; /*< Local BLE controller reference */ 00083 00084 ReadOnlyGattCharacteristic<PlantEnvironmentType_t> plantEnvironmentCharacteristic; /*< Plant environment read-only characteristic */ 00085 00086 PlantEnvironmentType_t plantEnvironment; /*< Local var for plant environment */ 00087 }; 00088 00089 #endif /* #ifndef __BLE_GREEN_BUILDING_SERVICE_H__*/
Generated on Tue Jul 12 2022 14:54:29 by
1.7.2