Skip to content

Commit 859cfdb

Browse files
Copilotdorkmo
andcommitted
Fix Arduino Opta compilation errors by using platform-specific headers
Co-authored-by: dorkmo <[email protected]>
1 parent c0f55b7 commit 859cfdb

File tree

3 files changed

+84
-24
lines changed

3 files changed

+84
-24
lines changed

TankAlarm-112025-Client-BluesOpta/TankAlarm-112025-Client-BluesOpta.ino

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,27 @@
2222
#include <Arduino.h>
2323
#include <Wire.h>
2424
#include <ArduinoJson.h>
25-
#include <LittleFS.h>
2625
#include <Notecard.h>
2726
#include <math.h>
2827
#include <string.h>
2928

30-
// Watchdog support for STM32H7 (Arduino Opta)
31-
#if defined(ARDUINO_OPTA) || defined(STM32H7xx)
29+
// Filesystem and Watchdog support
30+
// Note: Arduino Opta uses Mbed OS, which has different APIs than STM32duino
31+
#if defined(ARDUINO_ARCH_STM32) && !defined(ARDUINO_ARCH_MBED)
32+
// STM32duino platform (non-Mbed)
33+
#include <LittleFS.h>
3234
#include <IWatchdog.h>
35+
#define FILESYSTEM_AVAILABLE
3336
#define WATCHDOG_AVAILABLE
3437
#define WATCHDOG_TIMEOUT_SECONDS 30
38+
#elif defined(ARDUINO_OPTA) || defined(ARDUINO_ARCH_MBED)
39+
// Arduino Opta with Mbed OS - filesystem and watchdog disabled for now
40+
// TODO: Implement Mbed OS LittleFileSystem and mbed::Watchdog support
41+
#warning "LittleFS and Watchdog features disabled on Mbed OS platform"
3542
#endif
3643

