ChuckBell / MySQL_Connector_Arduino

Database connector library for using MySQL with your Arduino projects.
332 stars 133 forks source link

ERROR: Timeout waiting for client. #216

Open smorelsc opened 6 months ago

smorelsc commented 6 months ago

I’m trying to connect an Arduino R4 Wifi and an Arduino Uno with Ethernet shield HanRun HR911105A 15/10 to SQL Server 2022 Development Edition installed on Windows 10 Pro OS. The SQL Server TCP/IP Properties for IPALL is configured to use port 1433. I created an Inbound and Outbound Windows Defender Firewall Rule to allow port 1433 traffic. I didn’t create a new SQL Login account assuming that “sa” would have the required permissions. I confirmed that I can remotely connect to the database from another PC on the Network. I tried turning off the Firewall. I can’t seem to get either Arduino board to connect to the database no matter what I try, both are giving the same Timeout error, I was wondering if you could provide some ideas?

Output of the R4 Wifi SSID: MYNetwork IP Address: 192.168.1.105 signal strength (RSSI):-59 dBm To see this page in action, open a browser to http://192.168.1.105 Connecting... to database server_addr = 192.168.1.120 port = 1433 user = sa password = password ...trying... ERROR: Timeout waiting for client. ERROR: Timeout waiting for client. Error: -1 = FAILED to connect to SQL Server!

Code for above error; *

include

include

char ssid[] = "SSID "; // your network SSID (name) char pass[] = "password"; // your network password (use for WPA, or use as key for WEP)

int status = WL_IDLE_STATUS; WiFiServer server(80);

byte mac_addr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

IPAddress server_addr(192,168,1,120); // IP of the SQL Server Database char user[] = "sa"; // SQL Server user login username char password[] = "password"; // SQL Server user login password

WiFiClient client; MySQL_Connection conn((Client *)&client);

