6363// Select the static Local IP address according to your local network
6464IPAddress ip (192 , 168 , 2 , 222 );
6565
66- #define USING_HOST_NAME true
66+ #define USING_HOST_NAME false // true
6767
6868#if USING_HOST_NAME
6969 // Optional using hostname, and Ethernet built-in DNS lookup
@@ -88,15 +88,9 @@ String INSERT_SQL = String("INSERT INTO ") + default_database + "." + default_ta
8888
8989MySQL_Connection conn ((Client *)&client);
9090
91- void setup ()
91+ void initEthernet ()
9292{
93- Serial.begin (115200 );
94- while (!Serial); // wait for serial port to connect
95-
96- MYSQL_DISPLAY3 (" \n Starting Basic_Insert on" , BOARD_NAME, " , with" , SHIELD_TYPE);
97- MYSQL_DISPLAY (MYSQL_MARIADB_GENERIC_VERSION);
98-
99- #if !(USE_ETHERNET_PORTENTA_H7)
93+ #if !(USE_ETHERNET_PORTENTA_H7 || USE_ETHERNET_LAN8742A || USE_ETHERNET_LAN8720)
10094
10195 MYSQL_LOGERROR (F (" =========================================" ));
10296 MYSQL_LOGERROR (F (" Default SPI pinout:" ));
@@ -114,7 +108,7 @@ void setup()
114108
115109 MYSQL_LOGERROR1 (F (" ESP8266 setCsPin:" ), USE_THIS_SS_PIN);
116110
117- #if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC )
111+ #if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC )
118112 // For ESP8266
119113 // Pin D0(GPIO16) D1(GPIO5) D2(GPIO4) D3(GPIO0) D4(GPIO2) D8
120114 // Ethernet 0 X X X X 0
@@ -125,17 +119,8 @@ void setup()
125119 // D2 is safe to used for Ethernet, Ethernet2, Ethernet3, EthernetLarge libs
126120 // Must use library patch for Ethernet, EthernetLarge libraries
127121 Ethernet.init (USE_THIS_SS_PIN);
128-
129- #elif USE_ETHERNET3
130- // Use MAX_SOCK_NUM = 4 for 4K, 2 for 8K, 1 for 16K RX/TX buffer
131- #ifndef ETHERNET3_MAX_SOCK_NUM
132- #define ETHERNET3_MAX_SOCK_NUM 4
133- #endif
134-
135- Ethernet.setCsPin (USE_THIS_SS_PIN);
136- Ethernet.init (ETHERNET3_MAX_SOCK_NUM);
137-
138- #endif // ( USE_ETHERNET || USE_ETHERNET2 || USE_ETHERNET_LARGE || USE_ETHERNET_ENC )
122+
123+ #endif // ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC )
139124
140125#elif defined(ESP32)
141126
@@ -154,24 +139,15 @@ void setup()
154139 MYSQL_LOGERROR1 (F (" ESP32 setCsPin:" ), USE_THIS_SS_PIN);
155140
156141 // For other boards, to change if necessary
157- #if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC )
142+ #if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC )
158143 // Must use library patch for Ethernet, EthernetLarge libraries
159144 // ESP32 => GPIO2,4,5,13,15,21,22 OK with Ethernet, Ethernet2, EthernetLarge
160145 // ESP32 => GPIO2,4,5,15,21,22 OK with Ethernet3
161146
162147 // Ethernet.setCsPin (USE_THIS_SS_PIN);
163148 Ethernet.init (USE_THIS_SS_PIN);
164149
165- #elif USE_ETHERNET3
166- // Use MAX_SOCK_NUM = 4 for 4K, 2 for 8K, 1 for 16K RX/TX buffer
167- #ifndef ETHERNET3_MAX_SOCK_NUM
168- #define ETHERNET3_MAX_SOCK_NUM 4
169- #endif
170-
171- Ethernet.setCsPin (USE_THIS_SS_PIN);
172- Ethernet.init (ETHERNET3_MAX_SOCK_NUM);
173-
174- #endif // ( USE_ETHERNET || USE_ETHERNET2 || USE_ETHERNET_LARGE || USE_ETHERNET_ENC )
150+ #endif // ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC )
175151
176152#elif ETHERNET_USE_RPIPICO
177153
@@ -181,7 +157,7 @@ void setup()
181157 // ETHERNET_USE_RPIPICO, use default SS = 5 or 17
182158 #ifndef USE_THIS_SS_PIN
183159 #if defined(ARDUINO_ARCH_MBED)
184- #define USE_THIS_SS_PIN 5 // For Arduino Mbed core
160+ #define USE_THIS_SS_PIN 17 // For Arduino Mbed core
185161 #else
186162 #define USE_THIS_SS_PIN 17 // For E.Philhower core
187163 #endif
@@ -190,7 +166,7 @@ void setup()
190166 MYSQL_LOGERROR1 (F (" RPIPICO setCsPin:" ), USE_THIS_SS_PIN);
191167
192168 // For other boards, to change if necessary
193- #if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC )
169+ #if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC )
194170 // Must use library patch for Ethernet, EthernetLarge libraries
195171 // For RPI Pico using Arduino Mbed RP2040 core
196172 // SCK: GPIO2, MOSI: GPIO3, MISO: GPIO4, SS/CS: GPIO5
@@ -200,17 +176,8 @@ void setup()
200176
201177 // Ethernet.setCsPin (USE_THIS_SS_PIN);
202178 Ethernet.init (USE_THIS_SS_PIN);
203-
204- #elif USE_ETHERNET3
205- // Use MAX_SOCK_NUM = 4 for 4K, 2 for 8K, 1 for 16K RX/TX buffer
206- #ifndef ETHERNET3_MAX_SOCK_NUM
207- #define ETHERNET3_MAX_SOCK_NUM 4
208- #endif
209-
210- Ethernet.setCsPin (USE_THIS_SS_PIN);
211- Ethernet.init (ETHERNET3_MAX_SOCK_NUM);
212179
213- #endif // ( USE_ETHERNET || USE_ETHERNET2 || USE_ETHERNET3 || USE_ETHERNET_LARGE )
180+ #endif // ( USE_ETHERNET_GENERIC || USE_ETHERNET_LARGE )
214181
215182#else // defined(ESP8266)
216183 // unknown board, do nothing, use default SS = 10
@@ -221,34 +188,35 @@ void setup()
221188 MYSQL_LOGERROR3 (F (" Board :" ), BOARD_NAME, F (" , setCsPin:" ), USE_THIS_SS_PIN);
222189
223190 // For other boards, to change if necessary
224- #if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC )
191+ #if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC )
225192 // Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries
226193
227194 Ethernet.init (USE_THIS_SS_PIN);
228-
229- #elif USE_ETHERNET3
230- // Use MAX_SOCK_NUM = 4 for 4K, 2 for 8K, 1 for 16K RX/TX buffer
231- #ifndef ETHERNET3_MAX_SOCK_NUM
232- #define ETHERNET3_MAX_SOCK_NUM 4
233- #endif
234-
235- Ethernet.setCsPin (USE_THIS_SS_PIN);
236- Ethernet.init (ETHERNET3_MAX_SOCK_NUM);
237-
238- #endif // ( USE_ETHERNET || USE_ETHERNET2 || USE_ETHERNET_LARGE || USE_ETHERNET_ENC )
195+
196+ #endif // ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC )
239197
240198#endif // defined(ESP8266)
241199
242- // Just info to know how to connect correctly
243- MYSQL_LOGERROR (F (" =========================================" ));
244- MYSQL_LOGERROR (F (" Currently Used SPI pinout:" ));
245- MYSQL_LOGERROR1 (F (" MOSI:" ), MOSI);
246- MYSQL_LOGERROR1 (F (" MISO:" ), MISO);
247- MYSQL_LOGERROR1 (F (" SCK:" ), SCK);
248- MYSQL_LOGERROR1 (F (" SS:" ), SS);
249- MYSQL_LOGERROR (F (" =========================================" ));
200+ #if !(USE_ETHERNET_PORTENTA_H7 || USE_ETHERNET_LAN8742A || USE_ETHERNET_LAN8720)
201+ // Just info to know how to connect correctly
202+ #if defined(CUR_PIN_MISO)
203+ MYSQL_LOGERROR (F (" Currently Used SPI pinout:" ));
204+ MYSQL_LOGERROR1 (F (" MOSI:" ), CUR_PIN_MOSI);
205+ MYSQL_LOGERROR1 (F (" MISO:" ), CUR_PIN_MISO);
206+ MYSQL_LOGERROR1 (F (" SCK:" ), CUR_PIN_SCK);
207+ MYSQL_LOGERROR1 (F (" SS:" ), CUR_PIN_SS);
208+ #else
209+ MYSQL_LOGERROR (F (" Currently Used SPI pinout:" ));
210+ MYSQL_LOGERROR1 (F (" MOSI:" ), MOSI);
211+ MYSQL_LOGERROR1 (F (" MISO:" ), MISO);
212+ MYSQL_LOGERROR1 (F (" SCK:" ), SCK);
213+ MYSQL_LOGERROR1 (F (" SS:" ), SS);
214+ #endif
215+
216+ MYSQL_LOGERROR (F (" =========================" ));
217+ #endif
250218
251- #endif // #if !(USE_ETHERNET_PORTENTA_H7)
219+ #endif // #if !(USE_ETHERNET_PORTENTA_H7 || USE_ETHERNET_LAN8742A || USE_ETHERNET_LAN8720 )
252220
253221 // start the ethernet connection and the server:
254222 // Use DHCP dynamic IP and random mac
@@ -259,6 +227,17 @@ void setup()
259227
260228 MYSQL_DISPLAY1 (" Using mac index =" , index);
261229 MYSQL_DISPLAY1 (" Connected! IP address:" , Ethernet.localIP ());
230+ }
231+
232+ void setup ()
233+ {
234+ Serial.begin (115200 );
235+ while (!Serial && millis () < 5000 ); // wait for serial port to connect
236+
237+ MYSQL_DISPLAY3 (" \n Starting Basic_Insert on" , BOARD_NAME, " , with" , SHIELD_TYPE);
238+ MYSQL_DISPLAY (MYSQL_MARIADB_GENERIC_VERSION);
239+
240+ initEthernet ();
262241
263242 MYSQL_DISPLAY3 (" Connecting to SQL Server @" , server, " , Port =" , server_port);
264243 MYSQL_DISPLAY5 (" User =" , user, " , PW =" , password, " , DB =" , default_database);
0 commit comments