Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: NaturalTinyShell_ice libmDot-12Sept mbed-rtos mbed
Fork of ICE by
Diff: src/AnalyticsLogger/AnalyticsLogger.cpp
- Revision:
- 199:d65ed41d4dd4
- Parent:
- 177:9ec90c8e3ce1
- Child:
- 224:9ea8925c61e0
--- a/src/AnalyticsLogger/AnalyticsLogger.cpp Thu Oct 06 21:02:11 2016 +0000 +++ b/src/AnalyticsLogger/AnalyticsLogger.cpp Fri Oct 07 11:40:51 2016 +0000 @@ -26,30 +26,47 @@ struct tm *ts; time_t curr_sec; int last_min=8; - + bool log_sent=false; + while ( true ) { - - std::ostringstream log_event; + + 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%1) == 0) && (ts->tm_min != last_min) ) { last_min = ts->tm_min; - + log_event << "\"lr\":["; std::map<std::string, ModbusRegister>::iterator iter; for (iter = ModbusRegisterMap.begin(); iter != ModbusRegisterMap.end(); ++iter) { - + log_event << "{\"t\":"<< "\"" << iter->first.c_str() << "\"," << "\"v\":"<< "\"" << iter->second.float_value<< "\"},"; + log_sent = false; + if( log_event.str().size() >= 150 ) { + std::string str = log_event.str(); + str.erase( str.size() - 1 ); + str.append("]"); +// printf("%s:%d: Logging %s : len=%d\r\n", __func__, __LINE__, str.c_str(), str.length() ); + LiveDataLoggerApi( str.c_str() ); + log_event.str(""); + log_event.clear(); + log_event << "\"lr\":["; + log_sent = true; + } } - 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() ); + if( log_sent == false ) { + std::string str = log_event.str(); + str.erase( str.size() - 1 ); + str.append("]"); + if( str.length() > 10 ) { +// printf("%s:%d: Logging %s : len=%d\r\n", __func__, __LINE__, str.c_str(), str.length() ); + LiveDataLoggerApi( str.c_str() ); + } + } } - + Thread::wait(5000); } } \ No newline at end of file