Skip to content
This repository was archived by the owner on Jan 29, 2023. It is now read-only.

Commit 4531434

Browse files
authored
v1.4.0 to support QNEthernet
### Major Release v1.4.0 1. Add support to [QNEthernet Library](https://github.com/ssilverman/QNEthernet) for Teensy 4.1 built-in Ethernet 2. Fix bug in non-blocking connection 3. Add new feature to permit using either server's hostname, such as `your_account.duckdns.org`, or server's IPAddress, such as IPAddress(192,168,2,112) 4. Update examples with new features, bug-fixes, etc.
1 parent b94db72 commit 4531434

18 files changed

+403
-110
lines changed

CONTRIBUTING.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ If you don't find anything, please [open a new issue](https://github.com/khoih-p
1515
Please ensure to specify the following:
1616

1717
* Arduino IDE version (e.g. 1.8.15) or Platform.io version
18-
* `SAMD` Core Version (e.g. Arduino SAMD core v1.8.11, Adafruit SAMD core v1.7.4, Seeed Studio SAMD v1.8.1)
18+
* Board Core Version (e.g. Arduino SAMDUE core v1.6.12, ESP8266 core v3.0.2, ArduinoCore-mbed v2.4.1, etc.)
1919
* Contextual information (e.g. what you were trying to achieve)
2020
* Simplest possible steps to reproduce
2121
* Anything that might be relevant in your opinion, such as:
@@ -27,12 +27,13 @@ Please ensure to specify the following:
2727

