Processor Metadata topic

Classes for the using the processor as a sensor.

Introduction

The processor can return the number of "samples" it has taken, the amount of RAM it has available and, for some boards, the battery voltage (EnviroDIY Mayfly, Sodaq Mbili, Ndogo, Autonomo, and One, Adafruit Feathers). The version of the board is required as input (ie, for a EnviroDIY Mayfly: "v0.3" or "v0.4" or "v0.5"). Use a blank value (ie, "") for un-versioned boards. Please note that while you cannot opt to average more than one sample, it really makes no sense to do so for the processor. These values are only intended to be used as diagnostics.

Sensor Datasheet

Sensor Constructor

ProcessorStats::ProcessorStats(const char* version, uint8_t measurementsToAverage = 1)

Construct a new Processor Stats object for a known, unmodified development board using the standard manufacturer core for that board.

Parameters
version The version of the MCU, if applicable. This is used to fill in the correct battery connection information.
measurementsToAverage The number of measurements to take and average before giving a "final" result from the sensor; optional with a default value of 1.

Boards that can be used with this constructor:

  • EnviroDIY
    • Mayfly
      • the version must be one of "v0.3", "v0.4", "v0.5", "v0.5b", "v1.0", or "v1.1"
    • Stonefly
      • the version must be "v0.1"
  • Adafruit
    • Feather M0 variants (M0, M0 Express, M0 Adalogger, etc)
    • Feather M4 variants
    • Feather 328p variants
      • WARNING: The processor isn't powerful enough for this library. To use it, you would have to strip the library down.
    • Feather 32U4 variants (Basic proto, RadioFruit, BlueFruit, etc)
      • WARNING: The processor isn't powerful enough for this library. To use it, you would have to strip the library down.
  • Sodaq
    • Mbili
    • Ndogo
    • One
      • the version must be "v0.1" or "v0.2"
    • Autonomo
      • the version must be "v0.1"


Example Code

The processor is used as a sensor in all of the examples, including the menu a la carte example.

1#include <sensors/ProcessorStats.h>
2
3// Create the main processor chip "sensor" - for general metadata
4#if defined(ENVIRODIY_STONEFLY_M4)
5const char* mcuBoardVersion = "v0.1";
6#elif defined(ARDUINO_AVR_ENVIRODIY_MAYFLY)
7const char* mcuBoardVersion = "v1.1";
8#else
9const char* mcuBoardVersion = "unknown";
10#endif
11ProcessorStats mcuBoard(mcuBoardVersion, 5);
12
13// Create sample number, battery voltage, free RAM, and reset cause variable
14// pointers for the processor
15Variable* mcuBoardBatt = new ProcessorStats_Battery(
16 &mcuBoard, "12345678-abcd-1234-ef00-1234567890ab");
17Variable* mcuBoardAvailableRAM = new ProcessorStats_FreeRam(
18 &mcuBoard, "12345678-abcd-1234-ef00-1234567890ab");
19Variable* mcuBoardSampNo = new ProcessorStats_SampleNumber(
20 &mcuBoard, "12345678-abcd-1234-ef00-1234567890ab");
21Variable* mcuBoardReset = new ProcessorStats_ResetCode(
22 &mcuBoard, "12345678-abcd-1234-ef00-1234567890ab");

Classes

class ProcessorStats
The main class to use the main processor (MCU) as a sensor.
class ProcessorStats_Battery
The Variable sub-class used for the battery voltage output measured by the processor's on-board ADC.
class ProcessorStats_FreeRam
The Variable sub-class used for the free RAM measured by the MCU.
class ProcessorStats_SampleNumber
The Variable sub-class used for the sample number output from the main processor.
class ProcessorStats_ResetCode
The Variable sub-class used for the reset cause recorded by the MCU.

Defines

#define LOGGER_BOARD = "EnviroDIY Mayfly"
Pretty text for the board name derived from the board's compiler define.

Sensor Variable Counts

The number of variables that can be returned by the main processor

#define PROCESSOR_NUM_VARIABLES = 4
Sensor::_numReturnedValues; the processor can report 4 values: battery, free ram, sample number, and reset cause.
#define PROCESSOR_INC_CALC_VARIABLES = 1
Sensor::_incCalcValues; sample number is (sort-of) calculated.

Sensor Timing

The sensor timing for the processor/mcu

  • Timing variables do not apply to the processor in the same way they do to other sensors.
