我现在遇到的问题是:使用Arduino上下载的MySQL的类库里的示例代码,使用ESP8266连接MySQL数据库并在表中插入测试数据,在串口上显示WiFi连接成功但是数据库连接失败
- #include <ESP8266WiFi.h> // Use this for WiFi instead of Ethernet.h
- #include <MySQL_Connection.h>
- #include <MySQL_Cursor.h>
- IPAddress server_addr(192,168,1,3); // 这个是我自己电脑的ip地址
- char user[] = "root"; // MySQL user login username
- char password[] = "123456"; // MySQL user login password
- // Sample query
- char INSERT_SQL[] = "INSERT INTO test.mess (message) VALUES ('Hello, Arduino!')";
- // WiFi card example
- char ssid[] = "CU_cJt5"; // your SSID
- char pass[] = "nv4q5vzz"; // your SSID Password
- WiFiClient client; // Use this for WiFi instead of EthernetClient
- MySQL_Connection conn(&client);
- MySQL_Cursor* cursor;
- void setup()
- {
- Serial.begin(115200);
- while (!Serial); // wait for serial port to connect. Needed for Leonardo only
- // Begin WiFi section
- Serial.printf("\nConnecting to %s", ssid);
- WiFi.begin(ssid, pass);
- while (WiFi.status() != WL_CONNECTED) {
- delay(500);
- Serial.print(".");
- }
- // print out info about the connection:
- Serial.println("\nConnected to network");
- Serial.print("My IP address is: ");
- Serial.println(WiFi.localIP());
- Serial.print("Connecting to SQL... ");
- Serial.println(server_addr);
- if (conn.connect(server_addr, 3306, user, password)) //在这一步执行连接的时候总是失败
- Serial.println("OK.");
- else
- Serial.println("FAILED.");
-
- // create MySQL cursor object
- cursor = new MySQL_Cursor(&conn);
- }
- void loop()
- {
- if (conn.connected())
- cursor->execute(INSERT_SQL);
- delay(5000);
- }
复制代码 我在自己的MySQL中用我自己电脑的ip地址可以登入MySQL但是通过ESP8266却失败了,我想请教一下原因
|