Condensation Monitor Measure the current environment condition at outside and inside and make caution or warnings related to condensation. Support UART over BLE. It works with nRF Toolbox. 結露モニタ 屋内外の環境情報を計測し、結露に関する警告あるいは注意を出力します。 nRF Toolboxと一緒に動作し、UART機能でBLE経由でメッセージを出力します。 ドキュメント https://developer.mbed.org/users/takafuminaka/notebook/information-about-my-condensation-monitor-for-mbed/

Dependencies:   AQM0802 BME280 HDC1000 VaporCondition mbed BLE_API nRF51822 BLE_Condensation_Monitor

Dependents:   BLE_Condensation_Monitor

Fork of Condensation_Monitor by Nakatafu ☆

Revision:
5:06d988a47721
Parent:
4:3075954b341c
Child:
6:3c2404870d39
--- a/main.cpp	Sun May 31 06:39:09 2015 +0000
+++ b/main.cpp	Sun May 31 09:46:44 2015 +0000
@@ -16,6 +16,7 @@
 #include "VaporCondition.h"
 
 #define NEED_CONSOLE_OUTPUT 1
+#define NEED_BLE_CONSOLE 1
 #define NEED_LCD_OUTPUT 1
 
 #if NEED_CONSOLE_OUTPUT
@@ -25,6 +26,13 @@
 #define PC(...) /* nothing */
 #endif /* #if NEED_CONSOLE_OUTPUT */
 
+#if NEED_BLE_CONSOLE
+#include "BLEDevice.h"
+#include "UARTService.h"
+#define BLEC(...) { char __blecstr[32]; sprintf(__blecstr,__VA_ARGS__); if (uart) uart->write(__blecstr, strlen(__blecstr)); }
+#else
+#define BLEC(...) /* nothing */
+#endif /* #if NEED_BLE_CONSOLE */
 
 #if defined(TARGET_LPC1768)
     I2C i2c(p28, p27);
@@ -43,6 +51,18 @@
 DigitalOut led1(LED1);
 DigitalOut led2(LED2);
 
+#if NEED_BLE_CONSOLE
+BLEDevice  ble;
+UARTService *uart;
+
+void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason)
+{
+    PC("Disconnected!\n\r");
+    PC("Restarting the advertising process\n\r");
+    ble.startAdvertising();
+}
+
+#endif /* #if NEED_BLE_CONSOLE */
 
 int main() {
     float Tdp_o =0.;
@@ -54,6 +74,7 @@
     int mode=0;
     int skip=0;
     char msg[4][2][9];
+    char bmsg[4][20];
     int skipf[4];
     
     float Tcur;
@@ -62,7 +83,9 @@
     char *sWin;
     char *ssTcur;
     char *ssWin;
-   
+    char *bsTcur;
+    char *bsWin;
+
     VaporCondition Inside;
     VaporCondition Outside;
 
@@ -75,7 +98,26 @@
     led2 = 0;
     
     // i2c.frequency(100000);
-      
+    
+#if NEED_BLE_CONSOLE
+    // Setup BLE //  
+    ble.init();
+    ble.onDisconnection(disconnectionCallback);
+    
+    uart = new UARTService(ble);
+
+    /* setup advertising */
+    ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED);
+    ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
+    ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME,
+                                     (const uint8_t *)"BLE Condensation Monitor", sizeof("BLE Condensation Monitor") - 1);
+    ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS,
+                                     (const uint8_t *)UARTServiceUUID_reversed, sizeof(UARTServiceUUID_reversed));
+
+    ble.setAdvertisingInterval(160); /* 100ms; in multiples of 0.625ms. */
+    ble.startAdvertising();
+#endif /* #if NEED_BLE_CONSOLE */
+     
     while(1) {
         // Get data
 
@@ -88,8 +130,7 @@
         Inside.t = float(hdc1000.temperature())/0x10000*165-40;
         Inside.h = float(hdc1000.humidity())/0x10000*100;
 
-//                PC("%2.2f degC, %2.2f %%\r\n", t, h);
-
+        
         PC("In: %2.2f degC, %2.2f %% Out: %2.2f degC, %2.2f %%, %04.2f hPa\r\n", Inside.t, Inside.h, Outside.t, Outside.h, Outside.p);
         PC("Humidity Ratio [g/kg] : In %2.2f Out %2.2f \r\n", Inside.Rh(), Outside.Rh());
         Tdp_o = Outside.Tdp();
@@ -105,18 +146,22 @@
                 Tcur = Outside.t;   // 1 and 3
                 sTcur = "Outside";
                 ssTcur = "Out";
+                bsTcur = "Out";
             } else {
                 Tcur = Inside.t;    // 0 and 2
                 sTcur = "Inside";
                 ssTcur = "In";
+                bsTcur = "In";
             }
 
             if ( ii / 2 ) {
                 sWin = " Window"; // 2 and 3
                 ssWin = "@Win";
+                bsWin = "Wind.";
             } else {
                 sWin = "";         // 0 and 1
                 ssWin = "";
+                bsWin = "";
             }
 
             if ( ii / 2 == ii %2 ) {
@@ -131,11 +176,13 @@
                     PC("Condensation at %s\r\n",sTcur);
                     sprintf(msg[ii][0],"Condns!!");
                     sprintf(msg[ii][1],"%s%s",ssTcur,ssWin);
+                    sprintf(bmsg[ii],"Cond. at %s",bsWin); 
                     cautions ++;
                 } else {
-                    PC("%2.2f degC to Condensation at %s%s\r\n", Tcur - Tdp, sTcur, sWin);
+                    PC("%4.1f degC to Condensation at %s%s\r\n", Tcur - Tdp, sTcur, sWin);
                     sprintf(msg[ii][0],"Cto%4.1fC",Tcur-Tdp);
                     sprintf(msg[ii][1],"%s%s\0",ssTcur,ssWin);
+                    sprintf(bmsg[ii],"%4.1ftoC.at%s%s",Tcur - Tdp, bsTcur, bsWin);
                     warnings ++;
                 }
             } else {
@@ -144,7 +191,7 @@
         }
 
         PC("\r\n");
-
+        
         if ( cautions > 0 ) {
             led2 = 1;
         } else {
@@ -166,21 +213,25 @@
             case (1):
                 sprintf(msg1,"Ti %4.1fC",Inside.t);
                 sprintf(msg2,"To %4.1fC",Outside.t);
+                BLEC("Temp.In%4.1f Out%4.1f\n",Inside.t, Outside.t);
                 break;
                 
             case (2):
                 sprintf(msg1,"Hi %4.1f%%",Inside.h);
                 sprintf(msg2,"Ho %4.1f%%",Outside.h);
+                BLEC("Hum.In%2.0f%% Out%2.0f%%\n",Inside.h, Outside.h);
                 break;
                 
             case (3):
                 sprintf(msg1,"Po%6.2f",Outside.p);
                 sprintf(msg2,"   [hPa]");
+                BLEC("Press. %6.2fhPa\n",Outside.p);
                 break;
                 
             case (4):
                 sprintf(msg1,"Dpi%4.1fC",Tdp_i);
                 sprintf(msg2,"Dpo%4.1fC",Tdp_o);
+                BLEC("DP. In%4.1f Out%4.1f\n",Tdp_i, Tdp_o);
                 break;
                 
             case (5):
@@ -191,6 +242,7 @@
                 skip = skipf[ii];
                 sprintf(msg1,"%8s",msg[ii][0]);
                 sprintf(msg2,"%8s",msg[ii][1]);
+                BLEC("%s\n",bmsg[ii]);
                 break;
         }
         mode++;