0

I'm trying to establish a connection with a MySQL database on a local server wirelessly using the following script:

The wireless connection with my router is successful but then connection with database results in

I'm using a WeMos D1 mini ESP8266, Windows 10, WAMP64, MySQL 5.7.14.

I get ping responses from MySQL at 127.0.0.1, and my host computer and also the ESP8266. I've disabled my Windows Firewall to test it temporarily. After the wifi connects with the ESP8266 and confirms the correct WiFi.localIP, 'Connection failed' error with additional text below.

I can manually enter data into the test_arduino table so I think it's a connection issue with the database server. Maybe something to do with my router's handling of of Port 80.

I am able to send sensor data to remote sites such as ThingSpeak.

Any help would be appreciated.

// Created by: Dr. Charles A. Bell
#include "ESP8266WiFi.h"
#include <MySQL_Connection.h>
#include <MySQL_Cursor.h>
IPAddress server_addr(192,168,0,10); // IP of the MySQL *server* here
char user[] = "root"; // MySQL user login username
char password[] = "PASSWORD"; // MySQL user login password
const char* SSID = "MYSSID"; // Your network SSID
const char* PASS = "MYPASSWORD";
// Sample query
char INSERT_SQL[] = "INSERT INTO test_arduino.hello_arduino (message) VALUES ('Hello, Arduino!')";
WiFiClient client;
MySQL_Connection conn((Client *)&client);
void setup() {
 Serial.begin(115200);
 while (!Serial); // wait for serial port to connect
 Serial.print("Connecting to "+*SSID);
 WiFi.begin(SSID, PASS);
 Serial.println("going into wl connect");
 while (WiFi.status() != WL_CONNECTED) //not connected, ...waiting to connect
 {
 delay(1000);
 Serial.print(".");
 }
 Serial.println("wl connected");
 Serial.println("");
 Serial.println("Credentials accepted! Connected to wifi\n ");
 Serial.println(WiFi.localIP());
 Serial.println("");
 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);
 // 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;
}

The following is the Serial COM4 readout:

Connected to wifi
 going into wl connect
.......wl connected
Credentials accepted! Connected to wifi
192.168.1.XX (intentionally deleted)
Connection failed.
Recording data.
Exception (3):
epc1=0x402050ea epc2=0x00000000 epc3=0x00000000 excvaddr=0x402315cc depc=0x00000000
ctx: cont 
sp: 3ffef5a0 end: 3ffef7d0 offset: 01a0
>>>stack>>>
3ffef740: 0a00a8c0 00000001 3ffe8785 402050f4 
3ffef750: 3ffee524 0000000e 3ffe850e 3ffee79c 
3ffef760: 3fffdad0 00000000 3ffee770 402048fd 
3ffef770: 402315cc 00000000 3ffee770 3ffee79c 
3ffef780: 3fffdad0 00000000 3ffee770 40204945 
3ffef790: 402010ae 00000000 3fff061c 4020292e 
3ffef7a0: 3ffe8780 00000000 3fff061c 40201d3e 
3ffef7b0: 3fffdad0 00000000 3ffee794 40204c34 
3ffef7c0: feefeffe feefeffe 3ffee7b0 40100718 
<<<stack<<<
 ets Jan 8 2013,rst cause:2, boot mode:(3,7)
load 0x4010f000, len 1384, room 16 
tail 8
chksum 0x2d
csum 0x2d
v09f0c112
~ld
sa_leinad
3,2182 gold badges23 silver badges51 bronze badges
asked Jun 12, 2017 at 0:22
1
  • It looks like you haven't finished part of your question: "The wireless connection with my router is successful but then connection with database results in...." Commented Jun 14, 2017 at 7:19

1 Answer 1

0

I figured it out. I needed to set up a User (IP server) in the database. In phpMyAdmin I created a new user (esp) and set the Host name to the IP address of the ESP8266. In the sketch I changed the user from "root" to "esp".

answered Jun 12, 2017 at 6:37
2
  • 2
    Please expand upon your answer. Your answer may prove to be useful to someone else, who has the same issue, but with less understanding of how to solve it. Commented Jun 12, 2017 at 8:12
  • Please accept your answer once you have edited/expanded on it. Commented Jun 14, 2017 at 7:14

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.