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

Go to the source code of this file.

Macros

#define ILLEGAL_TEMPERATURE   (1000*1000)
 

Typedefs

typedef uint32_t SENSOR_READ_CALLBACK(uint8_t *pUniqueID, uint8_t sensorSpecific)
 Function to call to read a sensor.
 
typedef SENSOR_READ_CALLBACKpSENSOR_READ_CALLBACK
 pointer to function to call to read a sensor
 

Enumerations

enum  SensorInterfaceID_t { InterfaceProcessorPin, InterfaceOneWire, InterfaceI2C }
 How the sensor is interfaced to the system.
 
enum  SensorTypeID_t {
  SensorProcessorADCpin, SensorProcessorIOpin, SensorDS18x20, SensorTCA9535,
  SensorAD7091R, SensorDLVRpressure
}
 
enum  GraphType_t { GraphTypeAllIntervals, GraphTypeAllSamples }
 Define types of graphs to output.
 

Functions

void sensorlibraryInit ()
 < version of this module More...
 
void sensorlibraryDumpSensors (Print *pPrinter=&Serial, FormatType_t formatType=FormatForConsole)
 
String sensorlibraryInterfaceGetName (SensorInterfaceID_t interface)
 
String sensorlibrarySensorTypeGetName (SensorTypeID_t sensorType)
 
int8_t sensorlibraryCreateSensor (uint8_t *uniqueID, String name, uint8_t bitsOfData, bool isSigned, SensorInterfaceID_t interface, SensorTypeID_t sensorType, SensorDatatypeID_t datatype, uint8_t decimalPlaces, uint8_t sensorSpecific, pSENSOR_READ_CALLBACK pReader)
 
void sensorlibraryDisableSensor (uint8_t sensorID)
 
void sensorlibraryReadSensors (LogElement_t &element)
 
void sensorlibraryDumpElement (Print *pPrinter, uint8_t indent, LogElement_t &element, FormatType_t formatType=FormatForConsole, SensorDatatypeID_t datatype=SDallTypes)
 
void sensorlibraryDumpElementIDvalue (Print *pPrinter, uint8_t indent, LogElement_t &element, FormatType_t formatType=FormatForConsole, SensorDatatypeID_t datatype=SDallTypes)
 
void sensorlibraryDumpSensorName (Print *pPrinter, uint8_t sensorID, FormatType_t formatType=FormatForConsole)
 
void sensorlibraryDumpSensorUniqueID (Print *pPrinter, uint8_t sensorID, FormatType_t formatType=FormatForConsole)
 
void sensorlibraryDumpSensorValue (Print *pPrinter, uint8_t indent, uint32_t value, uint8_t sensorID, FormatType_t formatType=FormatForConsole)
 
uint32_t sensorlibraryExtractPulseCount (uint8_t index, LogElement_t &element, uint32_t defaultCount)
 
void sensorlibraryDumpSampleList (Print *pPrinter, LogElement_t &element, SensorDatatypeID_t datatype=SDallTypes)
 
void sensorlibrarySetPulsesSinceBoot (LogElement_t &element)
 
void sensorlibraryDumpAddColumns (Print *pPrinter, GraphType_t graphType, SensorDatatypeID_t datatype)
 
String sensorlibraryGetSensorName (uint8_t index)
 
void sensorlibraryDumpSensorById (uint8_t index, Print *pPrinter, FormatType_t formatType)
 
uint8_t sensorlibraryGetI2Caddress (uint8_t sensorID)
 
uint8_t sensorlibraryGetSensorSpecificData (uint8_t sensorID)
 

Variables

const char *const datatypeNames []
 

Detailed Description

Manage a library of sensors and the instances of those sensors that are observed.

Macro Definition Documentation

#define ILLEGAL_TEMPERATURE   (1000*1000)

A temperature value that can be used to flag errors. Temperatures are in degrees * 1000 C

Enumeration Type Documentation

The type of sensor.

NOTES: Each processor pin used as an ADC will appear in the list and will have type SensorProcessorADCpin. The sensorSpecific is used to store the processor pin number for that pin.

A single SensorAD7091R will appear as four sensors. The sensorSpecific field is use to identify which of the four ADCinputs is logged.

Function Documentation

int8_t sensorlibraryCreateSensor ( uint8_t *  uniqueID,
String  name,
uint8_t  bitsOfData,
bool  isSigned,
SensorInterfaceID_t  interface,
SensorTypeID_t  sensorType,
SensorDatatypeID_t  datatype,
uint8_t  decimalPlaces,
uint8_t  sensorSpecific,
pSENSOR_READ_CALLBACK  pReader 
)

Establish a new sensor in the library.

Parameters
uniqueIDunique among sensors of the same type
namestring to emit for people
bitsOfDatabits in one sample
isSigneddata is a signed value
interfacehow the sensor is connected
sensorTypewhat kind of device provides the sensing
datatypetype of information that is stored
decimalPlacesplaces for display as a fixed point number
sensorSpecificinfo about this sensor
pReadercallback to read the sensor
Returns
unique ID for sensor created, -1 if no space
void sensorlibraryDisableSensor ( uint8_t  sensorID)

Once a sensor is created it can be turned off. This disables printout of the sensor and is typically used to decomission a sensor that is not available because the hardware is being used for another purpose

void sensorlibraryDumpAddColumns ( Print *  pPrinter,
GraphType_t  graphType,
SensorDatatypeID_t  datatype 
)

Dump the addColumn lines for a graph. Lines appropriate to sensors that are intervals can be emitted or lines that are appropriate to sensors that are samples.

??? future enhancements may add other graph types which will need updates to the types of graphs that can be output.

