EnviroDIYPublisher class

The EnviroDIYPublisher subclass of dataPublisher for publishing data to the Monitor My Watershed/EnviroDIY data portal at https://monitormywatershed.org/ (formerly at http://data.enviroDIY.org).

Base classes

class dataPublisher
The dataPublisher class is a virtual class used by other publishers to distribute data online.

Constructors, destructors, conversion operators

EnviroDIYPublisher()
Construct a new EnviroDIY Publisher object with no members set.
EnviroDIYPublisher(Logger& baseLogger, int sendEveryX = 1) explicit
Construct a new EnviroDIY Publisher object.
EnviroDIYPublisher(Logger& baseLogger, Client* inClient, int sendEveryX = 1)
Construct a new EnviroDIY Publisher object.
EnviroDIYPublisher(Logger& baseLogger, const char* registrationToken, const char* samplingFeatureUUID, int sendEveryX = 1)
Construct a new EnviroDIY Publisher object.
EnviroDIYPublisher(Logger& baseLogger, const char* registrationToken, int sendEveryX = 1)
Construct a new EnviroDIY Publisher object.
EnviroDIYPublisher(Logger& baseLogger, Client* inClient, const char* registrationToken, const char* samplingFeatureUUID, int sendEveryX = 1)
Construct a new EnviroDIY Publisher object.
EnviroDIYPublisher(Logger& baseLogger, Client* inClient, const char* registrationToken, int sendEveryX = 1)
Construct a new EnviroDIY Publisher object.
~EnviroDIYPublisher() virtual
Destroy the EnviroDIY Publisher object.

Public functions

String getEndpoint(void) -> String override
Get the destination for published data - generally the host name of the data receiver.
String getHost(void) -> String
Get the EnviroDIY/Monitor My Watershed web host.
void setHost(const char* host)
Set the EnviroDIY/Monitor My Watershed web host.
String getPath(void) -> String
Get the EnviroDIY/Monitor My Watershed API path.
void setPath(const char* endpoint)
Set the EnviroDIY/Monitor My Watershed API path.
int getPort(void) -> int
Get the EnviroDIY/Monitor My Watershed API port.
void setPort(int port)
Set the EnviroDIY/Monitor My Watershed API port.
void setToken(const char* registrationToken)
Set the site registration token.
uint16_t calculateJsonSize() -> uint16_t
Calculates how long the outgoing JSON will be.
void begin(Logger& baseLogger, Client* inClient, const char* registrationToken, const char* samplingFeatureUUID)
Begin the publisher - linking it to the client and logger.
void begin(Logger& baseLogger, const char* registrationToken, const char* samplingFeatureUUID)
Begin the publisher - linking it to the logger but not attaching a client.
void begin(Logger& baseLogger, const char* registrationToken)
Begin the publisher - linking it to the logger but not attaching a client.
bool connectionNeeded(void) -> bool override
Checks if the publisher needs an Internet connection for the next publishData call (as opposed to just buffering data internally).
int16_t publishData(Client* outClient, bool forceFlush = false) -> int16_t override
Utilize an attached modem to open a a TCP connection to the EnviroDIY/ODM2DataSharingPortal and then stream out a post request over that connection.

Protected functions

int16_t flushDataBuffer(Client* outClient) -> int16_t
Transmit data from the data buffer to an external site.

Protected variables

LogBuffer _logBuffer
Internal reference to the logger buffer.
uint8_t _initialTransmissionsRemaining
The number of transmissions remaining at the single minute intervals.

Portions of the POST request to EnviroDIY

const char* enviroDIYPath protected
The api path.
const char* enviroDIYHost protected
The host name.
int enviroDIYPort protected
The host port.
static const char* tokenHeader protected
The token header text.
static const char* contentLengthHeader protected
The content length header text.
static const char* contentTypeHeader protected
The content type header text.

Portions of the JSON object for EnviroDIY

static const char* samplingFeatureTag protected
The JSON feature UUID tag.
static const char* timestampTag protected
The JSON feature timestamp tag.

Function documentation

EnviroDIYPublisher::EnviroDIYPublisher(Logger& baseLogger, int sendEveryX = 1) explicit

Construct a new EnviroDIY Publisher object.

Parameters
baseLogger The logger supplying the data to be published
sendEveryX Interval (in units of the logging interval) between attempted data transmissions.

EnviroDIYPublisher::EnviroDIYPublisher(Logger& baseLogger, Client* inClient, int sendEveryX = 1)

Construct a new EnviroDIY Publisher object.

Parameters
baseLogger The logger supplying the data to be published
inClient An Arduino client instance to use to print data to. Allows the use of any type of client and multiple clients tied to a single TinyGSM modem instance
sendEveryX Interval (in units of the logging interval) between attempted data transmissions.

EnviroDIYPublisher::EnviroDIYPublisher(Logger& baseLogger, const char* registrationToken, const char* samplingFeatureUUID, int sendEveryX = 1)

Construct a new EnviroDIY Publisher object.

Parameters
baseLogger The logger supplying the data to be published
registrationToken The registration token for the site on the Monitor My Watershed data portal.
samplingFeatureUUID The sampling feature UUID for the site on the Monitor My Watershed data portal.
sendEveryX Interval (in units of the logging interval) between attempted data transmissions.

EnviroDIYPublisher::EnviroDIYPublisher(Logger& baseLogger, const char* registrationToken, int sendEveryX = 1)

Construct a new EnviroDIY Publisher object.

Parameters
baseLogger The logger supplying the data to be published
registrationToken The registration token for the site on the Monitor My Watershed data portal.
sendEveryX Interval (in units of the logging interval) between attempted data transmissions.

EnviroDIYPublisher::EnviroDIYPublisher(Logger& baseLogger, Client* inClient, const char* registrationToken, const char* samplingFeatureUUID, int sendEveryX = 1)

Construct a new EnviroDIY Publisher object.

Parameters
baseLogger The logger supplying the data to be published
inClient An Arduino client instance to use to print data to. Allows the use of any type of client and multiple clients tied to a single TinyGSM modem instance
registrationToken The registration token for the site on the Monitor My Watershed data portal.
samplingFeatureUUID The sampling feature UUID for the site on the Monitor My Watershed data portal.
sendEveryX Interval (in units of the logging interval) between attempted data transmissions.

EnviroDIYPublisher::EnviroDIYPublisher(Logger& baseLogger, Client* inClient, const char* registrationToken, int sendEveryX = 1)

Construct a new EnviroDIY Publisher object.

Parameters
baseLogger The logger supplying the data to be published
inClient An Arduino client instance to use to print data to. Allows the use of any type of client and multiple clients tied to a single TinyGSM modem instance
registrationToken The registration token for the site on the Monitor My Watershed data portal.
sendEveryX Interval (in units of the logging interval) between attempted data transmissions.

String EnviroDIYPublisher::getEndpoint(void) override

Get the destination for published data - generally the host name of the data receiver.

Returns String The URL or HOST to receive published data

String EnviroDIYPublisher::getHost(void)

Get the EnviroDIY/Monitor My Watershed web host.

Returns String The EnviroDIY/Monitor My Watershed web host

void EnviroDIYPublisher::setHost(const char* host)

Set the EnviroDIY/Monitor My Watershed web host.

Parameters
host The EnviroDIY/Monitor My Watershed web host

String EnviroDIYPublisher::getPath(void)

Get the EnviroDIY/Monitor My Watershed API path.

Returns String The EnviroDIY/Monitor My Watershed API path

void EnviroDIYPublisher::setPath(const char* endpoint)

Set the EnviroDIY/Monitor My Watershed API path.

Parameters
endpoint The EnviroDIY/Monitor My Watershed API path

int EnviroDIYPublisher::getPort(void)

Get the EnviroDIY/Monitor My Watershed API port.

Returns int The EnviroDIY/Monitor My Watershed API port

void EnviroDIYPublisher::setPort(int port)

Set the EnviroDIY/Monitor My Watershed API port.

Parameters
port The EnviroDIY/Monitor My Watershed API port

void EnviroDIYPublisher::setToken(const char* registrationToken)

Set the site registration token.

Parameters
registrationToken The registration token for the site on the Monitor My Watershed data portal.

uint16_t EnviroDIYPublisher::calculateJsonSize()

Calculates how long the outgoing JSON will be.

Returns uint16_t The number of characters in the JSON object.

void EnviroDIYPublisher::begin(Logger& baseLogger, Client* inClient, const char* registrationToken, const char* samplingFeatureUUID)

Begin the publisher - linking it to the client and logger.

Parameters
baseLogger The logger supplying the data to be published
inClient An Arduino client instance to use to print data to. Allows the use of any type of client and multiple clients tied to a single TinyGSM modem instance
registrationToken The registration token for the site on the Monitor My Watershed data portal.
samplingFeatureUUID The sampling feature UUID for the site on the Monitor My Watershed data portal.

This can be used as an alternative to adding the logger and client in the constructor.


void EnviroDIYPublisher::begin(Logger& baseLogger, const char* registrationToken, const char* samplingFeatureUUID)

Begin the publisher - linking it to the logger but not attaching a client.

Parameters
baseLogger The logger supplying the data to be published
registrationToken The registration token for the site on the Monitor My Watershed data portal.
samplingFeatureUUID The sampling feature UUID for the site on the Monitor My Watershed data portal.

This can be used as an alternative to adding the logger and client in the constructor.


void EnviroDIYPublisher::begin(Logger& baseLogger, const char* registrationToken)

Begin the publisher - linking it to the logger but not attaching a client.

Parameters
baseLogger The logger supplying the data to be published
registrationToken The registration token for the site on the Monitor My Watershed data portal.

This can be used as an alternative to adding the logger and client in the constructor.


bool EnviroDIYPublisher::connectionNeeded(void) override

Checks if the publisher needs an Internet connection for the next publishData call (as opposed to just buffering data internally).

Returns bool True if an internet connection is needed for the next publish.

int16_t EnviroDIYPublisher::publishData(Client* outClient, bool forceFlush = false) override

Utilize an attached modem to open a a TCP connection to the EnviroDIY/ODM2DataSharingPortal and then stream out a post request over that connection.

Parameters
outClient An Arduino client instance to use to print data to. Allows the use of any type of client and multiple clients tied to a single TinyGSM modem instance
forceFlush Ask the publisher to flush buffered data immediately.
Returns int16_t The http status code of the response.

This depends on an internet connection already having been made and a client being available.


int16_t EnviroDIYPublisher::flushDataBuffer(Client* outClient) protected

Transmit data from the data buffer to an external site.

Parameters
outClient The client to publish the data over
Returns int16_t The HTTP response code from the publish attempt


Variable documentation

uint8_t EnviroDIYPublisher::_initialTransmissionsRemaining protected

The number of transmissions remaining at the single minute intervals.

We send every one of the first five data points at only one minute intervals for faster in-field validation.