Write and Read to database Arduino via ESP


I need some help with this module: MEGA+WiFi R3 ATmega2560+ESP8266, flash 32MB, USB-TTL CH340G, Micro-USB

I was able to program esp to be a server and control the output for arduino.

Unfortunately, I do not know how to program communication: MySql -> ESP -> Arduino Arduino -> ESP -> MySql

This is reading and writing to the database.

Could you help me program this?

You will find limited support to write a full thing for you... we all have our projects and can help sharing ideas when someone is stuck, but if you want someone to write code for you, then it's more for the Gigs and Collaboration forum (and expect to pay for this).

On your needs:

do you expect your database to contact the ESP?

reading or writing is usually initiated [u]by a client[/u] of the Database. (with MySql you could have User Defined Functions within the DB that could trigger an HTTP request but this is not a great practice).

MySql has a REST API you could trigger through http from your ESP but probably best would be to not make your DB directly accessible from the internet and only have a higher level abstraction web server (PHP, Python, ...) that would be your interface to access the DB and read/write the data you want (possibly returning JSON formatted stuff)

I think You should explore first how to reach out from your ESP to a webServer (ie you are a client) and how to receive incoming HTTP request (your ESP is the Server). There are plenty of tutorials for this.

You should explore how database and SQL work.

You should learn the basics of how to program on the server side (PHP or Python for example)

then you should be able to build something ... won't happen in a few hours though

I jave a lot of experience with MySQL and Java ... including tale creation, data insertion, querying and perhaps the most beautiful feature of MySQL - Stored Procedures (which ultimately makes your code that talks to the database much simpler to read and write) .... but I have ZERO experience with MySQL in an Arduino environment.

Have you found any libraries that simplify the interaction with MySQL in the Arduino world? If so, can you give me a link? I might be able to throw something simple together to give you the gist of how it works so you can take it from there and develop what you need.


Mike - as discussed above, I assume OP does not want to embed a database in his Arduino but that the DB lives somewhere on the internet.

So unless you use some sort of direct REST interface from MySQL, which I have not done personally, the easiest way is to write a simple server side program that exposes a high level REST API (or other type of UDP/IP based protocol) and that program handles communication locally to the DB and returns the data (formatted and ideally simplified to small sets as memory is limited) to the arduino which triggered the read or write DB request.

Found this tutorial that might help