Sending data from Arduino to MySQL PLEASE HELP ME!

Dear Arduino community I come here to this post to ask for your help in one topic.
I need to send data from my arduino to a MySQL database and I have found different options about how to do it:

  1. Using MySQL connector and MySQL Workbench
  2. Sending the data from Arduino to a php and from php to MySQL

I already tried the first one and I had to purchase an arduino mega for this, and even that, it did not wotk propertly it takes so much time after every measurement and I want to send measurements every second. Furthermore at some point it crashes and I does not send data anymore (I don't know why)

The second one is new for me I see that you create an add.php file or something like that but I am not sure how to use this. I searched some info on the internet but I didn't find anything. Nevertheless I saw on this forum that someone made something similar. So I would appreciate it a lot a lot if someone can give me an example including the steps and the code for using the second option

Best regards,

Cesar.

Since it's clear you have little understanding about HOW to achieve what you want to achieve, you will be better of describing WHAT you want to achieve instead of telling us about your misunderstandings upon HOWs

So people here having better knowledge upon functional HOWs will describe them to you instead.

Better speak about platforms and processes like

  • which operating system mysql is running on laptop/PC/other
  • which arduino board you intend to use, if you decided already
  • and if not, you'll have to describe in detail what are the inputs/processing that have to be done on the arduino itself.
  • what kind of communication you desire/are required between the two above (e.g. wired, wireless, across continents, etc..)
  • how much data that needs to be stored in database arduino generates
  • how fast the above data is generated

Stuff like that.

blimpyway:
Since it's clear you have little understanding about HOW to achieve what you want to achieve, you will be better of describing WHAT you want to achieve instead of telling us about your misunderstandings upon HOWs

So people here having better knowledge upon functional HOWs will describe them to you instead.

Better speak about platforms and processes like

  • which operating system mysql is running on laptop/PC/other
  • which arduino board you intend to use, if you decided already
  • and if not, you'll have to describe in detail what are the inputs/processing that have to be done on the arduino itself.
  • what kind of communication you desire/are required between the two above (e.g. wired, wireless, across continents, etc..)
  • how much data that needs to be stored in database arduino generates
  • how fast the above data is generated

Stuff like that.

-Which operating system: MySQL Workbench
-Which arduino board: ATMEGA2560

  • I use to digital pins from the arduino that gives me HIGH other LOW signal depending on the measurement of the dust sensor (which by the way it is a DSM501a)
  • Communication: I have to use (I prefer to use) a Wireless shield
  • How much data: 4 tables with 20 values
  • how fast the data is generated: every second if possible

Hopefully you can help me. What I need to know is an example of a php file that I have to include for making the connection between the arduino and the mysql workbench, and where do I put this file
I saw a tutorial:

but it uses phpadmin and XXamp

Thanks in advance if you can help
Regards,
Cesar

Operating systems are named "Windows", "Mac OS", "Linux" or "OS/2"

Programing languages are "C", "C++", "C#", "VB", "Perl", "Ruby", "Python", "Java", "Objective-C", "Javascript" and yeah "PHP" is also just another language.

"Mysql Connector" is a generic term for any library that can be used by any code written in a specific programming language on a specific operating system to interact with a mysql database backend..

That means you must use a specific "connector" library for the specific language/os combination of your choice.

"Mysql Workbench" is not an operating system, it seems it's a visual interface program/tool for human interface/interaction to the database backend. Most likely, NOT meant to be used for general program to database interface, otherwise they wouldn't need to have all those "connectors" in the first place.


Can not tell much about PHP, I never used it, you have any good reason to use it or you just weren-t aware there are so many other options?

I'm asking it because PHP is specifically tailored to write server-side web applications and that might not be the simplest route to get the data from arduino to the database.


You might be more successful by asking these questions on this board: Interfacing w/ Software on the Computer - Arduino Forum

Hi Cesar,

I use php to insert data into a mysql database. See my project here.

I think one update per second would be too fast. Maybe one update every 10s would be OK.

Paul

Just to make things clear, there is no possible PHP (or any other programing language running on PC) that can extract arbitrarily data from an arduino's input pins

You need to design/ write:

  • an arduino program that extracts information from arduino input pins and forwards that relevant data in a clear specified format.
  • a PC program that receives this data sent by arduino and transforms it in appropriate calls to the Mysql Connector library to update the database.

And the two above

  • must have a common understanding upon how data is encoded/transmitted between arduino and PC program.
  • the PC program doesn't have to be PHP unless there-s a compelling reason you cannot run any other programs than PHP scripts (e.g. is a virtual site hosted somewhere on the internet with only PHP/mysql scripting available)

PaulRB:
I think one update per second would be too fast. Maybe one update every 10s would be OK.

To be more specific, you probably meant to say that one update/sec is unnecessarily fast for the purpose of OP's application, not that the http/php/mysql combo can not handle the faster update rate?

Hi Paul thanks a lot for your contribution it really helped me. I have one question I am following this tutorial:

and I need to know where to save the php file when using MySQL workbench. It says for example in this tutorial:

""2. Put the “write_data.php” file in the right folder

If you are using XAMPP you will need to place the file in the “C:\xampp\htdocs” directory (or if your XAMPP install directory is different use that directory\htdocs).

OR

If you are using an online web page, you will need to place the file in the “public_html/www” directory.""

In the case of Workbench where is this folder.

Best regards, and thanks a lot for your help

Sebastian

Hi Sebastian or Cesar (or whatever you want to be called, please decide)

The location where php scripts are kept has nothing to do with Mysql Workbench. The Workbench is a tool for creating databases.

What determines where php scripts are kept is the webserver, which is a separate concept and component of a system compared to a database, although they are usually used together.

There is a good chance that the webserver you are using is one called Apache. You may have heard of "LAMP", which refers to a bundle of applications that often go together. The " L" stands for Linux, "A" stands for Apache, the "M" stands for MySql and "P" stands for PHP.

In Apache, the php scripts are kept in the public_html folder. You normally have to copy them to that location using an FTP application on your PC.

Hi Paul I have a problem I try to access to 127.0.0.1 in my web browser (google chrome) and it says it can't.... I installed apache what else do I have to do?
Please help me.

Cesar Sebastian

Cesar, this is an Arduino forum. Your choice of PHP requires you to know how to properly install, configure and run Apache, MySQL server, SQL programming, HTTP and web server-side scripting with peculiarities of PHP language/modules. All these are very unrelated to arduino development, while general tutorials/beginner advice for Apache, MySQL, PHP, HTTP are somewhere else.

Once you nail these, you can follow here with questions like "How do I make HTTP requests from Arduino to interact with an HTTP server script"

I did not install Apache myself. I pay an annual subscription for a small virtual server on the internet. It came with Apache pre-installed and working. It sounds like your Apache is not installed or configured correctly, but I do not know enough about it to help you with that.

As blimpyway said, there are other forums and website where you can get help with LAMP/WAMP. Those forums won't be able to help you with the Arduino side of your project.

There are example sketches from the MySQL Connector Arduino Library that I think you should check out, if you haven't yet. They will help you understand using the library a bit more, and you can actually try sending/receiving some data from your mySQL database. Depending on whether or not you're accessing the DB server remotely, you'll have to set up the server to ensure remote access is enabled (creating users with all privileges granted, opening up ports from the firewall setting, bind-address option removed, etc.).

Here's a link of one of the example sketches: