Erick / Mbed 2 deprecated ICE_BLE_TEST

Dependencies:   NaturalTinyShell_ice libmDot-12Sept mbed-rtos mbed

Fork of ICE by Erick

Revision:
125:f11cc566d073
Parent:
116:7337ed514891
Child:
177:9ec90c8e3ce1
--- a/src/AnalyticsLogger/AnalyticsLogger.cpp	Fri Sep 23 15:29:15 2016 +0000
+++ b/src/AnalyticsLogger/AnalyticsLogger.cpp	Fri Sep 23 20:31:35 2016 +0000
@@ -6,7 +6,11 @@
  *****************************************************************************/
 #include "global.h"
 #include <stdio.h>
+#include <string>
+#include <sstream>
+#include <iostream>
 #include "AnalyticsLogger.h"
+#include "LoggerApi.h"
 #include "eep.h"
 #include "rtc.h"
 
@@ -21,40 +25,31 @@
 {
     struct tm       *ts;
     time_t curr_sec;
-    char time_string[80];
     int last_min=8;
-
-    curr_sec = time(0);
-    ts = localtime(&curr_sec);
-    strftime(time_string, sizeof(time_string), "%Y-%m-%d %H:%M:%S", ts);
-    printf("\r\n%s has started at: %s\r\n", __func__, time_string);
-
+    
     while ( true ) {
+        
+        std::ostringstream log_event; 
 
         curr_sec = time(0);
         ts = localtime(&curr_sec);
 //        printf("curr_sec=%ld, min=%d (last=%d)\r\n", curr_sec, ts->tm_min, last_min );
-        if( ((ts->tm_min%15) == 0) && (ts->tm_min != last_min) ) {
+        if( ((ts->tm_min%5) == 0) && (ts->tm_min != last_min) ) {
             last_min = ts->tm_min;
-            strftime(time_string, sizeof(time_string), "%Y-%m-%d %H:%M:%S", ts);
-            logInfo("%s logging at: %s\r\n", __func__, time_string);
             
+            log_event << "\"lr\":[";
             std::map<std::string, ModbusRegister>::iterator iter;
             for (iter = ModbusRegisterMap.begin(); iter != ModbusRegisterMap.end(); ++iter) {
-                logInfo("Logging tag=%s, value=%2.2f\r\n", iter->first.c_str(), iter->second.float_value );
+                
+                log_event << "{\"t\":"<< "\"" << iter->first.c_str() << "\"," << "\"v\":"<< "\"" << iter->second.float_value<< "\"},";
             }
+            std::string str = log_event.str();
+            str.erase( str.size() - 1 );
+            str.append("]");
+//            printf("Logging %s : len=%d\r\n", str.c_str(), str.length() );
+            LiveDataLoggerApi( str.c_str() );
         }
         
         Thread::wait(5000);
     }
-}
-
-bool AnalyticsLoggerApi( std::string *log_string )
-{   
-    logInfo("%s:%d Sending Mail To AnalyticsLoggerMailbox", __func__, __LINE__);
-    AnalyticsLoggerReq_t *mail = AnalyticsLoggerMailBox.alloc();
-    strncpy( mail->log_entry, log_string->c_str(), (sizeof(mail->log_entry)-1));
-    AnalyticsLoggerMailBox.put(mail);
-
-    return true;
 }
\ No newline at end of file