EnviroDIYPublisher class

The EnviroDIYPublisher subclass of dataPublisher for publishing data to the Monitor My Watershed/EnviroDIY data portal 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, Client* inClient, const char* registrationToken, const char* samplingFeatureUUID, 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.
int16_t publishData(Client* outClient) -> 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.

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. NOTE: not implemented by this publisher!

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. NOTE: not implemented by this publisher!

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. NOTE: not implemented by this publisher!

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. NOTE: not implemented by this publisher!

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.


int16_t EnviroDIYPublisher::publishData(Client* outClient) 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
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.