It is a simple IoT solution for plant life monitoring and maintenance, based on STM32NUCLEO boards and expansion modules. This branch is the post-eSAME development branch.
Dependencies: BLE_API X_NUCLEO_IDB0XA1 X_NUCLEO_IKS01A1 mbed
Fork of BLE_GreenYourLife_STM32 by
This branch is the main continuation of the original project. You can find it here.
GreenBuildingService.h@0:7dce5e74ad91, 2016-11-26 (annotated)
- Committer:
- kaiserhaz
- Date:
- Sat Nov 26 13:38:23 2016 +0000
- Revision:
- 0:7dce5e74ad91
Initial commit.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kaiserhaz | 0:7dce5e74ad91 | 1 | /************************ STM32NUCLEO IOT Contest ****************************** |
kaiserhaz | 0:7dce5e74ad91 | 2 | * |
kaiserhaz | 0:7dce5e74ad91 | 3 | * Green Building IoT Solution for |
kaiserhaz | 0:7dce5e74ad91 | 4 | * Plant Life Monitoring And Maintenance |
kaiserhaz | 0:7dce5e74ad91 | 5 | * |
kaiserhaz | 0:7dce5e74ad91 | 6 | * Authored by |
kaiserhaz | 0:7dce5e74ad91 | 7 | * Dien Hoa Truong |
kaiserhaz | 0:7dce5e74ad91 | 8 | * Muhammad Haziq Bin Kamarul Azman |
kaiserhaz | 0:7dce5e74ad91 | 9 | * |
kaiserhaz | 0:7dce5e74ad91 | 10 | * for the |
kaiserhaz | 0:7dce5e74ad91 | 11 | * eSAME 2016 STM32NUCLEO IoT Contest in Sophia-Antipolis |
kaiserhaz | 0:7dce5e74ad91 | 12 | * |
kaiserhaz | 0:7dce5e74ad91 | 13 | * |
kaiserhaz | 0:7dce5e74ad91 | 14 | * GreenBuildingService.h | Green Building Service header |
kaiserhaz | 0:7dce5e74ad91 | 15 | * |
kaiserhaz | 0:7dce5e74ad91 | 16 | ******************************************************************************/ |
kaiserhaz | 0:7dce5e74ad91 | 17 | |
kaiserhaz | 0:7dce5e74ad91 | 18 | #ifndef __BLE_GREEN_BUILDING_SERVICE_H__ |
kaiserhaz | 0:7dce5e74ad91 | 19 | #define __BLE_GREEN_BUILDING_SERVICE_H__ |
kaiserhaz | 0:7dce5e74ad91 | 20 | |
kaiserhaz | 0:7dce5e74ad91 | 21 | #include "ble/BLE.h" |
kaiserhaz | 0:7dce5e74ad91 | 22 | |
kaiserhaz | 0:7dce5e74ad91 | 23 | /** |
kaiserhaz | 0:7dce5e74ad91 | 24 | * @class GreenBuildingService |
kaiserhaz | 0:7dce5e74ad91 | 25 | * @brief Custom service derived from mbed's BLE Environmental Service. This service provides air temperature, humidity and soil moisture measurement. |
kaiserhaz | 0:7dce5e74ad91 | 26 | */ |
kaiserhaz | 0:7dce5e74ad91 | 27 | class GreenBuildingService { |
kaiserhaz | 0:7dce5e74ad91 | 28 | public: |
kaiserhaz | 0:7dce5e74ad91 | 29 | |
kaiserhaz | 0:7dce5e74ad91 | 30 | static const uint16_t UUID_GREEN_BUILDING_SERVICE = 0xEB00; /**< Green Building service UUID */ |
kaiserhaz | 0:7dce5e74ad91 | 31 | static const uint16_t UUID_PLANT_ENVIRONMENT_CHAR = 0xEB01; /**< Plant environment characteristic UUID */ |
kaiserhaz | 0:7dce5e74ad91 | 32 | |
kaiserhaz | 0:7dce5e74ad91 | 33 | /** Plant environment data type |
kaiserhaz | 0:7dce5e74ad91 | 34 | * |
kaiserhaz | 0:7dce5e74ad91 | 35 | */ |
kaiserhaz | 0:7dce5e74ad91 | 36 | typedef struct |
kaiserhaz | 0:7dce5e74ad91 | 37 | { |
kaiserhaz | 0:7dce5e74ad91 | 38 | uint8_t airTemperature; /**< Air temperature value */ |
kaiserhaz | 0:7dce5e74ad91 | 39 | uint8_t airHumidity ; /**< Air humidity value */ |
kaiserhaz | 0:7dce5e74ad91 | 40 | uint8_t soilMoisture ; /**< Soil moisture value */ |
kaiserhaz | 0:7dce5e74ad91 | 41 | } PlantEnvironmentType_t; |
kaiserhaz | 0:7dce5e74ad91 | 42 | |
kaiserhaz | 0:7dce5e74ad91 | 43 | /** |
kaiserhaz | 0:7dce5e74ad91 | 44 | * @brief GreenBuildingService constructor. |
kaiserhaz | 0:7dce5e74ad91 | 45 | * @param ble Reference to BLE device. |
kaiserhaz | 0:7dce5e74ad91 | 46 | */ |
kaiserhaz | 0:7dce5e74ad91 | 47 | GreenBuildingService(BLE& _ble) : |
kaiserhaz | 0:7dce5e74ad91 | 48 | ble(_ble), |
kaiserhaz | 0:7dce5e74ad91 | 49 | plantEnvironmentCharacteristic(GreenBuildingService::UUID_PLANT_ENVIRONMENT_CHAR, |
kaiserhaz | 0:7dce5e74ad91 | 50 | &plantEnvironment , |
kaiserhaz | 0:7dce5e74ad91 | 51 | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) |
kaiserhaz | 0:7dce5e74ad91 | 52 | { |
kaiserhaz | 0:7dce5e74ad91 | 53 | static bool serviceAdded = false; // Ensure only single service is added |
kaiserhaz | 0:7dce5e74ad91 | 54 | if (serviceAdded) { |
kaiserhaz | 0:7dce5e74ad91 | 55 | return; |
kaiserhaz | 0:7dce5e74ad91 | 56 | } |
kaiserhaz | 0:7dce5e74ad91 | 57 | |
kaiserhaz | 0:7dce5e74ad91 | 58 | GattCharacteristic *charTable[] = { &plantEnvironmentCharacteristic }; // Compile characteristics |
kaiserhaz | 0:7dce5e74ad91 | 59 | |
kaiserhaz | 0:7dce5e74ad91 | 60 | GattService greenBuildingService(GreenBuildingService::UUID_GREEN_BUILDING_SERVICE, |
kaiserhaz | 0:7dce5e74ad91 | 61 | charTable , |
kaiserhaz | 0:7dce5e74ad91 | 62 | sizeof(charTable) / sizeof(GattCharacteristic *)); // Create GATT service |
kaiserhaz | 0:7dce5e74ad91 | 63 | |
kaiserhaz | 0:7dce5e74ad91 | 64 | ble.gattServer().addService(greenBuildingService); // Register service with GATT server |
kaiserhaz | 0:7dce5e74ad91 | 65 | |
kaiserhaz | 0:7dce5e74ad91 | 66 | serviceAdded = true; |
kaiserhaz | 0:7dce5e74ad91 | 67 | } |
kaiserhaz | 0:7dce5e74ad91 | 68 | |
kaiserhaz | 0:7dce5e74ad91 | 69 | /** |
kaiserhaz | 0:7dce5e74ad91 | 70 | * @brief Update plant environment characteristic. |
kaiserhaz | 0:7dce5e74ad91 | 71 | * @param newPlantEnvironmentVal New plant environment measurement. |
kaiserhaz | 0:7dce5e74ad91 | 72 | */ |
kaiserhaz | 0:7dce5e74ad91 | 73 | void updatePlantEnvironment(PlantEnvironmentType_t newPlantEnvironmentVal) |
kaiserhaz | 0:7dce5e74ad91 | 74 | { |
kaiserhaz | 0:7dce5e74ad91 | 75 | plantEnvironment = (PlantEnvironmentType_t) (newPlantEnvironmentVal); |
kaiserhaz | 0:7dce5e74ad91 | 76 | ble.gattServer().write(plantEnvironmentCharacteristic.getValueHandle(), (uint8_t *) &plantEnvironment, sizeof(PlantEnvironmentType_t)); |
kaiserhaz | 0:7dce5e74ad91 | 77 | } |
kaiserhaz | 0:7dce5e74ad91 | 78 | |
kaiserhaz | 0:7dce5e74ad91 | 79 | private: |
kaiserhaz | 0:7dce5e74ad91 | 80 | BLE& ble; /*< Local BLE controller reference */ |
kaiserhaz | 0:7dce5e74ad91 | 81 | |
kaiserhaz | 0:7dce5e74ad91 | 82 | ReadOnlyGattCharacteristic<PlantEnvironmentType_t> plantEnvironmentCharacteristic; /*< Plant environment read-only characteristic */ |
kaiserhaz | 0:7dce5e74ad91 | 83 | |
kaiserhaz | 0:7dce5e74ad91 | 84 | PlantEnvironmentType_t plantEnvironment; /*< Local var for plant environment */ |
kaiserhaz | 0:7dce5e74ad91 | 85 | }; |
kaiserhaz | 0:7dce5e74ad91 | 86 | |
kaiserhaz | 0:7dce5e74ad91 | 87 | #endif /* #ifndef __BLE_GREEN_BUILDING_SERVICE_H__*/ |