![]() |
Data Gator
Hardware and software documentation for the Data Gator project.
|
Utilities for logging data. More...
#include <Preferences.h>
#include <NTPClient.h>
#include <TimeStamp.hpp>
#include <SDLogger.hpp>
#include <SDReader.hpp>
Go to the source code of this file.
Functions | |
std::string | cache_retrieve_timestamp () |
void | cache_timestamp (std::string timestamp) |
bool | init_data_logger () |
Initialize logging interfaces. | |
std::string | get_log_filename (TimeStampParser *) |
void | log_to_sd_file (std::string filename, std::string time, std::string topic, std::string message) |
void | cache_log_offset (int log_offset) |
int | cache_retrieve_log_offset (void) |
void | log_to_sd_file (SDLogger *l, std::string time, std::string topic, std::string message) |
Variables | |
Preferences | gator_prefs |
Reference to non-volatile-storage on ESP32. | |
bool | logging_available = false |
is some logging interface available? | |
bool | absolute_timestamp_available = false |
is an exact/accurate timestamp available? | |
bool | logged_relative_data = false |
relatively accurate timestamp used, last exact timestamp + # of minutes/resets elapsed | |
std::string | time_stamp_to_cache = "" |
the formatted timestamp to write to non-volatile memory for next reset | |
SDLogger * | logger = NULL |
reads and writes to files | |
TimeStampBuilder * | tsb = NULL |
builds timestamp strings | |
TimeStampParser * | tsp = NULL |
parses timestamp strings | |
Utilities for logging data.
Define the helper functions/utilities which have been written for logging data on the Data Gators.
Emphasis is placed on making this as simple to use as possible. Unfortunately it is likely that the implementation is rather difficult to follow due to the number of edge cases covered. These include:
Key functionality includes functions for:
Save the reset count.
[in] | log_offset | The offset in ticks. |
Retrieves the reset count.
std::string cache_retrieve_timestamp | ( | ) |
Retrieve time stamp from non-volatile memory so that it can be used for log file access.
void cache_timestamp | ( | std::string | timestamp | ) |
Cache/update the last known absolute timestamp from the NTPClient to non-volatile memory
[in] | timestamp | A timestamp string following the syntax of TimeStampBuilder |
std::string get_log_filename | ( | TimeStampParser * | tsp | ) |
Generate a file name based on the current time stamp. Should only be called if TimeStampBuilder has been updated.
[in] | tsp | TimeStampParser which defines parser for reading the current time stamp from a string. |
log_<month>-<day>-<year>
bool init_data_logger | ( | ) |
Initialize logging interfaces.
Perform all initialization necessary before logging any data with log_message to the uSD card.
void log_to_sd_file | ( | SDLogger * | l, |
std::string | time, | ||
std::string | topic, | ||
std::string | message | ||
) |
Write an MQTT message to a file on the SD card. Requires a time stamp and filename.
[in] | l | The SDLogger instance with all filename and separator information pre-set |
[in] | time | The time hr:min:sec+offset that will be written to the log file |
[in] | topic | The mqtt topic the data should have been logged to |
[in] | message | The mqtt message containing the data we want to save |
void log_to_sd_file | ( | std::string | filename, |
std::string | time, | ||
std::string | topic, | ||
std::string | message | ||
) |
Write an MQTT message to a file on the SD card. Requires a time stamp and filename.
[in] | filename | The string file name to log the topic and message to. |
[in] | time | string time, formatted according to TimeStampBuilder. |
[in] | topic | The topic, according to MQTT format. |
[in] | message | The message which contains data. Often JSON object. |
is an exact/accurate timestamp available?
Flag set during initialization, indicates that WiFi connection to NTP for update was obtained.
|
extern |
Reference to non-volatile-storage on ESP32.
Reference to non-volatile-storage on ESP32.
NVS memory access interface.
relatively accurate timestamp used, last exact timestamp + # of minutes/resets elapsed
Flag set to indicate that no network connection was available for NTP update to get precise timestamp.
is some logging interface available?
Flag showing that some logging interface is available. May be uSD card or MQTT.
std::string time_stamp_to_cache = "" |
the formatted timestamp to write to non-volatile memory for next reset
The timestamp, last exact timestamp + offset to write to non-volatile storage. This timestamp will be retrieved on next reset and replaced if network connection to NTP available. If NTP not available, then the offset is incremented.