You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -57,6 +59,10 @@ Change settings of your Arduino-based Modbus RTU to Modbus TCP/UDP gateway via w
57
59
58
60
**Reboot**.
59
61
62
+
**EEPROM Health**. Keeps track of EEPROM write cycles (this counter is persistent, never cleared during factory resets). Replace your Arduino once you reach 100 000 write cycles (with 6 hours EEPROM_INTERVAL you have more than 50 years lifespan).
63
+
64
+
**Ethernet Sockets**. Max number of usable sockets. See Limitations bellow. One socket is reserved for Modbus UDP, remaining sockets are shared between Modbus TCP and WebUI.
65
+
60
66
**Generate New MAC**. Generate new MAC address. First 3 bytes are fixed 90:A2:DA, remaining 3 bytes are true random.
@@ -73,7 +79,7 @@ Change settings of your Arduino-based Modbus RTU to Modbus TCP/UDP gateway via w
73
79
74
80
**Requests Queue**. Monitors internal request queue (buffer). The limits for bytes and for the number of requests stored in the queue can be configured in advanced settings.
75
81
76
-
**Modbus Statistics**. Counters for various errors. Insigned longs are used, rollover of counters is synchronized:
82
+
**Modbus Statistics**.
77
83
***Slave Responded**. Slave responded with a valid Modbus RTU response within response timeout.
78
84
***Slave Responded with Error (Codes 1~8)**. Slave responded, but with an error. For the list of error codes see https://en.wikipedia.org/wiki/Modbus#Exception_responses.
79
85
***Gateway Overloaded (Code 10)**. Request queue is full (either the number of bytes stored or the number of requests stored). Request was dropped and the gateway responded with an error code 10.
@@ -148,21 +154,27 @@ Get the hardware (cheap clones from China are sufficient) and connect together:
148
154
***Arduino Nano, Uno or Mega** (and possibly other). On Mega you have to configure Serial in advanced settings in the sketch.
149
155
***W5100, W5200 or W5500 based Ethernet shield**. The ubiquitous W5100 shield for Uno/Mega is sufficient. If available, I recommend W5500 Ethernet Shield. !!! ENC28J60 will not work !!!
150
156
***TTL to RS485 module**:
151
-
- with hardware automatic flow control (recommended, available on Aliexpress)<br>
152
-
Arduino <-> Module<br>
153
-
Tx1 <-> Tx<br>
154
-
Rx0 <-> Rx
155
-
- with flow controlled by pin (such as MAX485 module)<br>
156
-
Arduino <-> MAX485<br>
157
-
Tx1 <-> DI<br>
158
-
Rx0 <-> RO<br>
157
+
- recommended: TTL to RS485 module with hardware automatic flow control (available on Aliexpress)<br>
158
+
Arduino <-> Module
159
+
Tx1 <-> Tx
160
+
Rx0 <-> Rx<br>
161
+
162
+
- not recommended: MAX485 module with flow controlled by pin (works but is vulnerable to burn outs)<br>
Download this repository (all *.ino files) and open arduino-modbus-rtu-tcp-gateway.ino in Arduino IDE. Download all required libraries (they are available in "library manager"). If you want, you can check the default factory settings (can be later changed via web interface) and advanced settings (can only be changed in the sketch). Compile and upload your program to Arduino. Connect your Arduino to ethernet, connect your Modbus RTU slaves to MAX485 module. Use your web browser to access the web interface on default IP http://192.168.1.254 Enjoy :-)
172
+
You can either:
173
+
-** Download and flash my pre-compiled firmware** from "Releases".
174
+
-**Compile your own firmware**. Download this repository (all *.ino files) and open arduino-modbus-rtu-tcp-gateway.ino in Arduino IDE. Download all required libraries (they are available in "library manager"). If you want, you can check the default factory settings (can be later changed via web interface) and advanced settings (can only be changed in the sketch). Compile and upload your program to Arduino.
175
+
176
+
Connect your Arduino to ethernet and use your web browser to access the web interface on default IP: http://192.168.1.254
177
+
Enjoy :-)
166
178
167
179
## Where can I learn more about Modbus protocols?
168
180
@@ -199,7 +211,7 @@ The number of used sockets is determined (by the Ethernet.h library) based on mi
199
211
200
212
#### Memory
201
213
202
-
Not everything could fit into the limited flash memory of Arduino Nano / Uno. If you have a microcontroller with more memory (such as Mega), you can enable extra settings in the main sketch by defining ENABLE_DHCP and/or ENABLE_EXTRA_DIAG in the sketch.
214
+
Not everything could fit into the limited flash memory of Arduino Nano / Uno. If you have a microcontroller with more memory (such as Mega), you can enable extra settings in the main sketch by defining ENABLE_DHCP and/or ENABLE_EXTRA_DIAG in advanced settings.
if (rtuCount[i] > ROLLOVER || ethCount[i] > ROLLOVER) {
162
+
returntrue;
163
+
}
165
164
}
166
165
#endif/* ENABLE_EXTRA_DIAG */
167
166
returnfalse;
168
167
}
169
168
170
169
voidresetStats() {
171
170
memset(errorCount, 0, sizeof(errorCount));
172
-
errorTcpCount = 0;
173
-
errorRtuCount = 0;
174
-
errorTimeoutCount = 0;
175
171
#ifdef ENABLE_EXTRA_DIAG
176
172
remaining_seconds = -(millis() / 1000);
177
-
ethRxCount = 0;
178
-
ethTxCount = 0;
179
-
serialRxCount = 0;
180
-
serialTxCount = 0;
173
+
memset(rtuCount, 0, sizeof(rtuCount));
174
+
memset(ethCount, 0, sizeof(ethCount));
181
175
#endif/* ENABLE_EXTRA_DIAG */
176
+
updateEeprom();
182
177
}
183
178
184
179
voidgenerateMac() {
@@ -192,13 +187,31 @@ void generateMac() {
192
187
}
193
188
}
194
189
195
-
190
+
voidupdateEeprom() {
191
+
eepromTimer.sleep(EEPROM_INTERVAL * 60UL * 60UL * 1000UL); // EEPROM_INTERVAL is in hours, sleep is in milliseconds!
192
+
eepromWrites++; // we assume that at least some bytes are written to EEPROM during EEPROM.update or EEPROM.put
193
+
int address = CONFIG_START;
194
+
EEPROM.put(address, eepromWrites);
195
+
address += sizeof(eepromWrites);
196
+
EEPROM.put(address, VERSION[0]);
197
+
address += 1;
198
+
EEPROM.put(address, localConfig);
199
+
address += sizeof(localConfig);
200
+
EEPROM.put(address, errorCount);
201
+
address += sizeof(errorCount);
202
+
#ifdef ENABLE_EXTRA_DIAG
203
+
EEPROM.put(address, rtuCount);
204
+
address += sizeof(rtuCount);
205
+
EEPROM.put(address, ethCount);
206
+
address += sizeof(ethCount);
207
+
#endif/* ENABLE_EXTRA_DIAG */
208
+
}
196
209
197
210
#if MAX_SOCK_NUM == 8
198
-
unsignedlong lastSocketUse[MAX_SOCK_NUM] = { 0, 0, 0, 0, 0, 0, 0, 0 };// +rs 03Feb2019 - records last interaction involving each socket to enable detecting sockets unused for longest time period
unsignedlong lastSocketUse[MAX_SOCK_NUM] = { 0, 0, 0, 0 };// +rs 03Feb2019 - records last interaction involving each socket to enable detecting sockets unused for longest time period
byte addressPos = 6 * !localConfig.enableRtuOverTcp; // position of slave address in the incoming TCP/UDP message (0 for Modbus RTU over TCP/UDP and 6 for Modbus RTU over TCP/UDP)
153
153
if (localConfig.enableRtuOverTcp) { // check CRC for Modbus RTU over TCP/UDP
154
154
if (checkCRC(inBuffer, msgLength) == false) {
155
-
errorTcpCount++;
155
+
errorCount[ERROR_TCP]++;
156
156
return0; // drop request and do not return any error code
if (status != SLAVE_ERROR_0B_QUEUE && isScan == false) errorCount[status]++; // there is no counter for SLAVE_ERROR_0B_QUEUE, ignor scans in statistics
0 commit comments