fixing ui stuff
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include <ArduinoJson.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include "esp_sntp.h"
|
||||
#include "esp_heap_caps.h"
|
||||
|
||||
BoomUploader boomUploader;
|
||||
@@ -44,6 +45,19 @@ static void addPart(String& body, const String& boundary, const char* name, cons
|
||||
body += "--" + boundary + "\r\nContent-Disposition: form-data; name=\"" + name + "\"\r\n\r\n" + value + "\r\n";
|
||||
}
|
||||
|
||||
static bool waitForNtpTime() {
|
||||
// SNTP reports COMPLETED once per synchronization. Retain that result for
|
||||
// later uploads; a reboot clears it and requires a new NTP sync.
|
||||
static bool synchronized = false;
|
||||
const uint32_t started = millis();
|
||||
while (!synchronized && boomNetwork.connected() && millis() - started < 20000) {
|
||||
if (sntp_get_sync_status() == SNTP_SYNC_STATUS_COMPLETED) synchronized = true;
|
||||
if (!synchronized) delay(100);
|
||||
}
|
||||
time_t now = time(nullptr);
|
||||
return synchronized && now >= 1704067200; // Reject an unset or implausible clock.
|
||||
}
|
||||
|
||||
bool BoomUploader::submitOne(const String& filename) {
|
||||
if (!queue_ || !queue_->ready() || !boomNetwork.connected() || !queue_->exists(filename)) return false;
|
||||
boomState.setSyncing(true, "Uploading " + filename);
|
||||
@@ -88,8 +102,8 @@ bool BoomUploader::doPost(const String& filename, const String& path) {
|
||||
BoomEventMeta meta;
|
||||
if (!queue_->readMeta(filename, meta)) return false;
|
||||
String token = boomState.prefs().getString("token", SENSOR_TOKEN);
|
||||
if (!token.length() || !SENSOR_ID || !strlen(SERVER_CA_CERT)) {
|
||||
Serial.println("[Upload] sensor ID, token or CA certificate missing");
|
||||
if (!token.length() || !SENSOR_ID) {
|
||||
Serial.println("[Upload] sensor ID or token missing");
|
||||
permanentFailure_ = true;
|
||||
return false;
|
||||
}
|
||||
@@ -106,6 +120,11 @@ bool BoomUploader::doPost(const String& filename, const String& path) {
|
||||
if (colon >= 0) { port = host.substring(colon + 1).toInt(); host = host.substring(0, colon); }
|
||||
if (!host.length() || !port) return false;
|
||||
|
||||
if (!waitForNtpTime()) {
|
||||
Serial.println("[Upload] waiting for NTP time before TLS validation");
|
||||
return false;
|
||||
}
|
||||
|
||||
FILE* file = fopen(path.c_str(), "rb");
|
||||
if (!file) return false;
|
||||
const size_t fileBytes = queue_->fileSize(filename);
|
||||
@@ -128,7 +147,7 @@ bool BoomUploader::doPost(const String& filename, const String& path) {
|
||||
const size_t length = preamble.length() + fileBytes + trailer.length();
|
||||
|
||||
WiFiClientSecure client;
|
||||
client.setCACert(SERVER_CA_CERT);
|
||||
client.useBuiltinCACertBundle();
|
||||
client.setTimeout(60);
|
||||
Serial.printf("[Upload] free heap=%u PSRAM=%u largest PSRAM=%u\n",
|
||||
unsigned(ESP.getFreeHeap()), unsigned(ESP.getFreePsram()),
|
||||
|
||||
Reference in New Issue
Block a user