Skip to content

Commit b37061d

Browse files
committed
HTML code optimisation.
1 parent 58874db commit b37061d

File tree

3 files changed

+27
-25
lines changed

3 files changed

+27
-25
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ enum post_key : byte {
7777
POST_PARITY, // parity
7878
POST_STOP, // stop bits
7979
POST_TIMEOUT, // response timeout
80-
POST_RETRY, // retry attempts
80+
POST_ATTEMPTS, // number of request attempts
8181
POST_ACTION // actions on Tools page
8282
};
8383

@@ -308,8 +308,8 @@ void processPost(char postParameter[]) {
308308
case POST_TIMEOUT:
309309
localConfig.serialTimeout = paramValueUlong;
310310
break;
311-
case POST_RETRY:
312-
localConfig.serialRetry = (byte)paramValueUlong;
311+
case POST_ATTEMPTS:
312+
localConfig.serialAttempts = (byte)paramValueUlong;
313313
break;
314314
case POST_ACTION:
315315
action = (action_type)paramValueUlong;

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

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ void sendPage(EthernetClient &client, byte reqPage) {
3535
"Transfer-Encoding: chunked\r\n"
3636
"\r\n"));
3737
chunked.begin();
38-
chunked.print(F("<!doctype html>" // the start of the HTTP Body - contains the HTML
39-
"<html lang=en>"
38+
chunked.print(F("<!DOCTYPE html>"
39+
"<html>"
4040
"<head>"
4141
"<meta charset=utf-8"));
4242
if (reqPage == PAGE_STATUS || reqPage == PAGE_WAIT) chunked.print(F(" http-equiv=refresh content=5"));
@@ -49,23 +49,25 @@ void sendPage(EthernetClient &client, byte reqPage) {
4949
chunked.print(F(">"
5050
"<title>Modbus RTU &rArr; Modbus TCP/UDP Gateway</title>"
5151
"<style>"
52-
"a {text-decoration:none;color:white}"
52+
"html,body{margin:0;height:100%;font-family:sans-serif}"
53+
"a{text-decoration:none;color:white}"
5354
"td:first-child {text-align:right;width:30%}"
54-
"th {text-align:left;background-color:#0067AC;color:white;padding:10px}"
55-
"table {width:100%}"
55+
"th{text-align:left;background-color:#0067AC;color:white;padding:10px;height:0}"
56+
"table{width:100%}"
57+
"h1{margin:0}"
5658
"</style>"
5759
"</head>"
58-
"<body style='font-family:sans-serif'"));
60+
"<body"));
5961
#ifdef ENABLE_DHCP
6062
chunked.print(F(" onload='dis(document.getElementById(&quot;box&quot;).checked)'>"
6163
"<script>function dis(st) {var x = document.getElementsByClassName('ip');for (var i = 0; i < x.length; i++) {x[i].disabled = st}}</script"));
6264
#endif /* ENABLE_DHCP */
6365
chunked.print(F(">"
64-
"<table height=100% style='position:absolute;top:0;bottom:0;left:0;right:0'>"
65-
"<tr style='height:10px'><th colspan=2>"
66-
"<h1 style='margin:0px'>Modbus RTU &rArr; Modbus TCP/UDP Gateway</h1>" // first row is header
67-
"<tr>" // second row is left menu (first cell) and main page (second cell)
68-
"<th valign=top style=width:20%;padding:0px>"
66+
"<table height=100%>"
67+
"<tr><th colspan=2>"
68+
"<h1>Modbus RTU &rArr; Modbus TCP/UDP Gateway</h1>" // first row is header
69+
"<tr valign=top>" // second row is left menu (first cell) and main page (second cell)
70+
"<th style=width:20%;padding:0>"
6971

7072
// Left Menu
7173
"<table>"));
@@ -542,15 +544,15 @@ void contentRtu(ChunkedPrint &chunked) {
542544
"<tr><td>Response Timeout:"));
543545
helperInput(chunked);
544546
chunked.print(POST_TIMEOUT);
545-
chunked.print(F(" min=100 max=9999 value="));
547+
chunked.print(F(" min=100 max=2000 value="));
546548
chunked.print(localConfig.serialTimeout);
547-
chunked.print(F("> (100~9999) ms"
549+
chunked.print(F("> (100~2000) ms"
548550
"<tr><td>Retry Attempts:"));
549551
helperInput(chunked);
550-
chunked.print(POST_RETRY);
551-
chunked.print(F(" min=1 max=10 value="));
552-
chunked.print(localConfig.serialRetry);
553-
chunked.print(F("> (1~10)"));
552+
chunked.print(POST_ATTEMPTS);
553+
chunked.print(F(" min=1 max=5 value="));
554+
chunked.print(localConfig.serialAttempts);
555+
chunked.print(F("> (1~5)"));
554556
}
555557

556558
// Tools

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ typedef struct
9393
unsigned long baud;
9494
byte serialConfig;
9595
unsigned int serialTimeout;
96-
byte serialRetry;
96+
byte serialAttempts;
9797
} config_type;
9898

9999
/*
@@ -118,7 +118,7 @@ const config_type defaultConfig = {
118118
9600, // baud
119119
SERIAL_8E1, // serialConfig (Modbus RTU default is 8E1, another frequently used option is 8N2)
120120
500, // serialTimeout
121-
5 // serialRetry
121+
3 // serialAttempts
122122
};
123123
// local configuration values (stored in RAM)
124124
config_type localConfig;
@@ -127,9 +127,9 @@ const byte configStart = 128;
127127

128128
/****** ETHERNET AND SERIAL ******/
129129

130-
#ifdef UDP_TX_PACKET_MAX_SIZE //if the macro MAX_SOCK_NUM is defined
131-
#undef UDP_TX_PACKET_MAX_SIZE //un-define it
132-
#define UDP_TX_PACKET_MAX_SIZE modbusSize //redefine it with the new value
130+
#ifdef UDP_TX_PACKET_MAX_SIZE
131+
#undef UDP_TX_PACKET_MAX_SIZE
132+
#define UDP_TX_PACKET_MAX_SIZE modbusSize
133133
#endif
134134

135135
#ifdef MAX_SOCK_NUM // Ethernet.h library determines MAX_SOCK_NUM by Microcontroller RAM (not by Ethernet chip type).

0 commit comments

Comments
 (0)