Advertisement
Marijn78

Untitled

Jun 16th, 2021
1,020
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. String getBeaconsReport() {
  2.   StaticJsonDocument<1024> doc;
  3.   JsonArray tagsArr = doc.createNestedArray("tags");
  4.   for (x = 0; x < noOfBeacons; x++) {
  5.     JsonObject tagsObj = tagsArr.createNestedObject();
  6.     tagsObj["mac"] = getMacAsString(x);
  7.     tagsObj["rssi"] = beaconsRSSI[x];
  8.     tagsObj["time"] = saved_beacons.beacons[x].time;
  9.   }
  10.   doc["mac"] = String(eth_mac);
  11.   doc["msg"] = "REPORT";
  12.   doc["bcnt"] = bootCount;
  13.   String json;
  14.   serializeJson(doc, json);
  15.   return json;
  16. }
  17.  
  18. void reportStatusOverWifi() {
  19.   String content = getBeaconsReport();
  20.   String result = myGAS.gasClient(content, false);
  21.   if (!result.equals("error")) {
  22.     reportTimerRTC = timestampUnix;
  23.   } else {
  24.     if (debug) Serial.println("Error reportStatusOverWifi: " + String(result));  
  25.   }
  26. }
  27.  
  28. void reportStatus() {
  29.   if (!readBridgeConfig()) {
  30.     if (debug) Serial.println("Error readBridgeConfig");
  31.   } else {
  32.     if (internetservices_internet) {
  33.       if ( (timestampUnix - reportTimerRTC > reportTimer) || (smsAlert == true) ) {
  34.         genericDurationStart = millis();
  35.         if (debug) Serial.println("Reporting over wifi..");
  36.         reportStatusOverWifi();
  37.         genericDurationTotal = millis() - genericDurationStart;
  38.         if (debugDuration) Serial.println("Duration ReportStatusOverWifi: " + String(genericDurationTotal));
  39.       } else {
  40.         if (debug) Serial.println("Next report: " + String(reportTimer - (timestampUnix - reportTimerRTC)) + " seconds");
  41.       }
  42.     }
  43.   }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement