Skip to content

Commit ca242be

Browse files
committed
Add SW version
Add SW version to current status page. Forced factory reset (load defaut settings from sketch) on MAJOR version change.
1 parent 5b5d36d commit ca242be

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

arduino-modbus-rtu-tcp-gateway/04-webserver.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ void processPost(char postParameter[]) {
311311
break;
312312
}
313313
// new parameter values received, save them to EEPROM
314-
EEPROM.put(configStart, localConfig); // it is safe to call, only changed values are updated
314+
EEPROM.put(configStart + 1, localConfig); // it is safe to call, only changed values are updated
315315
if (action == SERIAL_SOFT) { // can do it without "please wait" page
316316
dbgln(F("[serial] reload Serial"));
317317
Serial.flush();

arduino-modbus-rtu-tcp-gateway/05-pages.ino

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ void menuItem(ChunkedPrint& menu, byte item) {
155155
// Current Status
156156
void contentStatus(ChunkedPrint& content)
157157
{
158+
content.print(F("<tr><td>SW Version:<td>"));
159+
content.print(version[0], HEX);
160+
content.print(F("."));
161+
content.print(version[1], HEX);
158162
content.print(F("<tr><td>Microcontroller:<td>"));
159163
content.print(BOARD);
160164
content.print(F("<tr><td>Ethernet Chip:<td>"));
@@ -352,7 +356,7 @@ void contentStatus(ChunkedPrint& content)
352356
content.print(F(" OK"));
353357
countSlaves++;
354358
}
355-
else content.print(F(" waiting..."));
359+
else content.print(F(" scanning..."));
356360
}
357361
}
358362
if (countSlaves == 0 && scanCounter == 0) content.print(F("<tr><td><td>none"));

arduino-modbus-rtu-tcp-gateway/arduino-modbus-rtu-tcp-gateway.ino

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,21 @@
2424
Rx0 <-> RO
2525
Pin 6 <-> DE,RE
2626
27+
Version history
28+
v0.1 2020-04-05 Initial commit
29+
v0.2 2021-03-02 Random MAC generation
30+
v1.0 2021-03-20 Add web interface, settings stored in EEPROM
31+
v2.0 2021-04-01 Improve random MAC algorithm (Marsaglia algorithm from https://github.com/RobTillaart/randomHelpers),
32+
replace some libraries with more efficient code, compatibility with Arduino Mega
33+
v2.1 2021-04-12 Code optimisation
34+
v2.2 2021-06-06 Fix TCP closed socket, support RS485 modules with hardware automatic flow control
35+
v2.3 2021-09-10 Fix IPAddress cast (gateway freeze)
36+
v2.4 2021-10-15 Add SW version. Forced factory reset (load defaut settings from sketch) on MAJOR version change.
2737
2838
*/
2939

40+
const byte version[] = {2, 4};
41+
3042
#include <SPI.h>
3143
#include <Ethernet.h>
3244
#include <EthernetUdp.h>
@@ -63,7 +75,6 @@ const byte scanCommand[] = {0x03, 0x00, 0x00, 0x00, 0x01}; // Command sent duri
6375

6476
typedef struct
6577
{
66-
char marker;
6778
byte mac[6];
6879
bool enableDhcp;
6980
IPAddress ip;
@@ -82,12 +93,13 @@ typedef struct
8293

8394
/*
8495
Please note that after boot, Arduino loads settings stored in EEPROM, even if you flash new program to it!
85-
If you want to force Arduino to load factory defaults specified bellow, you must either
86-
1) click "Restore" defaults in WebUI (factory reset configuration, keeps MAC)
87-
2) change "marker" in the sketch to another character (factory reset configuration AND generates new MAC)
96+
97+
Arduino loads factory defaults specified bellow in case:
98+
1) User clicks "Restore" defaults in WebUI (factory reset configuration, keeps MAC)
99+
2) VERSION_MAJOR changes (factory reset configuration AND generates new MAC)
88100
*/
101+
89102
const config_type defaultConfig = {
90-
't', // marker (if marker specified in sketch and stored in EEPROM are the same, settings from EEPROM are loaded during boot)
91103
{ 0x90, 0xA2, 0xDA }, // mac (bytes 4, 5 and 6 will be generated randomly)
92104
false, // enableDhcp
93105
{192, 168, 1, 254}, // ip
@@ -211,15 +223,16 @@ void setup()
211223
CreateTrulyRandomSeed();
212224

213225
// is config already stored in EEPROM?
214-
if (EEPROM.read(configStart) == defaultConfig.marker) {
226+
if (EEPROM.read(configStart) == version[0]) {
215227
// load (configStart) the local configuration struct from EEPROM
216-
EEPROM.get(configStart, localConfig);
228+
EEPROM.get(configStart + 1, localConfig);
217229
} else {
218230
// load (overwrite) the local configuration struct from defaults and save them to EEPROM
219231
localConfig = defaultConfig;
220232
// generate new MAC (bytes 0, 1 and 2 are static, bytes 3, 4 and 5 are generated randomly)
221233
generateMac();
222-
EEPROM.put(configStart, localConfig);
234+
EEPROM.write(configStart, version[0]);
235+
EEPROM.put(configStart + 1, localConfig);
223236
}
224237

225238
startSerial();

0 commit comments

Comments
 (0)