Wombat Environmental Node 1.0
An environmental node for SDI-12 and digital sensors.
Loading...
Searching...
No Matches
Utils.h File Reference
#include <ArduinoJson.h>
#include <dpiclimate-12.h>
#include "globals.h"
Include dependency graph for Utils.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  URC< T >
 
class  CommandURCVector< T >
 

Functions

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 *filename, char *buffer, size_t max_length, size_t &bytes_read)
 
int read_r5_file (const String &filename, char *buffer, 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...
 
int get_version_string (char *buffer, size_t length)
 

Function Documentation

◆ connect_to_internet()

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.

Returns
true if the connection succeeds, otherwise false.

◆ disable12V()

void disable12V ( void  )

Disable the SDI-12 power line.

◆ enable12V()

void enable12V ( void  )

Enable the SDI-12 power line if it is not already enabled.

◆ get_version_string()

int get_version_string ( char *  buffer,
size_t  length 
)

◆ getSensorDefn() [1/2]

JsonObjectConst getSensorDefn ( const char *const  vendor,
const char *const  model 
)

◆ getSensorDefn() [2/2]

JsonObjectConst getSensorDefn ( const size_t  sensor_idx,
const sensor_list &  sensors 
)

◆ iso8601()

const char * iso8601 ( void  )

◆ log_to_sdcard()

void log_to_sdcard ( const char *  msg)

◆ log_to_sdcardf()

void log_to_sdcardf ( const char *  fmt,
  ... 
)

◆ read_r5_file()

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.

Parameters
filenameThe name of the file to read.
bufferThe buffer to read the file into.
lengthThe 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.
Returns
0 on success, otherwise a failure.

◆ read_spiffs_file()

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.

Parameters
filenameThe name of the file to read.
bufferThe buffer to read the file into.
max_lengthThe size of buffer in bytes.
bytes_read[OUT] How many bytes were read into buffer.
Returns
0 on success, otherwise a failure.

◆ readFromStreamUntil()

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.

Parameters
streamthe Stream to read from.
delimthe character that causes reading to stop and the function to return.
bufferthe buffer to write characters into.
maxthe maximum number of characters to be read.
Returns
the length of the string read from stream.

◆ streamPassthrough()

void streamPassthrough ( Stream *  s1,
Stream *  s2 
)

◆ wait_for_at()

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.

Returns
true if the modem responds, otherwise false.

◆ waitForChar()

int waitForChar ( Stream &  stream,
uint32_t  timeout 
)

Wait up to timeout ms for any character to appear in stream.

Parameters
streamthe Stream to read from.
timeoutthe number of ms to wait for a character.
Returns
the character read from stream, or -1 if the timeout occurred.