24
24
Rx0 <-> RO
25
25
Pin 6 <-> DE,RE
26
26
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.
27
37
28
38
*/
29
39
40
+ const byte version[] = {2 , 4 };
41
+
30
42
#include < SPI.h>
31
43
#include < Ethernet.h>
32
44
#include < EthernetUdp.h>
@@ -63,7 +75,6 @@ const byte scanCommand[] = {0x03, 0x00, 0x00, 0x00, 0x01}; // Command sent duri
63
75
64
76
typedef struct
65
77
{
66
- char marker;
67
78
byte mac[6 ];
68
79
bool enableDhcp;
69
80
IPAddress ip;
@@ -82,12 +93,13 @@ typedef struct
82
93
83
94
/*
84
95
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)
88
100
*/
101
+
89
102
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)
91
103
{ 0x90 , 0xA2 , 0xDA }, // mac (bytes 4, 5 and 6 will be generated randomly)
92
104
false , // enableDhcp
93
105
{192 , 168 , 1 , 254 }, // ip
@@ -211,15 +223,16 @@ void setup()
211
223
CreateTrulyRandomSeed ();
212
224
213
225
// is config already stored in EEPROM?
214
- if (EEPROM.read (configStart) == defaultConfig. marker ) {
226
+ if (EEPROM.read (configStart) == version[ 0 ] ) {
215
227
// load (configStart) the local configuration struct from EEPROM
216
- EEPROM.get (configStart, localConfig);
228
+ EEPROM.get (configStart + 1 , localConfig);
217
229
} else {
218
230
// load (overwrite) the local configuration struct from defaults and save them to EEPROM
219
231
localConfig = defaultConfig;
220
232
// generate new MAC (bytes 0, 1 and 2 are static, bytes 3, 4 and 5 are generated randomly)
221
233
generateMac ();
222
- EEPROM.put (configStart, localConfig);
234
+ EEPROM.write (configStart, version[0 ]);
235
+ EEPROM.put (configStart + 1 , localConfig);
223
236
}
224
237
225
238
startSerial ();
0 commit comments