问题
Is it at all possible to send data to a MySQL database from an Arduino with an Ethernet shield?
Currently I have data outputting to a webpage, but I would like to record a history of that data - can I send the data directly to a databse?
Alternatively, can I use PHP to capture the data and send it to a database without having a page constantly open, as I would like to record data over a series of days.
回答1:
Yes you can, although it might be tediouis. The details of client/server protocol are here: http://dev.mysql.com/doc/internals/en/client-server-protocol.html so it's just a matter of implementing it in Arduino. Given program memory limitations, it might a difficult task though.
The other option, having database exposed as a webservice would be a lot easier. You can define the protocol however you wish, and leave all MySQL handling to PHP.
回答2:
Without a web server and PHP, you would need a MySQL client library for the Arduino, but I don't think one exists. AFAIK it's not possible to communicate directly with the MySQL server otherwise.
If you install a web server with PHP alongside MySQL, you can set up a PHP script that listens to the Arduino's requests and stores the passed-in data into the database. Those connections are between the Arduino and the web server, so you don't have to keep any page constantly open.
Note that the PHP script won't listen just to your Arduino but to anyone sending a request to it, so you should make sure that you can trust the passed-in data before storing it in the database.
回答3:
This is now possible with the new Connector/Arduino MySQL Database connector. Check it out at: https://launchpad.net/mysql-arduino. Also, see my blog at: http://drcharlesbell.blogspot.com/2013/04/introducing-mysql-connectorarduino_6.html
来源:https://stackoverflow.com/questions/9456908/can-i-put-items-in-a-mysql-database-directly-from-my-arduino