37-
#ifndef strlcpy
44+
// strlcpy is provided by Notecard library on Mbed platforms
45+
#if !defined(ARDUINO_ARCH_MBED) && !defined(strlcpy)
3846
static size_t strlcpy(char *dst, const char *src, size_t size) {
3947
if (!dst || !src || size == 0) {
4048
return 0;
@@ -350,12 +358,16 @@ void loop() {
350358
}
351359

352360
static void initializeStorage() {
361+
#ifdef FILESYSTEM_AVAILABLE
353362
if (!LittleFS.begin()) {
354363
Serial.println(F("LittleFS init failed; halting"));
355364
while (true) {
356365
delay(1000);
357366
}
358367
}
368+
#else
369+
Serial.println(F("Warning: Filesystem not available on this platform - configuration will not persist"));
370+
#endif
359371
}
360372

361373
static void ensureConfigLoaded() {
@@ -396,6 +408,7 @@ static void createDefaultConfig(ClientConfig &cfg) {
396408
}
397409

398410
static bool loadConfigFromFlash(ClientConfig &cfg) {
411+
#ifdef FILESYSTEM_AVAILABLE
399412
if (!LittleFS.exists(CLIENT_CONFIG_PATH)) {
400413
return false;
401414
}
@@ -457,9 +470,13 @@ static bool loadConfigFromFlash(ClientConfig &cfg) {
457470
}
458471

459472
return true;
473+
#else
474+
return false; // Filesystem not available
475+
#endif
460476
}
461477

462478
static bool saveConfigToFlash(const ClientConfig &cfg) {
479+
#ifdef FILESYSTEM_AVAILABLE
463480
DynamicJsonDocument doc(4096);
464481
doc["site"] = cfg.siteName;
465482
doc["deviceLabel"] = cfg.deviceLabel;
@@ -508,6 +525,9 @@ static bool saveConfigToFlash(const ClientConfig &cfg) {
508525

509526
file.close();
510527
return true;
528+
#else
529+
return false; // Filesystem not available
530+
#endif
511531
}
512532

513533
static void printHardwareRequirements(const ClientConfig &cfg) {
@@ -710,7 +730,7 @@ static void pollForConfigUpdates() {
710730

711731
J *body = JGetObject(rsp, "body");
712732
if (body) {
713-
char *json = JConvertToJson(body);
733+
char *json = JConvertToJSONString(body);
714734
if (json) {
715735
DynamicJsonDocument doc(4096);
716736
DeserializationError err = deserializeJson(doc, json);
@@ -798,10 +818,10 @@ static void applyConfigUpdate(const JsonDocument &doc) {
798818

799819
if (doc.containsKey("tanks")) {
800820
hardwareChanged = true; // Tank configuration affects hardware
801-
JsonArray tanks = doc["tanks"].as<JsonArray>();
821+
JsonArrayConst tanks = doc["tanks"].as<JsonArrayConst>();
802822
gConfig.tankCount = min<uint8_t>(tanks.size(), MAX_TANKS);
803823
for (uint8_t i = 0; i < gConfig.tankCount; ++i) {
804-
JsonObject t = tanks[i];
824+
JsonObjectConst t = tanks[i];
805825
gConfig.tanks[i].id = t["id"].as<const char *>() ? t["id"].as<const char *>()[0] : ('A' + i);
806826
strlcpy(gConfig.tanks[i].name, t["name"].as<const char *>() ? t["name"].as<const char *>() : "Tank", sizeof(gConfig.tanks[i].name));
807827
gConfig.tanks[i].tankNumber = t["number"].is<uint8_t>() ? t["number"].as<uint8_t>() : (i + 1);
@@ -1410,7 +1430,7 @@ static void publishNote(const char *fileName, const JsonDocument &doc, bool sync
14101430

14111431
J *body = JParse(buffer);
14121432
if (!body) {
1413-
notecard.deleteRequest(req);
1433+
notecard.deleteResponse(req);
14141434
bufferNoteForRetry(targetFile, buffer, syncNow);
14151435
return;
14161436
}
@@ -1428,6 +1448,7 @@ static void publishNote(const char *fileName, const JsonDocument &doc, bool sync
14281448
}
14291449

14301450
static void bufferNoteForRetry(const char *fileName, const char *payload, bool syncNow) {
1451+
#ifdef FILESYSTEM_AVAILABLE
14311452
File file = LittleFS.open(NOTE_BUFFER_PATH, "a");
14321453
if (!file) {
14331454
Serial.println(F("Failed to open note buffer; dropping payload"));
@@ -1441,9 +1462,13 @@ static void bufferNoteForRetry(const char *fileName, const char *payload, bool s
14411462
file.close();
14421463
Serial.println(F("Note buffered for retry"));
14431464
pruneNoteBufferIfNeeded();
1465+
#else
1466+
Serial.println(F("Warning: Filesystem not available; note dropped"));
1467+
#endif
14441468
}
14451469

14461470
static void flushBufferedNotes() {
1471+
#ifdef FILESYSTEM_AVAILABLE
14471472
if (!gNotecardAvailable) {
14481473
return;
14491474
}
@@ -1515,9 +1540,11 @@ static void flushBufferedNotes() {
15151540
LittleFS.remove(NOTE_BUFFER_PATH);
15161541
LittleFS.remove(NOTE_BUFFER_TEMP_PATH);
15171542
}
1543+
#endif
15181544
}
15191545

15201546
static void pruneNoteBufferIfNeeded() {
1547+
#ifdef FILESYSTEM_AVAILABLE
15211548
if (!LittleFS.exists(NOTE_BUFFER_PATH)) {
15221549
return;
15231550
}
@@ -1564,4 +1591,5 @@ static void pruneNoteBufferIfNeeded() {
15641591
LittleFS.remove(NOTE_BUFFER_PATH);
15651592
LittleFS.rename(NOTE_BUFFER_TEMP_PATH, NOTE_BUFFER_PATH);
15661593
Serial.println(F("Note buffer pruned"));
1594+
#endif
15671595
}

TankAlarm-112025-Server-BluesOpta/TankAlarm-112025-Server-BluesOpta.ino

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include <ArduinoJson.h>
2323
#include <Notecard.h>
2424
#include <Ethernet.h>
25-
#include <LittleFS.h>
2625
#include <math.h>
2726
#include <string.h>
2827
#include <ctype.h>
@@ -37,12 +36,19 @@
3736
#endif
3837
#endif
3938

40-
// Watchdog support for STM32H7 (Arduino Opta)
41-
#if defined(ARDUINO_OPTA) || defined(STM32H7xx)
42-
39+
// Filesystem and Watchdog support
40+
// Note: Arduino Opta uses Mbed OS, which has different APIs than STM32duino
41+
#if defined(ARDUINO_ARCH_STM32) && !defined(ARDUINO_ARCH_MBED)
42+
// STM32duino platform (non-Mbed)
43+
#include <LittleFS.h>
4344
#include <IWatchdog.h>
45+
#define FILESYSTEM_AVAILABLE
4446
#define WATCHDOG_AVAILABLE
4547
#define WATCHDOG_TIMEOUT_SECONDS 30
48+
#elif defined(ARDUINO_OPTA) || defined(ARDUINO_ARCH_MBED)
49+
// Arduino Opta with Mbed OS - filesystem and watchdog disabled for now
50+
// TODO: Implement Mbed OS LittleFileSystem and mbed::Watchdog support
51+
#warning "LittleFS and Watchdog features disabled on Mbed OS platform"
4652
#endif
4753

4854
#ifndef SERVER_PRODUCT_UID
@@ -2540,6 +2546,13 @@ static void sendClientConsole(EthernetClient &client);
25402546
static void sendTankJson(EthernetClient &client);
25412547
static void sendClientDataJson(EthernetClient &client);
25422548
static void handleConfigPost(EthernetClient &client, const String &body);
2549+
// Forward declarations
2550+
enum class ConfigDispatchStatus : uint8_t {
2551+
Ok = 0,
2552+
PayloadTooLarge,
2553+
NotecardFailure
2554+
};
2555+
25432556
static void handlePinPost(EthernetClient &client, const String &body);
25442557
static void handleRefreshPost(EthernetClient &client, const String &body);
25452558
static ConfigDispatchStatus dispatchClientConfig(const char *clientUid, JsonVariantConst cfgObj);
@@ -2558,11 +2571,6 @@ static ClientConfigSnapshot *findClientConfigSnapshot(const char *clientUid);
25582571
static bool checkSmsRateLimit(TankRecord *rec);
25592572
static void publishViewerSummary();
25602573
static double computeNextAlignedEpoch(double epoch, uint8_t baseHour, uint32_t intervalSeconds);
2561-
enum class ConfigDispatchStatus : uint8_t {
2562-
Ok = 0,
2563-
PayloadTooLarge,
2564-
NotecardFailure
2565-
};
25662574

25672575
static void handleRefreshPost(EthernetClient &client, const String &body) {
25682576
char clientUid[64] = {0};
@@ -2658,12 +2666,16 @@ void loop() {
26582666
}
26592667

26602668
static void initializeStorage() {
2669+
#ifdef FILESYSTEM_AVAILABLE
26612670
if (!LittleFS.begin()) {
26622671
Serial.println(F("LittleFS init failed; halting"));
26632672
while (true) {
26642673
delay(1000);
26652674
}
26662675
}
2676+
#else
2677+
Serial.println(F("Warning: Filesystem not available on this platform - configuration will not persist"));
2678+
#endif
26672679
}
26682680

26692681
static void ensureConfigLoaded() {
@@ -2694,6 +2706,7 @@ static void createDefaultConfig(ServerConfig &cfg) {
26942706
}
26952707

26962708
static bool loadConfig(ServerConfig &cfg) {
2709+
#ifdef FILESYSTEM_AVAILABLE
26972710
if (!LittleFS.exists(SERVER_CONFIG_PATH)) {
26982711
return false;
26992712
}
@@ -2736,34 +2749,38 @@ static bool loadConfig(ServerConfig &cfg) {
27362749
cfg.smsOnClear = doc["smsOnClear"].is<bool>() ? doc["smsOnClear"].as<bool>() : false;
27372750

27382751
if (doc.containsKey("staticIp")) {
2739-
JsonArray ip = doc["staticIp"].as<JsonArray>();
2752+
JsonArrayConst ip = doc["staticIp"].as<JsonArrayConst>();
27402753
if (ip.size() == 4) {
27412754
gStaticIp = IPAddress(ip[0], ip[1], ip[2], ip[3]);
27422755
}
27432756
}
27442757
if (doc.containsKey("gateway")) {
2745-
JsonArray gw = doc["gateway"].as<JsonArray>();
2758+
JsonArrayConst gw = doc["gateway"].as<JsonArrayConst>();
27462759
if (gw.size() == 4) {
27472760
gStaticGateway = IPAddress(gw[0], gw[1], gw[2], gw[3]);
27482761
}
27492762
}
27502763
if (doc.containsKey("subnet")) {
2751-
JsonArray sn = doc["subnet"].as<JsonArray>();
2764+
JsonArrayConst sn = doc["subnet"].as<JsonArrayConst>();
27522765
if (sn.size() == 4) {
27532766
gStaticSubnet = IPAddress(sn[0], sn[1], sn[2], sn[3]);
27542767
}
27552768
}
27562769
if (doc.containsKey("dns")) {
2757-
JsonArray dns = doc["dns"].as<JsonArray>();
2770+
JsonArrayConst dns = doc["dns"].as<JsonArrayConst>();
27582771
if (dns.size() == 4) {
27592772
gStaticDns = IPAddress(dns[0], dns[1], dns[2], dns[3]);
27602773
}
27612774
}
27622775

27632776
return true;
2777+
#else
2778+
return false; // Filesystem not available
2779+
#endif
27642780
}
27652781

27662782
static bool saveConfig(const ServerConfig &cfg) {
2783+
#ifdef FILESYSTEM_AVAILABLE
27672784
DynamicJsonDocument doc(2048);
27682785
doc["serverName"] = cfg.serverName;
27692786
doc["clientFleet"] = cfg.clientFleet;
@@ -2817,6 +2834,9 @@ static bool saveConfig(const ServerConfig &cfg) {
28172834

28182835
file.close();
28192836
return true;
2837+
#else
2838+
return false; // Filesystem not available
2839+
#endif
28202840
}
28212841

28222842
static void printHardwareRequirements() {
@@ -3768,6 +3788,7 @@ static ClientConfigSnapshot *findClientConfigSnapshot(const char *clientUid) {
37683788

37693789
static void loadClientConfigSnapshots() {
37703790
gClientConfigCount = 0;
3791+
#ifdef FILESYSTEM_AVAILABLE
37713792
if (!LittleFS.exists(CLIENT_CONFIG_CACHE_PATH)) {
37723793
return;
37733794
}
@@ -3812,9 +3833,11 @@ static void loadClientConfigSnapshots() {
38123833
}
38133834

38143835
file.close();
3836+
#endif
38153837
}
38163838

38173839
static void saveClientConfigSnapshots() {
3840+
#ifdef FILESYSTEM_AVAILABLE
38183841
File file = LittleFS.open(CLIENT_CONFIG_CACHE_PATH, "w");
38193842
if (!file) {
38203843
return;
@@ -3827,6 +3850,7 @@ static void saveClientConfigSnapshots() {
38273850
}
38283851

38293852
file.close();
3853+
#endif
38303854
}
38313855

38323856
static void cacheClientConfigFromBuffer(const char *clientUid, const char *buffer) {

TankAlarm-112025-Viewer-BluesOpta/TankAlarm-112025-Viewer-BluesOpta.ino

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,17 @@
3232
#endif
3333
#endif
3434

35-
#if defined(ARDUINO_OPTA) || defined(STM32H7xx)
35+
// Watchdog support
36+
// Note: Arduino Opta uses Mbed OS, which has different APIs than STM32duino
37+
#if defined(ARDUINO_ARCH_STM32) && !defined(ARDUINO_ARCH_MBED)
38+
// STM32duino platform (non-Mbed)
3639
#include <IWatchdog.h>
3740
#define WATCHDOG_AVAILABLE
3841
#define WATCHDOG_TIMEOUT_SECONDS 30
42+
#elif defined(ARDUINO_OPTA) || defined(ARDUINO_ARCH_MBED)
43+
// Arduino Opta with Mbed OS - watchdog disabled for now
44+
// TODO: Implement Mbed OS mbed::Watchdog support
45+
#warning "Watchdog features disabled on Mbed OS platform"
3946
#endif
4047

4148
#ifndef VIEWER_PRODUCT_UID
@@ -81,7 +88,8 @@
8188
#define STR_HELPER(x) #x
8289
#define STR(x) STR_HELPER(x)
8390

84-
#ifndef strlcpy
91+
// strlcpy is provided by Notecard library on Mbed platforms
92+
#if !defined(ARDUINO_ARCH_MBED) && !defined(strlcpy)
8593
static size_t strlcpy(char *dst, const char *src, size_t size) {
8694
if (!dst || !src || size == 0) {
8795
return 0;
@@ -825,7 +833,7 @@ static void fetchViewerSummary() {
825833
break;
826834
}
827835

828-
char *json = JConvertToJson(body);
836+
char *json = JConvertToJSONString(body);
829837
double epoch = JGetNumber(rsp, "time");
830838
if (json) {
831839
DynamicJsonDocument doc(TANK_JSON_CAPACITY + 1024);

0 commit comments

Comments
 (0)