Hello!
I buy a CC3000 wifi shield and try to connect with a MySQL database.
How can a I do this? Send some parameters to MySQL database?
I managed to send paramenter form WEB to Arduino using sockets, but how i do the reverse?
Tnks
Hello!
I buy a CC3000 wifi shield and try to connect with a MySQL database.
How can a I do this? Send some parameters to MySQL database?
I managed to send paramenter form WEB to Arduino using sockets, but how i do the reverse?
Tnks
Searching 'arduino mysql' revealed this: MySQL Connector/Arduino in Launchpad.
If you have a web server, it might be more efficient to use a php script to access the DB and return content ready for the Arduino.
Also, if you are using an actual web sql server (not a local server on your PC) then you will be transmitting your DB user and pass in plaintext over the internet.
A php script will allow you to control what happens to the DB, and if needed an Arduino could talk securely to the php script using AES or something similar.
Pyro, what you propose is a good idea. But in this part I try and I dont have results, I cant send parameter to a PHP page. You know how to do? I see something with client.print(), but i dont see how really work.
There are examples that come with the IDE.
Using the WebClient example:
In the line of code highlighted here, you can see a parameter being sent with a GET request. The example connects to google and searches the term 'arduino'.
https://github.com/arduino/Arduino/blob/master/libraries/Ethernet/examples/WebClient/WebClient.ino#L58
To send data using POST, search the forums for examples, there are many.
Can I use the same code to a local server?
should be able to replace the server domain name with your local IP (127.0.0.1, or 'localhost')
char server[] = "127.0.0.1";
And possibly remove this line here
Pyro, a try somethings and a done this code:
dafruit_CC3000_Client www = cc3000.connectTCP(ip, 80);
if (www.connected()) {
www.fastrprint(F("GET "));
www.fastrprint(WEBPAGE);
www.fastrprint(F(" HTTP/1.1\r\n"));
www.fastrprint(F("Host: ")); www.fastrprint(WEBSITE); www.fastrprint(F("\r\n"));
www.fastrprint(F("\r\n"));
www.print(request);
www.println();
}
This code work, they acess one page, and for test, when this page was accessed, print one new line in DB.
But now, how i send a parameter like "Temperature= 115"?
I use a PHP page very simple:
<?php $data= $_GET["temp"]; $host = "localhost"; $usuario1 = "root"; $password = ""; $link = mysql_connect($host, $usuario1, $password) or die ("Erro ao tentar conectar"); /* nesse arquivo estão definidas todas as variaveis responsaveis pela conexão com o banco de dados */ mysql_query("CREATE DATABASE IF NOT EXISTS testeluz") or die(mysql_error()); mysql_select_db('testeluz') or die(mysql_error()); mysql_query("CREATE TABLE IF NOT EXISTS teste1 ( id INT AUTO_INCREMENT PRIMARY KEY, HORA INT)") or die(mysql_error()); mysql_query("INSERT INTO teste1 VALUES('null', '$data')") or die(mysql_error()); ?>I see my mistake now!
I have to send the data in:
#define WEBPAGE "/controleluz/send.php?cort=123&nluz=500"...
Now work ^^