Skip to content

Commit

Permalink
Made the EnviroDIY host/path/port settable
Browse files Browse the repository at this point in the history
Signed-off-by: Sara Damiano <sdamiano@stroudcenter.org>
  • Loading branch information
SRGDamia1 committed May 20, 2024
1 parent c247aa6 commit 446f0b9
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 9 deletions.
54 changes: 49 additions & 5 deletions src/publishers/EnviroDIYPublisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
// Constant values for post requests
// I want to refer to these more than once while ensuring there is only one copy
// in memory
const char* EnviroDIYPublisher::postEndpoint = "/api/data-stream/";
const char* EnviroDIYPublisher::enviroDIYHost = "data.envirodiy.org";
const int EnviroDIYPublisher::enviroDIYPort = 80;
const char* EnviroDIYPublisher::tokenHeader = "\r\nTOKEN: ";
const char* EnviroDIYPublisher::contentLengthHeader = "\r\nContent-Length: ";
const char* EnviroDIYPublisher::contentTypeHeader =
Expand All @@ -31,15 +28,25 @@ const char* EnviroDIYPublisher::timestampTag = "\",\"timestamp\":[";


// Constructors
EnviroDIYPublisher::EnviroDIYPublisher() : dataPublisher() {}
EnviroDIYPublisher::EnviroDIYPublisher() : dataPublisher() {
setHost("monitormywatershed.org");
setPath("/api/data-stream/");
setPort(80);
}
EnviroDIYPublisher::EnviroDIYPublisher(Logger& baseLogger, int sendEveryX)
: dataPublisher(baseLogger, sendEveryX) {
_logBuffer.setNumVariables(_baseLogger->getArrayVarCount());
setHost("monitormywatershed.org");
setPath("/api/data-stream/");
setPort(80);
}
EnviroDIYPublisher::EnviroDIYPublisher(Logger& baseLogger, Client* inClient,
int sendEveryX)
: dataPublisher(baseLogger, inClient, sendEveryX) {
_logBuffer.setNumVariables(_baseLogger->getArrayVarCount());
setHost("monitormywatershed.org");
setPath("/api/data-stream/");
setPort(80);
}
EnviroDIYPublisher::EnviroDIYPublisher(Logger& baseLogger,
const char* registrationToken,
Expand All @@ -49,6 +56,9 @@ EnviroDIYPublisher::EnviroDIYPublisher(Logger& baseLogger,
setToken(registrationToken);
_baseLogger->setSamplingFeatureUUID(samplingFeatureUUID);
_logBuffer.setNumVariables(_baseLogger->getArrayVarCount());
setHost("monitormywatershed.org");
setPath("/api/data-stream/");
setPort(80);
}
EnviroDIYPublisher::EnviroDIYPublisher(Logger& baseLogger, Client* inClient,
const char* registrationToken,
Expand All @@ -58,11 +68,45 @@ EnviroDIYPublisher::EnviroDIYPublisher(Logger& baseLogger, Client* inClient,
setToken(registrationToken);
_baseLogger->setSamplingFeatureUUID(samplingFeatureUUID);
_logBuffer.setNumVariables(_baseLogger->getArrayVarCount());
setHost("monitormywatershed.org");
setPath("/api/data-stream/");
setPort(80);
}
// Destructor
EnviroDIYPublisher::~EnviroDIYPublisher() {}


// Returns the data destination
String EnviroDIYPublisher::getHost(void) {
return String(enviroDIYHost);
}

// Returns the data destination
void EnviroDIYPublisher::setHost(const char* host) {
enviroDIYHost = host;
}

// Returns the data destination
String EnviroDIYPublisher::getPath(void) {
return String(enviroDIYPath);
}

// Returns the data destination
void EnviroDIYPublisher::setPath(const char* endpoint) {
enviroDIYPath = endpoint;
}

// Returns the data destination
int EnviroDIYPublisher::getPort(void) {
return enviroDIYPort;
}

// Returns the data destination
void EnviroDIYPublisher::setPort(int port) {
enviroDIYPort = port;
}


void EnviroDIYPublisher::setToken(const char* registrationToken) {
_registrationToken = registrationToken;
}
Expand Down Expand Up @@ -217,7 +261,7 @@ int16_t EnviroDIYPublisher::flushDataBuffer(Client* outClient) {

// copy the initial post header into the tx buffer
txBufferAppend(postHeader);
txBufferAppend(postEndpoint);
txBufferAppend(enviroDIYPath);
txBufferAppend(HTTPtag);

// add the rest of the HTTP POST headers to the outgoing buffer
Expand Down
48 changes: 44 additions & 4 deletions src/publishers/EnviroDIYPublisher.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,49 @@ class EnviroDIYPublisher : public dataPublisher {

// Returns the data destination
String getEndpoint(void) override {
return String(enviroDIYHost);
return String(enviroDIYHost) + String(enviroDIYPath);
}

/**
* @brief Get the EnviroDIY/Monitor My Watershed web host
*
* @return *String* The EnviroDIY/Monitor My Watershed web host
*/
String getHost(void);

/**
* @brief Set the EnviroDIY/Monitor My Watershed web host
*
* @param host The EnviroDIY/Monitor My Watershed web host
*/
void setHost(const char* host);

/**
* @brief Get the EnviroDIY/Monitor My Watershed API path
*
* @return *String* The EnviroDIY/Monitor My Watershed API path
*/
String getPath(void);
/**
* @brief Set the EnviroDIY/Monitor My Watershed API path
*
* @param endpoint The EnviroDIY/Monitor My Watershed API path
*/
void setPath(const char* endpoint);

/**
* @brief Get the EnviroDIY/Monitor My Watershed API port
*
* @return *int* The EnviroDIY/Monitor My Watershed API port
*/
int getPort(void);
/**
* @brief Set the EnviroDIY/Monitor My Watershed API port
*
* @param port The EnviroDIY/Monitor My Watershed API port
*/
void setPort(int port);

// Adds the site registration token
/**
* @brief Set the site registration token
Expand Down Expand Up @@ -178,9 +218,9 @@ class EnviroDIYPublisher : public dataPublisher {
*
* @{
*/
static const char* postEndpoint; ///< The endpoint
static const char* enviroDIYHost; ///< The host name
static const int enviroDIYPort; ///< The host port
const char* enviroDIYPath; ///< The api path
const char* enviroDIYHost; ///< The host name
int enviroDIYPort; ///< The host port
static const char* tokenHeader; ///< The token header text
static const char* contentLengthHeader; ///< The content length header text
static const char* contentTypeHeader; ///< The content type header text
Expand Down

1 comment on commit 446f0b9

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All sensor and variable subclasses must be included in the Menu a la Carte example
missing_menu_docs

Please sign in to comment.