Monitor for central heating system (e.g. 2zones+hw) Supports up to 15 temp probes (DS18B20/DS18S20) 3 valve monitors Gas pulse meter recording Use stand-alone or with nodeEnergyServer See http://robdobson.com/2015/09/central-heating-monitor
Dependencies: EthernetInterfacePlusHostname NTPClient Onewire RdWebServer SDFileSystem-RTOS mbed-rtos mbed-src
Logger.cpp@12:a52996515063, 2015-02-22 (annotated)
- Committer:
- Bobty
- Date:
- Sun Feb 22 22:08:37 2015 +0000
- Revision:
- 12:a52996515063
- Child:
- 20:7933076df5af
Watchdog implemented and working; Improved logging of events and data
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Bobty | 12:a52996515063 | 1 | // Log to SD |
Bobty | 12:a52996515063 | 2 | // Rob Dobson, 2015 |
Bobty | 12:a52996515063 | 3 | |
Bobty | 12:a52996515063 | 4 | #include "Logger.h" |
Bobty | 12:a52996515063 | 5 | |
Bobty | 12:a52996515063 | 6 | Logger::Logger(const char* eventLogFileName, const char* dataLogFileBase) |
Bobty | 12:a52996515063 | 7 | { |
Bobty | 12:a52996515063 | 8 | _eventLogFileName = eventLogFileName; |
Bobty | 12:a52996515063 | 9 | _dataLogFileBase = dataLogFileBase; |
Bobty | 12:a52996515063 | 10 | } |
Bobty | 12:a52996515063 | 11 | |
Bobty | 12:a52996515063 | 12 | void Logger::LogEvent(const char* format, ...) |
Bobty | 12:a52996515063 | 13 | { |
Bobty | 12:a52996515063 | 14 | char timeBuf[40]; |
Bobty | 12:a52996515063 | 15 | time_t seconds = time(NULL); |
Bobty | 12:a52996515063 | 16 | strftime(timeBuf, sizeof(timeBuf), "%Y-%m-%d\t%H:%M:%S\t", localtime(&seconds)); |
Bobty | 12:a52996515063 | 17 | |
Bobty | 12:a52996515063 | 18 | FILE* fp = fopen(_eventLogFileName, "a"); |
Bobty | 12:a52996515063 | 19 | if (fp == NULL) |
Bobty | 12:a52996515063 | 20 | { |
Bobty | 12:a52996515063 | 21 | printf ("Event Log ... Filename %s not found\r\n", _eventLogFileName); |
Bobty | 12:a52996515063 | 22 | } |
Bobty | 12:a52996515063 | 23 | else |
Bobty | 12:a52996515063 | 24 | { |
Bobty | 12:a52996515063 | 25 | fprintf(fp, timeBuf); |
Bobty | 12:a52996515063 | 26 | va_list argptr; |
Bobty | 12:a52996515063 | 27 | va_start(argptr, format); |
Bobty | 12:a52996515063 | 28 | vfprintf(fp, format, argptr); |
Bobty | 12:a52996515063 | 29 | va_end(argptr); |
Bobty | 12:a52996515063 | 30 | fprintf(fp, "\r\n"); |
Bobty | 12:a52996515063 | 31 | fclose(fp); |
Bobty | 12:a52996515063 | 32 | } |
Bobty | 12:a52996515063 | 33 | } |
Bobty | 12:a52996515063 | 34 | |
Bobty | 12:a52996515063 | 35 | // Utility function to log data |
Bobty | 12:a52996515063 | 36 | void Logger::LogData(const char* format, ...) |
Bobty | 12:a52996515063 | 37 | { |
Bobty | 12:a52996515063 | 38 | char fileNameBuf[60]; |
Bobty | 12:a52996515063 | 39 | strcpy(fileNameBuf, _dataLogFileBase); |
Bobty | 12:a52996515063 | 40 | time_t seconds = time(NULL); |
Bobty | 12:a52996515063 | 41 | strftime(fileNameBuf+strlen(fileNameBuf), sizeof(fileNameBuf)-strlen(fileNameBuf), "Data_%Y%m%d.txt", localtime(&seconds)); |
Bobty | 12:a52996515063 | 42 | |
Bobty | 12:a52996515063 | 43 | FILE* fp = fopen(fileNameBuf, "a"); |
Bobty | 12:a52996515063 | 44 | if (fp == NULL) |
Bobty | 12:a52996515063 | 45 | { |
Bobty | 12:a52996515063 | 46 | printf ("Data Log ... Filename %s not found\r\n", _eventLogFileName); |
Bobty | 12:a52996515063 | 47 | } |
Bobty | 12:a52996515063 | 48 | else |
Bobty | 12:a52996515063 | 49 | { |
Bobty | 12:a52996515063 | 50 | va_list argptr; |
Bobty | 12:a52996515063 | 51 | va_start(argptr, format); |
Bobty | 12:a52996515063 | 52 | vfprintf(fp, format, argptr); |
Bobty | 12:a52996515063 | 53 | va_end(argptr); |
Bobty | 12:a52996515063 | 54 | fprintf(fp, "\r\n"); |
Bobty | 12:a52996515063 | 55 | fclose(fp); |
Bobty | 12:a52996515063 | 56 | } |
Bobty | 12:a52996515063 | 57 | } |