#define PROCESSOR_WARM_UP_TIME_MS = 0
Sensor::_warmUpTime_ms; the processor is never powered down - there is no waiting for the processor to warmup.
#define PROCESSOR_STABILIZATION_TIME_MS = 0
Sensor::_stabilizationTime_ms; the processor is never powered down - there is no waiting for the processor to stabilize.
#define PROCESSOR_MEASUREMENT_TIME_MS = 0
Sensor::_measurementTime_ms; the processor measurement times aren't measurable.

Battery Voltage

The battery voltage variable from the processor/mcu This is the voltage as measured on the battery attached to the MCU using the inbuilt ADC, if applicable.

  • Range is assumed to be 0 to 5V
  • Accuracy is processor dependent
#define PROCESSOR_BATTERY_RESOLUTION = 3
Decimals places in string representation; battery voltage should have 3.
#define PROCESSOR_BATTERY_VAR_NUM = 0
Battery voltage is stored in sensorValues[0].
#define PROCESSOR_BATTERY_VAR_NAME = "batteryVoltage"
Variable name in ODM2 controlled vocabulary; batteryVoltage.
#define PROCESSOR_BATTERY_UNIT_NAME = "volt"
Variable unit name in ODM2 controlled vocabulary; "volt".
#define PROCESSOR_BATTERY_DEFAULT_CODE = "Battery"
Default variable short code; "Battery".

Available RAM

The RAM variable from the processor/mcu This is the amount of free space on the processor when running the program. This is just a diagnostic value. This number should always remain the same for a single logger program. If this number is not constant over time, there is a memory leak and something wrong with your logging program.

  • Range is 0 to full RAM available on processor

ProcessorStats_FreeRam::ProcessorStats_FreeRam(ProcessorStats* parentSense, const char* uuid = "", const char* varCode = "FreeRam") explicit

Construct a new ProcessorStats_FreeRam object.

Parameters
parentSense The parent ProcessorStats providing the result values.
uuid A universally unique identifier (UUID or GUID) for the variable; optional with the default value of an empty string.
varCode A short code to help identify the variable in files; optional with a default value of "FreeRam".

#define PROCESSOR_RAM_RESOLUTION = 0
Decimals places in string representation; ram should have 0 - resolution is 1 bit.
#define PROCESSOR_RAM_VAR_NUM = 1
Free RAM is stored in sensorValues[1].
#define PROCESSOR_RAM_VAR_NAME = "freeSRAM"
Variable name in ODM2 controlled vocabulary; freeSRAM.
#define PROCESSOR_RAM_UNIT_NAME = "Bit"
Variable unit name in ODM2 controlled vocabulary; "Bit".
#define PROCESSOR_RAM_DEFAULT_CODE = "FreeRam"
Default variable short code; "FreeRam".

Sample Number

The sample number variable from the processor/mcu

ProcessorStats_SampleNumber::ProcessorStats_SampleNumber(ProcessorStats* parentSense, const char* uuid = "", const char* varCode = "SampNum") explicit

Construct a new ProcessorStats_SampleNumber object.

Parameters
parentSense The parent ProcessorStats providing the result values.
uuid A universally unique identifier (UUID or GUID) for the variable; optional with the default value of an empty string.
varCode A short code to help identify the variable in files; optional with a default value of "SampNum".

#define PROCESSOR_SAMPNUM_RESOLUTION = 0
Decimals places in string representation; sample number should have 0 - resolution is 1.
#define PROCESSOR_SAMPNUM_VAR_NUM = 2
Sample number is stored in sensorValues[2].
#define PROCESSOR_SAMPNUM_VAR_NAME = "sequenceNumber"
Variable name in ODM2 controlled vocabulary; sequenceNumber.
#define PROCESSOR_SAMPNUM_UNIT_NAME = "Dimensionless"
Variable unit name in ODM2 controlled vocabulary; "Dimensionless" (sequence number)
#define PROCESSOR_SAMPNUM_DEFAULT_CODE = "SampNum"
Default variable short code; "SampNum".

Cause of last processor reset.

The reset cause code variable from the processor/mcu. This value only changes when the board is reset. You must look up the meaning of the code in the processor datasheet.

ProcessorStats_ResetCode::ProcessorStats_ResetCode(ProcessorStats* parentSense, const char* uuid = "", const char* varCode = "ResetCode") explicit

Construct a new ProcessorStats_ResetCode object.

Parameters
parentSense The parent ProcessorStats providing the result values.
uuid A universally unique identifier (UUID or GUID) for the variable; optional with the default value of an empty string.
varCode A short code to help identify the variable in files; optional with a default value of "ResetCode".

