fix tdpro remote admin display and lora init sd card mix

This commit is contained in:
pelgraine
2026-03-30 13:02:31 +11:00
parent d07ad71d5d
commit 0cab2ddfa7
2 changed files with 41 additions and 3 deletions
+33
View File
@@ -4,6 +4,8 @@
#include <Mesh.h>
#include <SD.h>
#include <esp_mac.h>
#include <time.h>
#include <sys/time.h>
CellularMQTT cellularMQTT;
@@ -734,6 +736,37 @@ restart:
Serial.printf("[Cell] Registered: oper=%s CSQ=%d APN=%s IMEI=%s\n",
_operator, _csq, _apn[0] ? _apn : "(none)", _imei);
// Sync ESP32 system clock from modem network time
for (int attempt = 0; attempt < 5; attempt++) {
if (attempt > 0) vTaskDelay(pdMS_TO_TICKS(2000));
if (sendAT("AT+CCLK?", "OK", 3000)) {
char* p = strstr(_atBuf, "+CCLK:");
if (p) {
int yy=0, mo=0, dd=0, hh=0, mm=0, ss=0, tz=0;
if (sscanf(p, "+CCLK: \"%d/%d/%d,%d:%d:%d", &yy, &mo, &dd, &hh, &mm, &ss) >= 6) {
if (yy < 24 || yy > 50) continue; // Not synced yet
char* tzp = p + 7;
while (*tzp && *tzp != '+' && *tzp != '-') tzp++;
if (*tzp) tz = atoi(tzp);
struct tm t = {};
t.tm_year = yy + 100;
t.tm_mon = mo - 1;
t.tm_mday = dd;
t.tm_hour = hh;
t.tm_min = mm;
t.tm_sec = ss;
time_t epoch = mktime(&t);
epoch -= (tz * 15 * 60);
struct timeval tv = { .tv_sec = epoch, .tv_usec = 0 };
settimeofday(&tv, nullptr);
Serial.printf("[Cell] Clock synced: %04d-%02d-%02d %02d:%02d:%02d UTC\n",
yy+2000, mo, dd, hh, mm, ss);
break;
}
}
}
}
// ---- Phase 4: Activate data ----
_state = CellState::DATA_ACTIVATING;
if (!activateData()) {
+8 -3
View File
@@ -1,6 +1,6 @@
#include <Arduino.h> // needed for PlatformIO
#include <Mesh.h>
#include <time.h>
#include "MyMesh.h"
#ifdef HAS_4G_MODEM
@@ -117,7 +117,8 @@ void setup() {
for (int i = 0; i < 3; i++) {
#ifdef SDCARD_CS
if (SD.begin(SDCARD_CS)) { sdCardReady = true; break; }
extern SPIClass displaySpi;
if (SD.begin(SDCARD_CS, displaySpi)) { sdCardReady = true; break; }
#else
if (SD.begin(SPI_CS)) { sdCardReady = true; break; }
#endif
@@ -129,6 +130,10 @@ Serial.printf("SD card: %s\n", sdCardReady ? "ready" : "FAILED");
// GPIO pins (36/47/33) from the display's HSPI peripheral
extern SPIClass displaySpi;
displaySpi.begin(PIN_DISPLAY_SCLK, 47, PIN_DISPLAY_MOSI, PIN_DISPLAY_CS);
// Re-claim shared HSPI bus — SD.begin() steals GPIO 36/47/33
extern SPIClass displaySpi;
displaySpi.begin(PIN_DISPLAY_SCLK, 47, PIN_DISPLAY_MOSI, PIN_DISPLAY_CS);
}
// Start cellular MQTT
@@ -195,7 +200,7 @@ void loop() {
Serial.printf("[MQTT] CLI: %s\n", mqttCmd.cmd);
char reply[512];
reply[0] = '\0';
the_mesh.handleCommand(0, mqttCmd.cmd, reply);
the_mesh.handleCommand((uint32_t)time(nullptr), mqttCmd.cmd, reply);
if (reply[0] == '\0') strcpy(reply, "OK");