Wombat Environmental Node 1.0
An environmental node for SDI-12 and digital sensors.
|
Global utility functions. More...
#include <Arduino.h>
#include "Utils.h"
#include <SPIFFS.h>
#include "DeviceConfig.h"
#include "TCA9534.h"
#include "CAT_M1.h"
#include "globals.h"
#include "sd-card/interface.h"
Macros | |
#define | TAG "utils" |
Functions | |
bool | getNTPTime (SARA_R5 &r5) |
size_t | readFromStreamUntil (Stream &stream, const char delim, char *const buffer, const size_t max) |
Read characters from stream into buffer until the delim char is encountered. More... | |
void | streamPassthrough (Stream *s1, Stream *s2) |
int | waitForChar (Stream &stream, uint32_t timeout) |
Wait up to timeout ms for any character to appear in stream. More... | |
JsonObjectConst | getSensorDefn (const char *const vendor, const char *const model) |
JsonObjectConst | getSensorDefn (const size_t sensor_idx, const sensor_list &sensors) |
void | enable12V (void) |
Enable the SDI-12 power line if it is not already enabled. More... | |
void | disable12V (void) |
Disable the SDI-12 power line. More... | |
const char * | iso8601 (void) |
void | log_to_sdcard (const char *msg) |
void | log_to_sdcardf (const char *fmt,...) |
int | read_spiffs_file (const char *const filename, char *buffer, const size_t max_length, size_t &bytes_read) |
int | read_r5_file (const String &filename, char *const buffer, const size_t length, size_t &bytes_read, SARA_R5_error_t &r5_err) |
bool | wait_for_at (void) |
Waits until an AT command to the R5 modem returns OK, or a timeout is reached. More... | |
bool | connect_to_internet (void) |
Get the R5 modem connected to the internet. More... | |
Variables | |
TCA9534 | io_expander |
static bool | v12_enabled = false |
static char | iso8601_buf [24] |
constexpr size_t | MAX_SD_CARD_MSG = 255 |
static char | sd_card_msg [MAX_SD_CARD_MSG+1] |
Global utility functions.
#define TAG "utils" |
bool connect_to_internet | ( | void | ) |
Get the R5 modem connected to the internet.
This function sets the ESP32 and modem RTCs from the network time using NTP.
If this function returns true, the modem has registered to the network, brought up a packet switched profile, and obtained an IP address. MQTT, FTP, etc can be used.
void disable12V | ( | void | ) |
Disable the SDI-12 power line.
void enable12V | ( | void | ) |
Enable the SDI-12 power line if it is not already enabled.
bool getNTPTime | ( | SARA_R5 & | r5 | ) |
JsonObjectConst getSensorDefn | ( | const char *const | vendor, |
const char *const | model | ||
) |
JsonObjectConst getSensorDefn | ( | const size_t | sensor_idx, |
const sensor_list & | sensors | ||
) |
const char * iso8601 | ( | void | ) |
void log_to_sdcard | ( | const char * | msg | ) |
void log_to_sdcardf | ( | const char * | fmt, |
... | |||
) |
int read_r5_file | ( | const String & | filename, |
char * | buffer, | ||
size_t | length, | ||
size_t & | bytes_read, | ||
SARA_R5_error_t & | r5_err | ||
) |
Reads a file from the R5 filesystem into buffer.
This function assumes sizeof(buffer) >= length.
filename | The name of the file to read. |
buffer | The buffer to read the file into. |
length | The size of the file in bytes. |
bytes_read | [OUT] How many bytes were read into buffer. |
r5_err | [OUT] The error code returned from the R5 library, if an error ocurred. |
int read_spiffs_file | ( | const char * | filename, |
char * | buffer, | ||
size_t | max_length, | ||
size_t & | bytes_read | ||
) |
Reads a file from the SPIFFS filesystem into buffer.
filename | The name of the file to read. |
buffer | The buffer to read the file into. |
max_length | The size of buffer in bytes. |
bytes_read | [OUT] How many bytes were read into buffer. |
size_t readFromStreamUntil | ( | Stream & | stream, |
const char | delim, | ||
char *const | buffer, | ||
const size_t | max | ||
) |
Read characters from stream into buffer until the delim char is encountered.
This function will respect the backspace character (0x08) by moving the 'virtual cursor' back one character in buffer, if buffer is not empty.
Up to max - 1 characters will be read to ensure the resulting string is null terminated.
stream | the Stream to read from. |
delim | the character that causes reading to stop and the function to return. |
buffer | the buffer to write characters into. |
max | the maximum number of characters to be read. |
void streamPassthrough | ( | Stream * | s1, |
Stream * | s2 | ||
) |
bool wait_for_at | ( | void | ) |
Waits until an AT command to the R5 modem returns OK, or a timeout is reached.
This function will try 5 times, pausing for 1 second between attempts.
This function uses g_buffer.
int waitForChar | ( | Stream & | stream, |
uint32_t | timeout | ||
) |
Wait up to timeout ms for any character to appear in stream.
stream | the Stream to read from. |
timeout | the number of ms to wait for a character. |
|
extern |
|
static |
|
constexpr |
|
static |
|
static |