PROBLEM: Mysql + arduino + dth11
Hi
I have a big problem with passing data captured by the DTH11 (temperature) sensor to mysql
when it connects the arduino board it is all normal, it says: Connected but in the database there is no data. please if you could guide me with this. Thanks a lot
ARDUINO.ino
#include <dht.h>
#include <Ethernet.h>
#include <SPI.h>
// INTERNET EN LA TARJETA DE RED
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress server (192, 168, 1, 4);
IPAddress subnet (255, 255, 255, 0);
IPAddress gateway (0, 0, 0, 0);
IPAddress ip (192, 168 , 1, 30);
EthernetClient client;
//#define dht_apin A0 // Analog Pin sensor is connected to
dht DHT;
float temperatura;
int analog_pin = A0;
//Configuracion de Arduino
void setup() {
Serial.begin(9600);
while (!Serial)
{
;
}
//Inicializa el dispositivo de Ethernet
Ethernet.begin(mac, ip);
delay(1000);
}
void loop() {
DHT.read11(analog_pin);
temperatura = DHT.temperature;
Serial.print(temperatura);
Serial.println(" °C");
Serial.println("Connecting...");
if (client.connect(server, 80)>0) {
Serial.println("Connected");
client.print(" GET /Ethernet.php?=temp=");
client.print(temperatura);
client.println(" HTTP/1.1");
client.println("Host: ");
client.println("Connection: close");
client.println();
Serial.println("Conectado");
} else {
Serial.println("Fallo en la conexion");
}
if (!client.connected()) {
Serial.println("Desconectado!");
client.stop();
}
}
ETHERNET.php
<?php
$temp = $GET["temp"];
$enlace = mysqli_connect('localhost','root','','conexion')
or die ('No se puede conectar: ' .mysql_error());
echo 'Conexion exitosa
';
echo 'Se ingresaron los datos
';
echo '
';
echo 'Dato: '.$temp;
echo '
';
$consulta = mysql_query($enlace, "INSERT INTO temperatura (temp) VALUES ($temp)");
if (!$consulta)
{
echo "Error al guardar
";
}
else
{
echo "Datos guardados
";
}
echo '
';
?>
thank you very much