Hola gente, estoy tratando de mostrar los valores, que arroja el sensor de temperatura DTH22, en un sitio web que se encuentra en un hosting. El problema en si que estoy teniendo es que cuando mando los datos los datos desde el arduino al parecer no me están llegando al sitio web ya que estoy creando un archivo "data.txt" por medio de php para ver lo que esta llegando a la web y este mismo se crea sin informacion. Si alguien me puede dar una manito le agradecería. Dejo los códigos que estoy utilizando.
#include <DHT.h>
#include <Ethernet2.h>
#include <SPI.h>
byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x01 };
char servidor[] = "www.xxxxxxxxxx.com.ar";
IPAddress ip(192, 168, 0, 177);
EthernetClient client;
#define DHTPIN 7 // PIN DEL SENSOR
#define DHTTYPE DHT22 //
DHT dht(DHTPIN, DHTTYPE);
long previousMillis = 0;
unsigned long currentMillis = 0;
long interval = 250000;
int t = 0; // TEMPERATURE VARIABLE
int h = 0; // HUMIDITY VARIABLE
String data;
String temp;
void setup() {
Serial.begin(9600);
if (Ethernet.begin(mac) == 0) {
Serial.println("Error al configurar Ethernet utilizando DHCP");
}
dht.begin();
delay(10000);
h = (int) dht.readHumidity();
t = (int) dht.readTemperature();
data = "";
temp = "Temperatura=";
if (client.connect(servidor, 80)) {
Serial.println("CONECTADO");
// Make a HTTP request:
client.println("GET /index.php HTTP/1.1");
client.println("Host: www.xxxxxxxx.com.ar");
client.println("Connection: close");
client.println();
}
else {
// kf you didn't get a connection to the server:
Serial.println("CONEXION FALLÓ");
}
}
void loop(){
currentMillis = millis();
if(currentMillis - previousMillis > interval) {
previousMillis = currentMillis;
h = (int) dht.readHumidity();
t = (int) dht.readTemperature();
}
Serial.print("TEMPERATURA: ");
Serial.println(t);
data = temp + String(t) ;
Serial.println(data);
if (client.connect("www.xxxxxxxx.com.ar",80)) {
client.println("GET /index.php?data="+ data + "HTTP/1.1");
client.println("Host: www.xxxxxxxx.com.ar");
}
if (client.connected()) {
client.stop(); // DISCONNECT FROM THE SERVER
}
delay(3000); // WAIT FIVE MINUTES BEFORE SENDING AGAIN
}
Código PHP:
<?php $file = fopen("data.txt", "a") or die("Error");
if(isset($_GET["data"])) fwrite($file, $_GET["data"]); fclose($file); ?>
<?php
echo "Hola Mundo";
$Temperatura=$_GET["data"];
echo $Temperatura;
?>
Este ultimo codigo solo muestra en el navegador "Hola Mundo". No logro identificar que estoy omitiendo.