2828
```
2929
Arduino IDE version: 1.8.15
30-
Arduino SAMD Core Version 1.8.11
30+
RASPBERRY_PI_PICO board
31+
ArduinoCore-mbed v2.4.1
3132
OS: Ubuntu 20.04 LTS
3233
Linux xy-Inspiron-3593 5.4.0-81-generic #91-Ubuntu SMP Thu Jul 15 19:09:17 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
3334
3435
Context:
35-
The board couldn't autoreconnect to Local Blynk Server after router power recycling.
36+
I encountered a crash while trying to use the Timer Interrupt.
3637
3738
Steps to reproduce:
3839
1. ...

README.md

Lines changed: 180 additions & 78 deletions
Large diffs are not rendered by default.

library.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"name": "MySQL_MariaDB_Generic",
3-
"version": "1.3.1",
4-
"keywords": "Communication, Database, Storage, MySQL, MariaDB, wt32-eth01, Teensy, SAMD, SAM DUE, nRF52, W5x00, ENC28J60, Ethernet, wifi, wifinina, lan8720, rp2040, nano-33-iot, nano-rp2040-connect, native-ethernet, rpi-pico, Arduino, AVR",
5-
"description": "Connects to MySQL or MariaDB using ESP8266/ESP32, WT32_ETH01 (ESP32 + LAN8720A), nRF52, SAMD21/SAMD51, STM32F/L/H/G/WB/MP1, Teensy, SAM DUE, Mega, RP2040-based boards, etc. with W5x00, ENC28J60 Ethernet, Teensy 4.1 NativeEthernet or WiFiNINA modules/shields. W5x00 can use Ethernet, EthernetLarge, Ethernet2 or Ethernet3 library. ENC28J60 can use either EthernetENC or UIPEthernet Library",
3+
"version": "1.4.0",
4+
"keywords": "Communication, Database, Storage, MySQL, MariaDB, wt32-eth01, Teensy, SAMD, SAM DUE, nRF52, W5x00, ENC28J60, Ethernet, wifi, wifinina, lan8720, rp2040, nano-33-iot, nano-rp2040-connect, QNEthernet, native-ethernet, rpi-pico, Arduino, AVR",
5+
"description": "Connects to MySQL or MariaDB using ESP8266/ESP32, WT32_ETH01 (ESP32 + LAN8720A), nRF52, SAMD21/SAMD51, STM32F/L/H/G/WB/MP1, Teensy, SAM DUE, Mega, RP2040-based boards, etc. with W5x00, ENC28J60 Ethernet, Teensy 4.1 NativeEthernet/QNEthernet or WiFiNINA modules/shields. W5x00 can use Ethernet, EthernetLarge, Ethernet2 or Ethernet3 library. ENC28J60 can use either EthernetENC or UIPEthernet Library. Now accepting server's hostname, besides IPAddress",
66
"authors": [
77
{
88
"name": "Dr. Charles Bell",
@@ -102,6 +102,10 @@
102102
"name": "EthernetLarge",
103103
"version": ">=2.0.0",
104104
"platforms": ["*"]
105+
},
106+
{
107+
"name": "QNEthernet",
108+
"version": "https://github.com/ssilverman/QNEthernet"
105109
}
106110
],
107111
"frameworks": "*",

library.properties

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
name=MySQL_MariaDB_Generic
2-
version=1.3.1
2+
version=1.4.0
33
author=Dr. Charles Bell <[email protected]>, Khoi Hoang <[email protected]>
44
maintainer=Khoi Hoang <[email protected]>
5-
sentence=Connects to MySQL or MariaDB using ESP8266/ESP32, WT32_ETH01 (ESP32 + LAN8720A), nRF52, SAMD21/SAMD51, STM32F/L/H/G/WB/MP1, Teensy, SAM DUE, Mega, RP2040-based boards, etc. with W5x00 or ENC28J60 Ethernet or WiFiNINA modules/shields. W5x00 can use Ethernet, EthernetLarge, Ethernet2 or Ethernet3 library. ENC28J60 can use either EthernetENC or UIPEthernet Library
6-
paragraph=You can use this library to connect your Arduino project directly to a MySQL / MariaDB server without using an intermediate computer or a web-based or cloud-based service. Having direct access to a database server means you can store data acquired from your project as well as check values stored in tables on the server. This also means you can setup your own, local MySQL / MariaDB server to store your data further removing the need for Internet connectivity. If that is not an issue, you can still connect to and store data on a MySQL / MariaDB server via your network, Internet, or even in the cloud!
5+
sentence=Connects to MySQL or MariaDB using ESP8266/ESP32, WT32_ETH01 (ESP32 + LAN8720A), nRF52, SAMD21/SAMD51, STM32F/L/H/G/WB/MP1, Teensy, SAM DUE, Mega, RP2040-based boards, etc. with W5x00 or ENC28J60 Ethernet, Teensy 4.1 NativeEthernet/QNEthernet or WiFiNINA modules/shields. W5x00 can use Ethernet, EthernetLarge, Ethernet2 or Ethernet3 library. ENC28J60 can use either EthernetENC or UIPEthernet Library
6+
paragraph=You can use this library to connect your Arduino project directly to a MySQL / MariaDB server without using an intermediate computer or a web-based or cloud-based service. Having direct access to a database server means you can store data acquired from your project as well as check values stored in tables on the server. This also means you can setup your own, local MySQL / MariaDB server to store your data further removing the need for Internet connectivity. If that is not an issue, you can still connect to and store data on a MySQL / MariaDB server via your network, Internet, or even in the cloud! Now accepting server's hostname, besides IPAddress
77
category=Communication
88
url=https://github.com/khoih-prog/MySQL_MariaDB_Generic
99
architectures=*
10-
depends=WiFiNINA_Generic,WebServer_WT32_ETH01,Ethernet,EthernetLarge,Ethernet2,Ethernet3,EthernetENC,UIPEthernet,WiFiEspAT,NativeEthernet
10+
depends=WiFiNINA_Generic,WebServer_WT32_ETH01,Ethernet,EthernetLarge,Ethernet2,Ethernet3,EthernetENC,UIPEthernet,WiFiEspAT,NativeEthernet, QNEthernet
1111
includes=MySQL_Generic.h

platformio/platformio.ini

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ lib_deps =
4444
EthernetENC@~2.0.0
4545
UIPEthernet@~2.0.8
4646
WiFiEspAT@~1.3.1
47+
https://github.com/ssilverman/QNEthernet
4748
; STM32duino STM32Ethernet@~1.2.0
4849
; STM32duino LwIP@~2.1.2
50+
;
4951
; PlatformIO 5.x
5052
; khoih.prog/WiFiNINA_Generic@~1.8.12
5153
; khoih.prog/WebServer_WT32_ETH01@~1.2.0
@@ -58,7 +60,7 @@ lib_deps =
5860
; jandrassy/WiFiEspAT@~1.3.1
5961
; stm32duino/STM32duino LwIP@~2.1.2
6062
; stm32duino/STM32duino STM32Ethernet@~1.2.0
61-
63+
; https://github.com/ssilverman/QNEthernet
6264

6365

6466
build_flags =

src/MySQL_Generic.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
1212
Built by Khoi Hoang https://github.com/khoih-prog/MySQL_MariaDB_Generic
1313
Licensed under MIT license
14-
Version: 1.3.1
14+
Version: 1.4.0
1515
1616
Version Modified By Date Comments
1717
------- ----------- ---------- -----------
@@ -24,13 +24,14 @@
2424
1.2.0 K Hoang 20/07/2021 Add support to WT32_ETH01 (ESP32 + LAN8720A)
2525
1.3.0 K Hoang 30/08/2021 Add support to Teensy 4.1 using NativeEthernet
2626
1.3.1 K Hoang 31/08/2021 Remove unnecessary SPI-bus code in NativeEthernet examples
27+
1.4.0 K Hoang 05/09/2021 Add support to Teensy 4.1 using QNEthernet
2728
**********************************************************************************************************************************/
2829

2930
#ifndef MYSQL_GENERIC_H
3031
#define MYSQL_GENERIC_H
3132

3233
#if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET3 || USE_ETHERNET_ENC || USE_ETHERNET_ESP8266 || \
33-
USE_UIP_ETHERNET || USE_NATIVE_ETHERNET || USE_CUSTOM_ETHERNET )
34+
USE_UIP_ETHERNET || USE_NATIVE_ETHERNET || USE_QN_ETHERNET || USE_CUSTOM_ETHERNET )
3435

3536
#include "MySQL_Generic_Ethernet.h"
3637

src/MySQL_Generic_Connection.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
1414
Built by Khoi Hoang https://github.com/khoih-prog/MySQL_MariaDB_Generic
1515
Licensed under MIT license
16-
Version: 1.3.1
16+
Version: 1.4.0
1717
1818
Version Modified By Date Comments
1919
------- ----------- ---------- -----------
@@ -26,6 +26,7 @@
2626
1.2.0 K Hoang 20/07/2021 Add support to WT32_ETH01 (ESP32 + LAN8720A)
2727
1.3.0 K Hoang 30/08/2021 Add support to Teensy 4.1 using NativeEthernet
2828
1.3.1 K Hoang 31/08/2021 Remove unnecessary SPI-bus code in NativeEthernet examples
29+
1.4.0 K Hoang 05/09/2021 Add support to Teensy 4.1 using QNEthernet
2930
**********************************************************************************************************************************/
3031

3132
/*********************************************************************************************************************************
@@ -66,6 +67,12 @@ class MySQL_Connection : public MySQL_Packet
6667

6768
Connection_Result connectNonBlocking(IPAddress server, int port, char *user, char *password, char *db = NULL);
6869

70+
// KH, add to use hostname. from v1.4.0
71+
bool connect(const char *hostname, int port, char *user, char *password, char *db = NULL);
72+
73+
Connection_Result connectNonBlocking(const char *hostname, int port, char *user, char *password, char *db = NULL);
74+
////////
75+
6976
int connected()
7077
{
7178
return client->connected();

src/MySQL_Generic_Connection_Impl.h

Lines changed: 166 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
1414
Built by Khoi Hoang https://github.com/khoih-prog/MySQL_MariaDB_Generic
1515
Licensed under MIT license
16-
Version: 1.3.1
16+
Version: 1.4.0
1717
1818
Version Modified By Date Comments
1919
------- ----------- ---------- -----------
@@ -26,6 +26,7 @@
2626
1.2.0 K Hoang 20/07/2021 Add support to WT32_ETH01 (ESP32 + LAN8720A)
2727
1.3.0 K Hoang 30/08/2021 Add support to Teensy 4.1 using NativeEthernet
2828
1.3.1 K Hoang 31/08/2021 Remove unnecessary SPI-bus code in NativeEthernet examples
29+
1.4.0 K Hoang 05/09/2021 Add support to Teensy 4.1 using QNEthernet
2930
**********************************************************************************************************************************/
3031

3132
/*********************************************************************************************************************************
@@ -49,7 +50,7 @@
4950

5051
#include <MySQL_Generic_Encrypt_Sha1.h>
5152

52-
#define MAX_CONNECT_ATTEMPTS 5 //3
53+
#define MAX_CONNECT_ATTEMPTS 10 //5 //3
5354
#define CONNECT_DELAY_MS 1000 //500
5455
#define SUCCESS 1
5556

@@ -85,10 +86,12 @@ bool MySQL_Connection::connect(IPAddress server, int port, char *user, char *pas
8586
while (retries++ < MAX_CONNECT_ATTEMPTS)
8687
{
8788
connected = client->connect(server, port);
89+
90+
MYSQL_LOGDEBUG1("connected =", connected);
8891

8992
if (connected != SUCCESS)
9093
{
91-
MYSQL_LOGERROR1("Can't connect. Retry #", retries);
94+
MYSQL_LOGDEBUG1("Can't connect. Retry #", retries);
9295
delay(CONNECT_DELAY_MS);
9396
}
9497
else
@@ -148,26 +151,32 @@ Connection_Result MySQL_Connection::connectNonBlocking(IPAddress server, int por
148151
if (db)
149152
MYSQL_LOGERROR1("Using Database:", db);
150153

151-
while (retries++ < MAX_CONNECT_ATTEMPTS)
154+
while (retries < MAX_CONNECT_ATTEMPTS)
152155
{
153156
if ( (now == 0) || ( millis() - now ) > CONNECT_DELAY_MS )
154157
{
155158
now = millis();
156159

157160
connected = client->connect(server, port);
161+
162+
retries++;
163+
164+
MYSQL_LOGDEBUG1("connected =", connected);
158165

159166
if (connected == SUCCESS)
160167
{
161168
break;
162169
}
163170
else
164171
{
165-
MYSQL_LOGERROR1("Can't connect. Retry #", retries);
166-
//return RESULT_PENDING;
172+
MYSQL_LOGDEBUG1("Can't connect. Retry #", retries);
167173
}
168174
}
169175
else
170-
return RESULT_PENDING;
176+
{
177+
//delay(CONNECT_DELAY_MS);
178+
yield();
179+
}
171180
}
172181

173182
if (connected != SUCCESS)
@@ -208,6 +217,156 @@ Connection_Result MySQL_Connection::connectNonBlocking(IPAddress server, int por
208217
return RESULT_OK;
209218
}
210219

220+
//////////////////////////////////////////////////////////////
221+
// KH, add to use hostname. from v1.4.0
222+
223+
bool MySQL_Connection::connect(const char *hostname, int port, char *user, char *password, char *db)
224+
{
225+
int connected = 0;
226+
int retries = 0;
227+
228+
MYSQL_LOGERROR3("Connecting to Server:", hostname, ", Port = ", port);
229+
230+
if (db)
231+
MYSQL_LOGERROR1("Using Database:", db);
232+
233+
// Retry up to MAX_CONNECT_ATTEMPTS times.
234+
while (retries++ < MAX_CONNECT_ATTEMPTS)
235+
{
236+
connected = client->connect(hostname, port);
237+
238+
MYSQL_LOGDEBUG1("connected =", connected);
239+
240+
if (connected != SUCCESS)
241+
{
242+
MYSQL_LOGDEBUG1("Can't connect. Retry #", retries);
243+
delay(CONNECT_DELAY_MS);
244+
}
245+
else
246+
{
247+
break;
248+
}
249+
}
250+
251+
if (connected != SUCCESS)
252+
return false;
253+
254+
MYSQL_LOGERROR("Connect OK. Try reading packets");
255+
256+
if ( !read_packet() )
257+
{
258+
MYSQL_LOGERROR("Can't connect. Error reading packets");
259+
return false;
260+
}
261+
262+
MYSQL_LOGERROR("Try parsing packets");
263+
264+
parse_handshake_packet();
265+
266+
MYSQL_LOGERROR("Try send_authentication packets");
267+
268+
send_authentication_packet(user, password, db);
269+
270+
if ( !read_packet() )
271+
{
272+
MYSQL_LOGERROR("Can't connect. Error reading auth packets");
273+
return false;
274+
}
275+
276+
if (get_packet_type() != MYSQL_OK_PACKET)
277+
{
278+
parse_error_packet();
279+
return false;
280+
}
281+
282+
MYSQL_LOGERROR1("Connected. Server Version =", server_version);
283+
284+
free(server_version); // don't need it anymore
285+
286+
return true;
287+
}
288+
289+
Connection_Result MySQL_Connection::connectNonBlocking(const char *hostname, int port, char *user, char *password, char *db)
290+
{
291+
int connected = 0;
292+
int retries = 0;
293+
294+
long now = 0;
295+
296+
MYSQL_LOGERROR3("Connecting to Server:", hostname, ", Port = ", port);
297+
298+
if (db)
299+
MYSQL_LOGERROR1("Using Database:", db);
300+
301+
while (retries < MAX_CONNECT_ATTEMPTS)
302+
{
303+
if ( (now == 0) || ( millis() - now ) > CONNECT_DELAY_MS )
304+
{
305+
now = millis();
306+
307+
connected = client->connect(hostname, port);
308+
309+
retries++;
310+
311+
MYSQL_LOGDEBUG1("connected =", connected);
312+
313+
if (connected == SUCCESS)
314+
{
315+
break;
316+
}
317+
else
318+
{
319+
MYSQL_LOGDEBUG1("Can't connect. Retry #", retries);
320+
}
321+
}
322+
else
323+
{
324+
//delay(CONNECT_DELAY_MS);
325+
yield();
326+
}
327+
}
328+
329+
if (connected != SUCCESS)
330+
return RESULT_FAIL;
331+
332+
MYSQL_LOGERROR("Connect OK. Try reading packets");
333+
334+
if ( !read_packet() )
335+
{
336+
MYSQL_LOGERROR("Can't connect. Error reading packets");
337+
return RESULT_FAIL;
338+
}
339+
340+
MYSQL_LOGERROR("Try parsing packets");
341+
342+
parse_handshake_packet();
343+
344+
MYSQL_LOGERROR("Try send_authentication packets");
345+
346+
send_authentication_packet(user, password, db);
347+
348+
if ( !read_packet() )
349+
{
350+
MYSQL_LOGERROR("Can't connect. Error reading auth packets");
351+
return RESULT_FAIL;
352+
}
353+
354+
if (get_packet_type() != MYSQL_OK_PACKET)
355+
{
356+
parse_error_packet();
357+
return RESULT_FAIL;
358+
}
359+
360+
MYSQL_LOGERROR1("Connected. Server Version =", server_version);
361+
362+
free(server_version); // don't need it anymore
363+
364+
return RESULT_OK;
365+
}
366+
367+
368+
//////////////////////////////////////////////////////////////
369+
211370
/*
212371
close - cancel the connection
213372

src/MySQL_Generic_Debug.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
1414
Built by Khoi Hoang https://github.com/khoih-prog/MySQL_MariaDB_Generic
1515
Licensed under MIT license
16-
Version: 1.3.1
16+
Version: 1.4.0
1717
1818
Version Modified By Date Comments
1919
------- ----------- ---------- -----------
@@ -26,6 +26,7 @@
2626
1.2.0 K Hoang 20/07/2021 Add support to WT32_ETH01 (ESP32 + LAN8720A)
2727
1.3.0 K Hoang 30/08/2021 Add support to Teensy 4.1 using NativeEthernet
2828
1.3.1 K Hoang 31/08/2021 Remove unnecessary SPI-bus code in NativeEthernet examples
29+
1.4.0 K Hoang 05/09/2021 Add support to Teensy 4.1 using QNEthernet
2930
**********************************************************************************************************************************/
3031

3132
/*********************************************************************************************************************************

0 commit comments

Comments
 (0)