IOTIO

Dependencies:   Nucleo_BLE_API_IOTIO Nucleo_BLE_BlueNRG Nucleo_BLE_DemoApp Nucleo_Sensor_Shield mbed

Dependents:   Nucleo_BLE_Demo_IOTIO

Fork of Nucleo_BLE_Demo by Cortex Challenge Team

Revision:
1:4bdfa7d7e8bf
Parent:
0:d450c9945f96
Child:
2:c69117fc79da
--- a/main.cpp	Wed May 27 18:59:24 2015 +0000
+++ b/main.cpp	Sat Oct 29 15:11:28 2016 +0000
@@ -16,7 +16,14 @@
 
 #include "mbed.h"
 #include "DemoAppService.h"
-
+#include "x_cube_mems.h"
+#define PI 3.1415169f
+float TEMPERATURE_C = 20;
+float HUMIDITY = 50;
+float PRESSURE = 1000;
+float WIND_DIRECTION = 0;
+int16_t MagRaw[3];
+AxesRaw_TypeDef MAGNETIC;
 
 extern bool user_button_pressed;
 bool connected = false;
@@ -39,13 +46,51 @@
 
 int main(void)
 {
-  demoService = startDemoBLE("Demo App");
+  demoService = startDemoBLE("BLE-1234567");
   demoService->setCallback(demoCallback);
 
   led = 0.0f;
-
+  
+  static X_CUBE_MEMS *Sensors = X_CUBE_MEMS::Instance();
+ 
+  
   while (true) 
   {
-    demoService->waitForEvent();
+       
+            /* Read the environmental sensors  */
+                  //  Sensors->hts221.GetTemperature((float *)&TEMPERATURE_C);
+//                    Sensors->hts221.GetHumidity((float *)&HUMIDITY);
+//                    Sensors->lps25h.GetPressure((float *)&PRESSURE);
+                    
+                    Sensors->hts221.GetTemperature((float *)&TEMPERATURE_C);
+                    Sensors->hts221.GetHumidity((float *)&HUMIDITY);
+                    Sensors->lps25h.GetPressure((float *)&PRESSURE);
+                    Sensors->lis3mdl.GetAxes((AxesRaw_TypeDef *)&MAGNETIC);
+                 
+                    
+                                            TEMPERATURE_C = TEMPERATURE_C*100;  //2 decimals
+                                            HUMIDITY = HUMIDITY*100;                        //2 decimals
+                                            PRESSURE = PRESSURE*1000;           //hPa to Pa + 1 decimal
+                                                    
+                                                    //Calcule the direction where the system is pointing relative to North.
+                    //I have used a simple empirical method to distinguish between 8 directions. 
+                    if (MAGNETIC.AXIS_X < 140) WIND_DIRECTION = 0; //North
+                    else if (MAGNETIC.AXIS_X >= 140 && MAGNETIC.AXIS_X < 200 && -MAGNETIC.AXIS_Y > 250 ) WIND_DIRECTION = 45;  //Northeast
+                    else if (MAGNETIC.AXIS_X >= 140 && MAGNETIC.AXIS_X < 200 && -MAGNETIC.AXIS_Y < 250 ) WIND_DIRECTION = 315; //Northwest
+                    else if (MAGNETIC.AXIS_X >= 200 && MAGNETIC.AXIS_X < 280 && -MAGNETIC.AXIS_Y > 250 ) WIND_DIRECTION = 90;  //East
+                    else if (MAGNETIC.AXIS_X >= 200 && MAGNETIC.AXIS_X < 280 && -MAGNETIC.AXIS_Y < 250 ) WIND_DIRECTION = 270; //Weast
+                    else if (MAGNETIC.AXIS_X >= 280 && MAGNETIC.AXIS_X < 380 && -MAGNETIC.AXIS_Y > 250 ) WIND_DIRECTION = 135; //Southeast
+                    else if (MAGNETIC.AXIS_X >= 280 && MAGNETIC.AXIS_X < 380 && -MAGNETIC.AXIS_Y < 250 ) WIND_DIRECTION = 225; //Soutwest           
+                    else if (MAGNETIC.AXIS_X >= 380) WIND_DIRECTION = 180; //South
+                    
+                     WIND_DIRECTION *=100;                             //2 decimals
+                                                    
+                                                         demoService->updateHumidity(HUMIDITY);
+                                                         demoService->updateTemperature(TEMPERATURE_C);
+                                                         demoService->updateWinddirection(WIND_DIRECTION);
+                                                         demoService->updatePressure(PRESSURE);
+            demoService->waitForEvent();
+         
+    
   }
 }