Skip to content

Commit 4fc8672

Browse files
committed
Fix strlcpy usage and improve Ethernet include handling
Corrects strlcpy usage in the client and server to avoid null pointer issues and ensures compatibility with Mbed platforms. Updates the viewer to conditionally include PortentaEthernet for specific boards, improving platform compatibility.
1 parent 9ebad25 commit 4fc8672

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,8 +1342,9 @@ static void applyConfigUpdate(const JsonDocument &doc) {
13421342
gConfig.tanks[i].enableServerUpload = t["upload"].as<bool>();
13431343
}
13441344
if (t.containsKey("relayTargetClient")) {
1345+
const char *relayTargetStr = t["relayTargetClient"].as<const char *>();
13451346
strlcpy(gConfig.tanks[i].relayTargetClient,
1346-
t["relayTargetClient"].as<const char *>() ?: "",
1347+
relayTargetStr ? relayTargetStr : "",
13471348
sizeof(gConfig.tanks[i].relayTargetClient));
13481349
}
13491350
if (t.containsKey("relayMask")) {
@@ -2325,7 +2326,7 @@ static void publishNote(const char *fileName, const JsonDocument &doc, bool sync
23252326

23262327
J *body = JParse(buffer);
23272328
if (!body) {
2328-
notecard.deleteResponse(req);
2329+
JDelete(req);
23292330
bufferNoteForRetry(targetFile, buffer, syncNow);
23302331
return;
23312332
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,9 @@ static bool gLastLinkState = false;
343343
static double gLastDailyEmailSentEpoch = 0.0;
344344
#define MIN_DAILY_EMAIL_INTERVAL_SECONDS 3600 // Minimum 1 hour between daily emails
345345

346-
#ifndef ARDUINO_TANKALARM_HAS_STRLCPY
347-
#define ARDUINO_TANKALARM_HAS_STRLCPY
348-
size_t strlcpy(char *dst, const char *src, size_t size) {
346+
// strlcpy is provided by Notecard library on Mbed platforms
347+
#if !defined(ARDUINO_ARCH_MBED) && !defined(strlcpy)
348+
static size_t strlcpy(char *dst, const char *src, size_t size) {
349349
if (!dst || !src || size == 0) {
350350
return 0;
351351
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@
1717
#include <Wire.h>
1818
#include <ArduinoJson.h>
1919
#include <Notecard.h>
20-
#include <Ethernet.h>
20+
#if defined(ARDUINO_OPTA) || defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4)
21+
#include <PortentaEthernet.h>
22+
#include <Ethernet.h>
23+
#else
24+
#include <Ethernet.h>
25+
#endif
2126
#include <math.h>
2227
#include <string.h>
2328

0 commit comments

Comments
 (0)