LOGGER  Logger
Data Logging using ESP8266
Classes | Macros | Functions | Variables
dataservices.h File Reference
#include "basetype.h"
#include "sensordatatype.h"

Go to the source code of this file.

Classes

struct  LogElement_t
 Structure that gets logged. More...
 

Macros

#define MAX_SENSORS   30
 < version of this include file More...
 

Functions

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

Variables

uint32_t secondsBetweenSamples
 

Detailed Description

Data logging and reporting service routines.

This module is responsible for storing and retrieving data. It also is responsible for time keeping on the elements that are stored. The LogElement_t structure is the primitive element that is logged. It comprises one sample of the datums logged for this device. The Sensor class is responsible for how the data is stored in the data block of the LogElement_t structure. (Pin values of the processor are logged in a regular data cell.)

The dataStorage is divided between inputs that come from multiple devices. There are access functions to read and/or set the data storage elements. The configuration of the data storage depends on what devices are attached to the LOGGER. See the Sensor class for a description of what devices are attached.

The data storage model can support appending to a file or simply writing to a NAND flash. There is a tacit assumption that Data stored in flash parts starts as all ones and gets written to zeros. When the data of an element is not valid all of the bits will be on.

There may be intervals when samples have not been taken. The most recent sample taken is copied to each element and samplesSinceValid keeps track of how far it is (in sample intervals not seconds) to get to the most recent sample.

There are 32 bits of overhead. With 30 16 bit samples per element this gives a block size of 64 bytes. On a 32Gigabyte card at one sample per second you get 16 years of data, (less a bit for file system overhead). At one sample every 5 seconds you get 81 years of data.

Macro Definition Documentation

#define MAX_SENSORS   30

< version of this include file

Maximum number of unique sensors that can be stored in the database.

Function Documentation

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
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
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
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
void dataservicesDumpElementIDvalue ( Print *  pPrinter,
uint8_t  indent,
LogElement_t element,
FormatType_t  formatType,
SensorDatatypeID_t  datatype = SDallTypes 
)

Convert the value of an element to a string. Limit what is output for each sensor to the ID and value of that sensor. 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
datatypewhich members of the element to dump
void dataservicesDumpNthElement ( Print *  pPrinter,
uint32_t  index 
)

Report the Nth database element

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

Report the temporary elements

Parameters
maxElementsmaximum number of elements to print
time_t dataservicesFirstLegalTime ( )

Get the first legal time in the database

Returns
the first time that can be found in the database
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
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
void dataservicesLoop ( )

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

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

uint32_t secondsBetweenSamples

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