LOGGER  Logger
Data Logging using ESP8266
Classes | Macros | Functions | Variables
dataservices.cpp File Reference
#include <arduino.h>
#include <Time.h>
#include "dataservices.h"
#include "consoleio.h"
#include "flashservices.h"
#include "huzzahpins.h"
#include "sensorlibrary.h"
#include "services.h"
#include "sleepservices.h"
#include "timeservices.h"
#include "webservices.h"

Classes

struct  ConfigurationInfo_t
 Configuration information stored at the beginning of the database. More...
 

Macros

#define dataservicesEdit   1
 version of this module
 
#define DATABASE_MAJOR_VERSION   1
 Major version of the database.
 
#define DATABASE_MINOR_VERSION   1
 Minor version of the database.
 

Functions

EXTERNDEF void dataservicesInit ()
 Initialize the data services, call once at system startup.
 
EXTERNDEF void dataservicesLogElement (LogElement_t &element, time_t sampleTime, uint32_t msSinceBoot)
 
EXTERNDEF bool dataservicesReadElement (time_t sampleTime, LogElement_t *pElement, time_t *pTimeError)
 
EXTERNDEF void dataservicesDumpElement (Print *pPrint, uint8_t indent, LogElement_t &element, FormatType_t formatType, bool reportDelta, SensorDatatypeID_t datatype)
 
EXTERNDEF void dataservicesDump (Print *pPrinter, bool formatForWeb)
 
EXTERNDEF void dataservicesDumpTemporaries (uint8_t maxElements)
 
EXTERNDEF void dataservicesDumpDatabase (time_t timeToStart, uint8_t maxElements)
 
EXTERNDEF void dataservicesDumpNthElement (Print *pPrinter, uint32_t index)
 
EXTERNDEF void dataservicesDumpElementAtUnixTime (Print *pPrinter, uint8_t indent, time_t elementTime, FormatType_t formatType)
 
EXTERNDEF void dataservicesReadConfiguration ()
 Read the configuration information from the flash storage.
 
EXTERNDEF void dataservicesInitialize ()
 
EXTERNDEF void dataservicesDumpConfiguration ()
 Dump the configuration information.
 
EXTERNDEF void dataservicesLoop ()
 
EXTERNDEF time_t dataservicesFirstLegalTime ()
 
time_t dataservicesLatestLegalTime ()
 

Variables

EXTERNVAR uint32_t secondsBetweenSamples
 

Detailed Description

Data logging and reporting services.

Function Documentation

EXTERNDEF void dataservicesDump ( Print *  pPrinter,
bool  formatForWeb 
)

Report the state of the the dataservices module. When formatting for the web emit fields as rows of a table.

Parameters
pPrinterwhere to print it
formatForWebtrue to emit web formatting
EXTERNDEF void dataservicesDumpDatabase ( time_t  timeToStart,
uint8_t  maxElements 
)

Report the database elements. When a time before the first element in the database is presented start with the first element in the database.

Parameters
timeToStarttime of first element to dump
maxElementsmaximum number of elements to print
EXTERNDEF void dataservicesDumpElement ( Print *  pPrinter,
uint8_t  indent,
LogElement_t element,
FormatType_t  formatType,
bool  reportDelta,
SensorDatatypeID_t  datatype = SDallTypes 
)

Convert the value of an element to a string. When formatted for the web the output expects to be emitted in a cell of a table. The

and are not included in the output.

Parameters
pPrinterwhere to print the element
indentnumber of spaces to indent each new line
elementthe element to dump
formatTypeoutput format type
reportDeltatrue to report time since the sample was taken
datatypewhich members of the element to dump
EXTERNDEF void dataservicesDumpElementAtUnixTime ( Print *  pPrinter,
uint8_t  indent,
time_t  elementTime,
FormatType_t  formatType 
)

Convert the value of an element to a string. Emit the time information and the associated value.

Parameters
pPrinterwhere to print the element
indentnumber of spaces to indent each new line
elementTimethe element to dump
formatTypeoutput format type
EXTERNDEF void dataservicesDumpNthElement ( Print *  pPrinter,
uint32_t  index 
)

Report the Nth database element

Parameters
pPrinterwhere to print to
indexelement to report
EXTERNDEF void dataservicesDumpTemporaries ( uint8_t  maxElements)

Report the temporary elements

Parameters
maxElementsmaximum number of elements to print
EXTERNDEF time_t dataservicesFirstLegalTime ( )

Get the first legal time in the database

Returns
the first time that can be found in the database
EXTERNDEF void dataservicesInitialize ( )

Flush all configuration and logged data. Reset the configuration to the default and start the log.

time_t dataservicesLatestLegalTime ( )

Get the most recent legal time in the database

Returns
the latest time that can be found in the database
EXTERNDEF void dataservicesLogElement ( LogElement_t element,
time_t  sampleTime,
uint32_t  msSinceBoot 
)

Log a set of values. The log is done at the current time.

Parameters
elementthe element to log
sampleTimetime the sample was taken (0 if unix time is not valid)
msSinceBootms since boot of when the sample was taken
EXTERNDEF void dataservicesLoop ( )

Perform periodic tasks managing data services. Call frequently as the system runs. Does not block.

EXTERNDEF bool dataservicesReadElement ( time_t  sampleTime,
LogElement_t pElement,
time_t *  pTimeError 
)

Get the value logged at a particular time. Elements for times in the future do not exist. A request for an element prior to the beginning of the entire log will report as not existing.

Parameters
sampleTimeUNIX time to retrieve from the log
pElementpointer to where to store the element
pTimeErrorpoint to where to store how different the actual sample time is from the requested time
Returns
true if the element exists

Variable Documentation

EXTERNVAR uint32_t secondsBetweenSamples

Time between samples stored in the database. As read from the configuration data at the beginning of the database.