yes Spada / Mbed OS programme
Revision:
15:aac1b3950a9e
Parent:
14:c5578b5edabe
Child:
16:eed9a9ba319c
--- a/WeatherStation.cpp	Tue Apr 02 09:51:34 2019 +0000
+++ b/WeatherStation.cpp	Tue Apr 16 07:22:47 2019 +0000
@@ -53,6 +53,15 @@
   // Starting the BLE peripheral with Advertising State
   GAPPeripheral::advertise();
 }
+
+
+void WeatherStation::onInitComplete(BLE::InitializationCompleteCallbackContext *event) {
+  GAPPeripheral::onInitComplete(event);
+  m_batteryService.addServiceToGattServer();
+  m_environmentalService.addServiceToGattServer();
+  performMeasurements();
+}
+
  
 void WeatherStation::performMeasurements(void) {
   m_logger.log("Performing measurements:\r\n");
@@ -71,7 +80,7 @@
   
   // get and log the battery level
   uint8_t battery = m_iDevKit.getBatteryLevel();
-  m_logger.log("Battery:        %u mV\r\n", battery);
+  m_logger.log("Battery:        %u %%\r\n", battery);
   
   //  Cleaning the console by the addition of a blank line
   m_logger.log("\r\n");
@@ -84,29 +93,6 @@
   m_history.addMeasurement(pressure, temp, humidity, time);
   
   //  Send the measured values for encoding
-  setupAdvertisementPayload(pressure, temp, humidity);
-}
-
-void WeatherStation::setupAdvertisementPayload(double pressure, double temp, double humidity) {
-    
-  //  Setting the right UUID (environmental values) to the Advertising Payload
-  dataPayload[0].serviceUUID = GattService::UUID_ENVIRONMENTAL_SERVICE;
-
-  //  Encode and store the measured environmental values to the Advertising Payload
-  uint32_encode((uint32_t) (pressure * 10), &dataPayload[0].serviceData[0]);
-  uint32_encode((int16_t) (temp * 100), &dataPayload[0].serviceData[4]);        // Padding of 4 Bytes (= 32 bits as the pressure's type)
-  uint32_encode((uint16_t) (humidity * 100), &dataPayload[0].serviceData[6]);   // Padding of 2 Bytes (= 16 bits as the temperature's type)
-    
-  //  Setting the Advertising Payload length   
-  dataPayload[0].serviceDataLength = 8; 
-    
-  //  Sending the Advertising Payload to the GAP Peripheral
-  //  Has just one Payload
-  setAdvertisementServiceData(dataPayload, 1);
-}
-
-void WeatherStation::onInitComplete(BLE::InitializationCompleteCallbackContext *event) {
-  GAPPeripheral::onInitComplete(event);
-  m_batteryService.addServiceToGattServer();
-  m_batteryService.updateBatteryLevel(m_lps25hb.getPressure());
+  m_environmentalService.updateEnvironmentalService(((uint32_t)(pressure*10)), ((int16_t)(temp*100)), ((uint16_t)(humidity*100)));
+  m_batteryService.updateBatteryLevel(battery);
 }
\ No newline at end of file