#define PROCESSOR_RESET_RESOLUTION = 0
Decimals places in string representation; ram should have 0 - it's just a code.
#define PROCESSOR_RESET_VAR_NUM = 3
Free RAM is stored in sensorValues[1].
#define PROCESSOR_RESET_VAR_NAME = "instrumentStatusCode"
Variable name in ODM2 controlled vocabulary; "instrumentStatusCode".
#define PROCESSOR_RESET_UNIT_NAME = "dimensionless"
Variable unit name in ODM2 controlled vocabulary; "dimensionless".
#define PROCESSOR_RESET_DEFAULT_CODE = "ResetCode"
Default variable short code; "ResetCode".

Define documentation

#define LOGGER_BOARD = "EnviroDIY Mayfly"

Pretty text for the board name derived from the board's compiler define.


#define PROCESSOR_NUM_VARIABLES = 4

Sensor::_numReturnedValues; the processor can report 4 values: battery, free ram, sample number, and reset cause.


#define PROCESSOR_INC_CALC_VARIABLES = 1

Sensor::_incCalcValues; sample number is (sort-of) calculated.


#define PROCESSOR_WARM_UP_TIME_MS = 0

Sensor::_warmUpTime_ms; the processor is never powered down - there is no waiting for the processor to warmup.


#define PROCESSOR_STABILIZATION_TIME_MS = 0

Sensor::_stabilizationTime_ms; the processor is never powered down - there is no waiting for the processor to stabilize.


#define PROCESSOR_MEASUREMENT_TIME_MS = 0

Sensor::_measurementTime_ms; the processor measurement times aren't measurable.


#define PROCESSOR_BATTERY_RESOLUTION = 3

Decimals places in string representation; battery voltage should have 3.

The resolution is of the EnviroDIY Mayfly is 0.005V, we will use that resolution for all processors.

ProcessorStats_Battery::ProcessorStats_Battery(ProcessorStats* parentSense, const char* uuid = "", const char* varCode = "Battery") explicit

Construct a new ProcessorStats_Battery object.

Parameters
parentSense The parent ProcessorStats providing the result values.
uuid A universally unique identifier (UUID or GUID) for the variable; optional with the default value of an empty string.
varCode A short code to help identify the variable in files; optional with a default value of "batteryVoltage".


#define PROCESSOR_BATTERY_VAR_NUM = 0

Battery voltage is stored in sensorValues[0].


#define PROCESSOR_BATTERY_VAR_NAME = "batteryVoltage"

Variable name in ODM2 controlled vocabulary; batteryVoltage.


#define PROCESSOR_BATTERY_DEFAULT_CODE = "Battery"

Default variable short code; "Battery".


#define PROCESSOR_RAM_RESOLUTION = 0

Decimals places in string representation; ram should have 0 - resolution is 1 bit.


#define PROCESSOR_RAM_VAR_NUM = 1

Free RAM is stored in sensorValues[1].


#define PROCESSOR_RAM_DEFAULT_CODE = "FreeRam"

Default variable short code; "FreeRam".


#define PROCESSOR_SAMPNUM_RESOLUTION = 0

Decimals places in string representation; sample number should have 0 - resolution is 1.


#define PROCESSOR_SAMPNUM_VAR_NUM = 2

Sample number is stored in sensorValues[2].


#define PROCESSOR_SAMPNUM_VAR_NAME = "sequenceNumber"

Variable name in ODM2 controlled vocabulary; sequenceNumber.


#define PROCESSOR_SAMPNUM_UNIT_NAME = "Dimensionless"

Variable unit name in ODM2 controlled vocabulary; "Dimensionless" (sequence number)


#define PROCESSOR_SAMPNUM_DEFAULT_CODE = "SampNum"

Default variable short code; "SampNum".


#define PROCESSOR_RESET_RESOLUTION = 0

Decimals places in string representation; ram should have 0 - it's just a code.


#define PROCESSOR_RESET_VAR_NUM = 3

Free RAM is stored in sensorValues[1].


#define PROCESSOR_RESET_VAR_NAME = "instrumentStatusCode"

Variable name in ODM2 controlled vocabulary; "instrumentStatusCode".


#define PROCESSOR_RESET_UNIT_NAME = "dimensionless"

Variable unit name in ODM2 controlled vocabulary; "dimensionless".


#define PROCESSOR_RESET_DEFAULT_CODE = "ResetCode"

Default variable short code; "ResetCode".