void printWifiStatus() { // print the SSID of the network you're attached to: Serial.print("SSID: "); Serial.println(WiFi.SSID());

// print your board's IP address: IPAddress ip = WiFi.localIP(); Serial.print("IP Address: "); Serial.println(ip);

// print the received signal strength: long rssi = WiFi.RSSI(); Serial.print("signal strength (RSSI):"); Serial.print(rssi); Serial.println(" dBm"); // print where to go in a browser: Serial.print("To see this page in action, open a browser to http://"); Serial.println(ip); }

void setup(void) { // start serial port Serial.begin(9600);

// check for the WiFi module: if (WiFi.status() == WL_NO_MODULE) { Serial.println("Communication with WiFi module failed!"); // don't continue while (true); }

// attempt to connect to WiFi network: while (status != WL_CONNECTED) { Serial.print("Attempting to connect to Network named: "); Serial.println(ssid); // print the network name (SSID);

// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
status = WiFi.begin(ssid, pass);
// wait 10 seconds for connection:
delay(10000);

}

printWifiStatus(); // you're connected now, so print out the status String fv = WiFi.firmwareVersion(); if (fv < WIFI_FIRMWARE_LATEST_VERSION) { Serial.println("Please upgrade the firmware"); } }

void loop(void) { Serial.println("Connecting... to database"); Serial.print ("server_addr = "); Serial.println(server_addr); Serial.print ("port = "); Serial.println(1433); Serial.print ("user = "); Serial.println(user); Serial.print ("password = "); Serial.println(password); delay(2000);

if (conn.connect(server_addr, 1433, user, password)) { Serial.println("Connection WORKED"); delay(1000); // You would add your code here to run a query once on startup. // this is where the databse update statment would go } else{ Serial.println("FAILED to connect to SQL Server!"); } conn.close(); delay(1000); }

Output of the Uno Shield Connected to Network My IP address: 192.168.1.122 Connecting... to database server_addr = 192.168.1.120 port = 1433 user = sa password = password ...trying... ERROR: Timeout waiting for client. ERROR: Timeout waiting for client. Error: -1 = FAILED to connect to SQL Server!

The code for the above error / Testing SQL Connect using Uno and Shield /

include

include

byte mac_addr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

IPAddress server_addr(192,168,1,120); // IP of the MySQL server here char user[] = "sa"; // MySQL user login username char password[] = "password"; // MySQL user login password

EthernetClient client; MySQL_Connection conn((Client *)&client);

void setup() { // You can use Ethernet.init(pin) to configure the CS pin //Ethernet.init(10); // Most Arduino shields // Open serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for native USB port only }

// start the Ethernet connection: Serial.println("Initialize Ethernet with DHCP:"); if (Ethernet.begin(mac_addr) == 0) { Serial.println("Failed to configure Ethernet using DHCP"); if (Ethernet.hardwareStatus() == EthernetNoHardware) { Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); } else if (Ethernet.linkStatus() == LinkOFF) { Serial.println("Ethernet cable is not connected."); } // no point in carrying on, so do nothing forevermore: while (true) { delay(1); } } // print your local IP address: Serial.print(" Connected to Network My IP address: "); Serial.println(Ethernet.localIP());

}

void loop() { Serial.println("Connecting... to database"); Serial.print ("server_addr = "); Serial.println(server_addr); Serial.print ("port = "); Serial.println(1433); Serial.print ("user = "); Serial.println(user); Serial.print ("password = "); Serial.println(password); delay(2000);

if (conn.connect(server_addr, 1433, user, password)) { Serial.println("Connection WORKED"); delay(1000); // You would add your code here to run a query once on startup. } else{ Serial.println("FAILED to connect to SQL Server!"); } conn.close(); delay(1000); }

ChuckBell commented 6 months ago

Hi. It appears you may be attempting to use the connector with Microsoft SQL Server, but this connector is written specifically for MySQL and cannot be used with MS SQL Server. If that is not the case, please tell me which version of MySQL your are using.

On Sun, Dec 17, 2023 at 11:44 smorelsc @.***> wrote:

I’m trying to connect an Arduino R4 Wifi and an Arduino Uno with Ethernet shield HanRun HR911105A 15/10 to SQL Server 2022 Development Edition installed on Windows 10 Pro OS. The SQL Server TCP/IP Properties for IPALL is configured to use port 1433. I created an Inbound and Outbound Windows Defender Firewall Rule to allow port 1433 traffic. I didn’t create a new SQL Login account assuming that “sa” would have the required permissions. I confirmed that I can remotely connect to the database from another PC on the Network. I tried turning off the Firewall. I can’t seem to get either Arduino board to connect to the database no matter what I try, both are giving the same Timeout error, I was wondering if you could provide some ideas?

Output of the R4 Wifi SSID: MYNetwork IP Address: 192.168.1.105 signal strength (RSSI):-59 dBm To see this page in action, open a browser to http://192.168.1.105 Connecting... to database server_addr = 192.168.1.120 port = 1433 user = sa password = password ...trying... ERROR: Timeout waiting for client. ERROR: Timeout waiting for client. Error: -1 = FAILED to connect to SQL Server!

Code for above error; *

  • Testing SQL Server Connection from Uno R4 WiFi */

include

include

char ssid[] = "SSID "; // your network SSID (name) char pass[] = "password"; // your network password (use for WPA, or use as key for WEP)

int status = WL_IDLE_STATUS; WiFiServer server(80);

byte mac_addr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

IPAddress server_addr(192,168,1,120); // IP of the SQL Server Database char user[] = "sa"; // SQL Server user login username char password[] = "password"; // SQL Server user login password

WiFiClient client; MySQL_Connection conn((Client *)&client);

void printWifiStatus() { // print the SSID of the network you're attached to: Serial.print("SSID: "); Serial.println(WiFi.SSID());

// print your board's IP address: IPAddress ip = WiFi.localIP(); Serial.print("IP Address: "); Serial.println(ip);

// print the received signal strength: long rssi = WiFi.RSSI(); Serial.print("signal strength (RSSI):"); Serial.print(rssi); Serial.println(" dBm"); // print where to go in a browser: Serial.print("To see this page in action, open a browser to http://"); Serial.println(ip); }

void setup(void) { // start serial port Serial.begin(9600);

// check for the WiFi module: if (WiFi.status() == WL_NO_MODULE) { Serial.println("Communication with WiFi module failed!"); // don't continue while (true); }

// attempt to connect to WiFi network: while (status != WL_CONNECTED) { Serial.print("Attempting to connect to Network named: "); Serial.println(ssid); // print the network name (SSID);

// Connect to WPA/WPA2 network. Change this line if using open or WEP network: status = WiFi.begin(ssid, pass); // wait 10 seconds for connection: delay(10000);

}

printWifiStatus(); // you're connected now, so print out the status String fv = WiFi.firmwareVersion(); if (fv < WIFI_FIRMWARE_LATEST_VERSION) { Serial.println("Please upgrade the firmware"); } }

void loop(void) { Serial.println("Connecting... to database"); Serial.print ("server_addr = "); Serial.println(server_addr); Serial.print ("port = "); Serial.println(1433); Serial.print ("user = "); Serial.println(user); Serial.print ("password = "); Serial.println(password); delay(2000);

if (conn.connect(server_addr, 1433, user, password)) { Serial.println("Connection WORKED"); delay(1000); // You would add your code here to run a query once on startup. // this is where the databse update statment would go } else{ Serial.println("FAILED to connect to SQL Server!"); } conn.close(); delay(1000); }

Output of the Uno Shield Connected to Network My IP address: 192.168.1.122 Connecting... to database server_addr = 192.168.1.120 port = 1433 user = sa password = password ...trying... ERROR: Timeout waiting for client. ERROR: Timeout waiting for client. Error: -1 = FAILED to connect to SQL Server!

The code for the above error / Testing SQL Connect using Uno and Shield /

include

include

byte mac_addr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

IPAddress server_addr(192,168,1,120); // IP of the MySQL server here char user[] = "sa"; // MySQL user login username char password[] = "password"; // MySQL user login password

EthernetClient client; MySQL_Connection conn((Client *)&client);

void setup() { // You can use Ethernet.init(pin) to configure the CS pin //Ethernet.init(10); // Most Arduino shields // Open serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for native USB port only }

// start the Ethernet connection: Serial.println("Initialize Ethernet with DHCP:"); if (Ethernet.begin(mac_addr) == 0) { Serial.println("Failed to configure Ethernet using DHCP"); if (Ethernet.hardwareStatus() == EthernetNoHardware) { Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); } else if (Ethernet.linkStatus() == LinkOFF) { Serial.println("Ethernet cable is not connected."); } // no point in carrying on, so do nothing forevermore: while (true) { delay(1); } } // print your local IP address: Serial.print(" Connected to Network My IP address: "); Serial.println(Ethernet.localIP());

}

void loop() { Serial.println("Connecting... to database"); Serial.print ("server_addr = "); Serial.println(server_addr); Serial.print ("port = "); Serial.println(1433); Serial.print ("user = "); Serial.println(user); Serial.print ("password = "); Serial.println(password); delay(2000);

if (conn.connect(server_addr, 1433, user, password)) { Serial.println("Connection WORKED"); delay(1000); // You would add your code here to run a query once on startup. } else{ Serial.println("FAILED to connect to SQL Server!"); } conn.close(); delay(1000); }

— Reply to this email directly, view it on GitHub https://github.com/ChuckBell/MySQL_Connector_Arduino/issues/216, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB6SHYBS2YL6Z7HRNTJD2WLYJ4OQFAVCNFSM6AAAAABAYPCXPWVHI2DSMVQWIX3LMV43ASLTON2WKOZSGA2DKMRYHA3DANY . You are receiving this because you are subscribed to this thread.Message ID: @.***>

smorelsc commented 6 months ago

No wonder I was having so much trouble, I thought they were the same thing. Is there a particular version of MySQL I should be looking to install? Can .Net connect to MySQL too?

ChuckBell commented 6 months ago

Hi. Any version of MySQL from Oracle will work. https://dev.mysql.com/downloads/

On Dec 17, 2023, at 3:16 PM, smorelsc @.***> wrote:

No wonder I was having so much trouble, I thought they were the same thing. Is there a particular version of MySQL I should be looking to install? Can .Net connect to MySQL too?

— Reply to this email directly, view it on GitHub https://github.com/ChuckBell/MySQL_Connector_Arduino/issues/216#issuecomment-1859272255, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB6SHYGI23HDM2IR3ZEBEV3YJ5HJ7AVCNFSM6AAAAABAYPCXPWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNJZGI3TEMRVGU. You are receiving this because you commented.