From 73f6e5bc0ced2b712fffa8835fecb2013a5f6b78 Mon Sep 17 00:00:00 2001 From: John Date: Tue, 27 Aug 2024 22:20:12 -0400 Subject: [PATCH] Remove parse target to prevent pinging tiltbridge.com --- .github/workflows/build.yml | 2 +- src/main.cpp | 2 - src/parseTarget.cpp | 162 +----------------------------------- src/sendData.cpp | 11 +-- 4 files changed, 5 insertions(+), 172 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5bcac4f..30d3e3c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,7 +4,7 @@ on: push: branches: - master - - no_std_strings + - no_parse # tags: # - "v*" # pull_request: diff --git a/src/main.cpp b/src/main.cpp index 3beba85..caea584 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -71,8 +71,6 @@ void setup() { // Set a reboot timer for 24 hours reboot24.once(86400, reboot); - // Set up Parse - doParsePoll(); } void loop() { diff --git a/src/parseTarget.cpp b/src/parseTarget.cpp index 5a26054..59f627f 100644 --- a/src/parseTarget.cpp +++ b/src/parseTarget.cpp @@ -16,173 +16,15 @@ static bool parseIsSetup = false; void doParsePoll() // Get Parse data from git repo { - if (!parseHasKeys) - { - HTTPClient http; - http.begin(SERVER_URL); - - // Send HTTP POST request - int httpResponseCode = http.GET(); - - String payload = "{}"; - - if (httpResponseCode >= 200 && httpResponseCode <= 299) - { - Log.verbose(F("Parse info loaded from repository." CR)); - payload = http.getString(); - http.end(); // Free resources - - StaticJsonDocument<384> doc; - DeserializationError error = deserializeJson(doc, payload); - - if (error) - { - Log.error(F("Parse Info: Failed to deserialize Parse information: %s" CR), error.f_str()); - return; - } - else - { - if (!doc["cloudUrl"].isNull()) - { - const char *cu = doc["cloudUrl"]; - strlcpy(config.cloudUrl, cu, sizeof(config.cloudUrl)); - } - - if (!doc["cloudAppID"].isNull()) - { - const char *ca = doc["cloudAppID"]; - strlcpy(config.cloudAppID, ca, sizeof(config.cloudAppID)); - } - - if (!doc["cloudClientKey"].isNull()) - { - const char *ck = doc["cloudClientKey"]; - strlcpy(config.cloudClientKey, ck, sizeof(config.cloudClientKey)); - } - parseHasKeys = true; - doParseSetup(); - } - } - else - { - Log.error(F("Parse Info: HTTP Response code: %d" CR), httpResponseCode); - } - } + } void doParseSetup() // Add this TiltBridge to Parse DB { - if (parseHasKeys && config.cloudEnabled) - { - if (!parseIsSetup) - { - Log.verbose(F("Initializing Parse SDK." CR)); - // Initialize Parse SDK with keys - Parse.begin(config.cloudAppID, config.cloudClientKey); - Parse.setServerURL(config.cloudUrl); - - // Use if the API host server fingerprint is not reliable - // Parse.setHostFingerprint("a4117a2ea12d7278e02d72929a3cfb085dffa62e"); - Parse.setClientInsecure(); - - Log.verbose(F("Checking if Tiltbridge already exists." CR)); - ParseCloudFunction cloudFunction; - cloudFunction.setFunctionName("addTiltbridge"); - cloudFunction.add("tiltbridgeID", config.guid); - cloudFunction.add("tiltbridgeVersion", version()); - ParseResponse response = cloudFunction.send(); - if (!response.getErrorCode()) - { - // The object has been saved - Log.verbose(F("Added TiltBridge to cloud DB." CR)); - parseIsSetup = true; - } - else - { - // There was a problem, check response. - Log.warning(F("Failed to add TiltBridge to cloud database." CR)); - } - // Free the resource - response.close(); - } - } - else - { - doParsePoll(); - } } void addTiltToParse() // Dispatch data to Parse { - if (parseIsSetup) - { - for (uint8_t i = 0; i < TILT_COLORS; i++) - { - // Determine if Color is active - if (tilt_scanner.tilt(i)->is_loaded()) - { - Log.verbose(F("Parse: Processing report for %s Tilt." CR), tilt_color_names[i]); - ParseCloudFunction cloudFunction; - // Concatenate field names: - // - // Name of log - char logName[13]; - strcpy(logName, "add"); - strcat(logName, tilt_color_names[i]); - strcat(logName, "Log"); - // Name of temperature point - char tempName[18]; - strcpy(tempName, "temperature"); - strcat(tempName, tilt_color_names[i]); - // Name of gravity point - char gravName[14]; - strcpy(gravName, "gravity"); - strcat(gravName, tilt_color_names[i]); - - cloudFunction.setFunctionName(logName); - cloudFunction.add("tiltbridgeID", config.guid); - - if (tilt_scanner.tilt(i)->receives_battery) - { - // Concatenate name of battery pont - char battName[14]; - strcpy(battName, "battery"); - strcat(battName, tilt_color_names[i]); - // Add field for battery life - cloudFunction.add(battName, tilt_scanner.tilt(i)->weeks_since_last_battery_change); - } - - if (tilt_scanner.tilt(i)->tilt_pro) // Send Pro gravity and temp - { - cloudFunction.add(tempName, tilt_scanner.tilt(i)->temp); - cloudFunction.add(gravName, tilt_scanner.tilt(i)->gravity_smoothed); - } - else // Send non-Pro gravity and temp - { - cloudFunction.add(tempName, tilt_scanner.tilt(i)->temp * 10); - cloudFunction.add(gravName, tilt_scanner.tilt(i)->gravity_smoothed * 10); - } - - ParseResponse response = cloudFunction.send(); - if (!response.getErrorCode()) - { - // The object has been saved - Log.verbose(F("Parse: %s Tilt dispatched to DB." CR), tilt_color_names[i]); - } - else - { - // There was a problem, check response - Log.error(F("Parse: Error sending %s Tilt to DB." CR), tilt_color_names[i]); - } - // Free the resource - response.close(); - } - } - } - else - { - doParseSetup(); - data_sender.send_cloudTarget = true; - } + } diff --git a/src/sendData.cpp b/src/sendData.cpp index 471c9cc..d2ed190 100644 --- a/src/sendData.cpp +++ b/src/sendData.cpp @@ -42,13 +42,13 @@ void dataSendHandler::init() gSheetsTicker.once(70, [](){data_sender.send_gSheets = true;}); // Schedule first send to Google Sheets grainfatherTicker.once(80, [](){data_sender.send_grainfather = true;}); // Schedule first send to Grainfather taplistioTicker.once(90, [](){data_sender.send_taplistio = true;}); // Schedule first send to Taplist.io - cloudTargetTicker.once(100, [](){data_sender.send_cloudTarget = true;}); // Schedule first send to Cloud Target + } void dataSendHandler::process() { if (WiFiClass::status() == WL_CONNECTED) { - send_to_cloud(); + send_to_localTarget(); send_to_bf_and_bf(); send_to_grainfather(); @@ -171,13 +171,6 @@ bool dataSendHandler::send_to_bf_and_bf() void dataSendHandler::send_to_cloud() { - if (data_sender.send_cloudTarget && !send_lock) { - send_lock = true; - send_cloudTarget = false; - addTiltToParse(); - cloudTargetTicker.once(CLOUD_DELAY, [](){data_sender.send_cloudTarget = true;}); // Set up subsequent send to localTarget - } - send_lock = false; } bool dataSendHandler::send_to_bf_and_bf(const uint8_t which_bf)