Hi, I have the data of the sensors stored locally in mySql and I need to send this data to a web server (not local) every other minute. Which would be the best way to send this data so I can store it in mySql in the web server?
Arduino code:
**********************************************************************************************************************
void send_temperatura() {
if (togglesensore == true) {
#ifdef debug
Console.println ("start Send");
#endif
digitalWrite(status_led, ON);
String datadb = nowdata();
String timedb = nowtime();
Send.begin("curl"); // Process that launch the "curl" command
String Sitourl = sito + "/inserisci.php?data=" + datadb +"&ora="+ timedb + "&temperatura=" + settemp + "&umidita=" + setumid + "&stato=" + stato + "&setpoint=" + settemperatura / 100 ;
Send.addParameter("--connect-timeout");
Send.addParameter("10");
Send.addParameter("-m");
Send.addParameter("60");
Send.addParameter( Sitourl ); // Add the URL parameter to "curl"
#ifdef debug
Console.println (Sitourl);
#endif
Send.run();// Run the process and wait for its termination
String risp = "";
#ifdef debug
Console.println ("send run");
Console.println(Send.exitValue());
#endif
if (Send.exitValue() == 0 && Send.available() > 0) {
risp = Send.readString();
Send.close();
b = 0 ;
}
else
{
#ifdef debug
Console.println("send timeout");
#endif
b++;
Send.close();
errore();
return;
}
risp.trim();
#ifdef debug
Console.println (risp);
#endif
if (risp == "dati inseriti") {
digitalWrite(status_led, OFF);
}
#ifdef debug
Console.println ("end send");
#endif
}
}
PHP Code:
<?php
include("configurazione.php");
if(@$_REQUEST['temperatura']!="" and @$_REQUEST['setpoint']!="0")
{
$data=mysql_real_escape_string($_REQUEST['data']);
$ora=mysql_real_escape_string($_REQUEST['ora']);
$temperatura=mysql_real_escape_string($_REQUEST['temperatura']);
$umidita=mysql_real_escape_string($_REQUEST['umidita']);
$stato=mysql_real_escape_string($_REQUEST['stato']);
$setpoint=mysql_real_escape_string($_REQUEST['setpoint']);
if ( $stato == "Acceso")
{
$acceso = $setpoint;
}
else
{
$acceso = 0;
}
mysql_query("INSERT INTO `temperatura`(`ID`, `date`,`time`, `temperatura`, `umidita`,`Stato`, `Setpoint`, `acceso` ) VALUES (\"\",'$data', '$ora',$temperatura,$umidita,'$stato',$setpoint,$acceso);");
// mysql_query("INSERT INTO `temperatura`(`ID`, `time`, `temperatura`, `umidita`) VALUES (\"\", now() , $temperatura,$umidita);");
echo "dati inseriti";
}
else
{
echo "errore";
echo $tempo;
echo $temperatura;
echo $umidita;
die();
}
?>
Regards,
Davide.
Thanks!! i need a solution in the linux side (python script or other solution).
criminalkaoz:
Thanks!! i need a solution in the linux side (python script or other solution).
@criminalkaoz,
the solution offered by chetto983 is php. It does not need a webserver. But if you want just Linux side, there are solution that people have documented.
google: arduino yun curl python
Good Articles:
Of course, you can use python, lua, ash (shell), and CURL
Is this enough? Or are you looking for more?
Jesse
This solution is ok (the php code is in the web server side to save the data in the database), but the "arduino code" to send the data is too long for a big proyect and i need a linux side solution (script in python or other that only send the data to the web server).
void send_temperatura() {
if (togglesensore == true) {
#ifdef debug
Console.println ("start Send");
#endif
digitalWrite(status_led, ON);
String datadb = nowdata();
String timedb = nowtime();
Send.begin("curl"); // Process that launch the "curl" command
String Sitourl = sito + "/inserisci.php?data=" + datadb +"&ora="+ timedb + "&temperatura=" + settemp + "&umidita=" + setumid + "&stato=" + stato + "&setpoint=" + settemperatura / 100 ;
Send.addParameter("--connect-timeout");
Send.addParameter("10");
Send.addParameter("-m");
Send.addParameter("60");
Send.addParameter( Sitourl ); // Add the URL parameter to "curl"
#ifdef debug
Console.println (Sitourl);
#endif
Send.run();// Run the process and wait for its termination
String risp = "";
#ifdef debug
Console.println ("send run");
Console.println(Send.exitValue());
#endif
if (Send.exitValue() == 0 && Send.available() > 0) {
risp = Send.readString();
Send.close();
b = 0 ;
}
else
{
#ifdef debug
Console.println("send timeout");
#endif
b++;
Send.close();
errore();
return;
}
risp.trim();
#ifdef debug
Console.println (risp);
#endif
if (risp == "dati inseriti") {
digitalWrite(status_led, OFF);
}
#ifdef debug
Console.println ("end send");
#endif
}
}
Someone has a pyton "curl" example code to send the local mysql data to webserver? Thanksss!!!
criminalkaoz:
Someone has a pyton "curl" example code to send the local mysql data to webserver? Thanksss!!!
criminalkaoz,
you can send data direct to server with Bridge Library using HttpClient Class.
Please give more details on server that receives data. Did you make? Do you need to make? Is 3rd part server?
What is data like? Do you need to use HTTP Post?
TIA
Jesse