Closed Endorfin35 closed 3 years ago
It works properly now. The code is below. I'm not sure what happened. My guess is that when I use a Fixed IP, the local network will accept arduino a little late. Thanks for library.
`#include
byte mac_addr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 8, 177); IPAddress gateway(192, 168, 8, 1); IPAddress subnet(255, 255, 255, 0); IPAddress myDns(192, 168, 8, 1);
IPAddress server_addr(192,168,8,100); // IP of the MySQL server here char user[] = "user"; // MySQL user login username char password[] = "1234User"; // MySQL user login password
// Sample query char INSERT_SQL_1[] = "INSERT INTO test1.laser (veri) VALUES ('500');"; //////////////////////"INSERT INTO test_arduino.hello_arduino (message) VALUES ('Hello, Arduino!')";
EthernetClient client; MySQL_Connection conn((Client *)&client);
void setup() { Serial.begin(115200); while (!Serial); // wait for serial port to connect
Ethernet.begin(mac_addr, ip, myDns, gateway, subnet);
delay(2000);
Serial.println("Connecting..."); if (conn.connect(server_addr, 3306, user, password)) { delay(1000); } else Serial.println("Connection failed."); }
void loop() { delay(2000);
Serial.println("Recording data.");
// Initiate the query class instance MySQL_Cursor *cur_mem = new MySQL_Cursor(&conn); // Execute the query cur_mem->execute(INSERT_SQL_1); // Note: since there are no results, we do not need to read any data // Deleting the cursor also frees up memory used delete cur_mem; }`
Good. Please close the issue if you are satisfied. :)
On Sep 17, 2020, at 10:55 AM, Endorfin35 notifications@github.com wrote:
It works properly now. The code is below. I'm not sure what happened. My guess is that when I use a Fixed IP, the local network will accept arduino a little late.
`#include
include
include
byte mac_addr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 8, 177); IPAddress gateway(192, 168, 8, 1); IPAddress subnet(255, 255, 255, 0); IPAddress myDns(192, 168, 8, 1);
IPAddress server_addr(192,168,8,100); // IP of the MySQL server here char user[] = "user"; // MySQL user login username char password[] = "1234User"; // MySQL user login password
// Sample query char INSERT_SQL_1[] = "INSERT INTO test1.laser (veri) VALUES ('500');"; //////////////////////"INSERT INTO test_arduino.hello_arduino (message) VALUES ('Hello, Arduino!')";
EthernetClient client; MySQL_Connection conn((Client *)&client);
void setup() { Serial.begin(115200); while (!Serial); // wait for serial port to connect
Ethernet.begin(mac_addr, ip, myDns, gateway, subnet);
delay(2000); Serial.println("Connecting..."); if (conn.connect(server_addr, 3306, user, password)) { delay(1000); } else Serial.println("Connection failed."); }
void loop() { delay(2000);
Serial.println("Recording data.");
// Initiate the query class instance MySQL_Cursor *cur_mem = new MySQL_Cursor(&conn); // Execute the query cur_mem->execute(INSERT_SQL_1); // Note: since there are no results, we do not need to read any data // Deleting the cursor also frees up memory used delete cur_mem; }`
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/ChuckBell/MySQL_Connector_Arduino/issues/156#issuecomment-694290821, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB6SHYA2GCSHMAM5QQ2D4N3SGIPNJANCNFSM4RQKNR3Q.
I tried the examples and I have successful connection
However, When I try to give a fixed IP with the Ethernet.begin command, the connection fails.
`
include
include
byte mac_addr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 8, 177); IPAddress gateway(192, 168, 8, 1); IPAddress subnet(255, 255, 255, 0); IPAddress myDns(192, 168, 8, 1);
IPAddress server_addr(192,168,8,100); // IP of the MySQL server here char user[] = "user"; // MySQL user login username char password[] = "1234User"; // MySQL user login password //char default_db = "test1;
EthernetClient client; MySQL_Connection conn((Client *)&client);
void setup() { Serial.begin(9600); while (!Serial); // wait for serial port to connect // Ethernet.begin(mac_addr, ip); ------------------------------------------??????? Ethernet.begin(mac_addr); Serial.println("Connecting..."); //if (conn.connect(server_addr, 3306, user, password)) if (conn.connect(server_addr, 3306, user, password,default_db)) { delay(1000); // You would add your code here to run a query once on startup. } else { Serial.println("Connection failed."); } conn.close(); }`
I want to give an IP instead of DHCP. Is this possible?