The lines have the form:

data.addColumn('number', 'ADC 0');
Parameters
pPrinterwhere to send the ouput
graphTypewhat kind of graph is being emitted
datatypetype of data elements to put in the list
void sensorlibraryDumpElement ( Print *  pPrinter,
uint8_t  indent,
LogElement_t element,
FormatType_t  formatType = FormatForConsole,
SensorDatatypeID_t  datatype = SDallTypes 
)

Print the contents of an element reporting the value logged in the element by the sensorlibraryReadSensors call.

Parameters
pPrinterwhere to sent the output
indentindentation for each new line
elementblock of data to work on
formatTypetype of output to do
datatypelimit output to this datatype
void sensorlibraryDumpElementIDvalue ( Print *  pPrinter,
uint8_t  indent,
LogElement_t element,
FormatType_t  formatType = FormatForConsole,
SensorDatatypeID_t  datatype = SDallTypes 
)

Print the contents of an element reporting the value logged in the element by the sensorlibraryReadSensors call. Limit the ouptut of each sensor to the ID and value of that sensor.

Parameters
pPrinterwhere to sent the output
indentindentation for each new line
elementblock of data to work on
formatTypetype of output to do
datatypelimit output to this datatype
void sensorlibraryDumpSampleList ( Print *  pPrinter,
LogElement_t element,
SensorDatatypeID_t  datatype = SDallTypes 
)

Print a comma seperated list of sample values. Skip over the pulse counts and pin arrays

Parameters
pPrinterwhere to send the output
elementelement to dump samples from
datatypetype of data elements to put in the list
void sensorlibraryDumpSensorById ( uint8_t  index,
Print *  pPrinter,
FormatType_t  formatType 
)

Dump a sensor given the ID returned by sensorlibraryCreateSensor.

Parameters
indexSensor ID
pPrinterwhere to send the ouput
formatTypehow to format the output
void sensorlibraryDumpSensorName ( Print *  pPrinter,
uint8_t  sensorID,
FormatType_t  formatType = FormatForConsole 
)

Dump the name of a sensor based on the ID index of the sensor determined when the sensor was created with sensorlibraryCreateSensor.

Parameters
pPrinterwhere to sent the output
sensorIDID returned by sensorlibraryCreateSensor
formatTypehow to format the output
void sensorlibraryDumpSensors ( Print *  pPrinter = &Serial,
FormatType_t  formatType = FormatForConsole 
)

Dump a list of sensors

Parameters
pPrinterprinter to use for output
formatTypetype of ouput to emit
void sensorlibraryDumpSensorUniqueID ( Print *  pPrinter,
uint8_t  sensorID,
FormatType_t  formatType = FormatForConsole 
)

Dump the unique ID of a sensor based on the ID index of the sensor determined when the sensor was created with sensorlibraryCreateSensor.

Parameters
pPrinterwhere to sent the output
sensorIDID returned by sensorlibraryCreateSensor
formatTypehow to format the output
void sensorlibraryDumpSensorValue ( Print *  pPrinter,
uint8_t  indent,
uint32_t  value,
uint8_t  sensorID,
FormatType_t  formatType = FormatForConsole 
)

Dump the value of a sensor based on the unique ID of the sensor determined when the sensor was created with sensorlibraryCreateSensor.

Parameters
pPrinterwhere to sent the output
indentindentation for each new line
valuevalue to dump
sensorIDID returned by sensorlibraryCreateSensor
formatTypeformat of output
uint32_t sensorlibraryExtractPulseCount ( uint8_t  index,
LogElement_t element,
uint32_t  defaultCount 
)

Given an element extract the Nth pulse count cell.

Parameters
indexwhich pulse count to extract
elementelement to fetch it from
defaultCountvalue to store in element if value found is invalid
Returns
the value of the Nth pulse count cell from the element
uint8_t sensorlibraryGetI2Caddress ( uint8_t  sensorID)

Look up the I2C address for a sensor. The I2C address is stored in the last byte of the uniqueID for TCA9535 device pins.

Parameters
sensorIDindex into 'sensors' table
Returns
I2C address for the device which contains this I/O pin
String sensorlibraryGetSensorName ( uint8_t  index)

Fetch a pointer to the name of a sensor given the ID returned by sensorlibraryCreateSensor.

Parameters
indexSensor ID
Returns
: name of the sensor
uint8_t sensorlibraryGetSensorSpecificData ( uint8_t  sensorID)

Look up the sensor specific data for a sensor.

Parameters
sensorIDindex into 'sensors' table
Returns
I2C address for the device which contains this I/O pin
void sensorlibraryInit ( )

< version of this module

Initialize the onewire services, call once at system startup.

String sensorlibraryInterfaceGetName ( SensorInterfaceID_t  interface)

Get the name of a sensor interface

Parameters
interfacethe interface ID
Returns
: name of the interface as a String
void sensorlibraryReadSensors ( LogElement_t element)

Read each sensor in the library and place it into the element that gets logged.

Parameters
elementblock of data to write data to
String sensorlibrarySensorTypeGetName ( SensorTypeID_t  sensorType)

Get the name of a sensor type

Parameters
sensorTypethe sensor type ID
Returns
: name of the sensor type as a String
void sensorlibrarySetPulsesSinceBoot ( LogElement_t element)

For all sensors that are pulse counters read the value from the element and tell the pulse counter module the initial value. This should be called with the latest element from the database at system startup to update the pulse counters with the pulses to date.

Parameters
elementelement to take initial pulses from

Update the pulse counter module

Variable Documentation

const char* const datatypeNames[]

This array is indexed by a SensorDatatypeID_t to get the ASCIZ name of that type.