Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
update 1e48cc9 Nov 20, 2018
1 contributor

Users who have contributed to this file

80 lines (64 sloc) 1.84 KB
#include <ESP8266WiFi.h>
#include "Timer.h"
#define NUM_ARDUINO X //Sustituir X por el numero de Arduino correcto
const char* ssid = "ssid";
const char* password = "password";
char url[] = "www.aprendiendoarduino.com";
WiFiClient client;
Timer t;
String webString = "";
void setup()
{
Serial.begin(9600);
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
Serial.println("Iniciando datalogger...");
delay(1000);
t.every(5000, grabaDatos);
}
void loop()
{
webString = "";
t.update();
if (client.available()) {
Serial.println("Respuesta del Servidor---->");
while (client.available()) {
char c = client.read();
webString += c;
}
Serial.println(webString);
if (webString.indexOf("GRABADOS") > 0) Serial.println("Datos guardados correctamente");
else Serial.println("Error al guardar los datos");
client.stop();
}
}
void grabaDatos() {
Serial.println("leyendo temperatura... ");
int sensorVal = analogRead(A0);
float voltage = (sensorVal / 1024.0) * 5.0;
float temperature = (voltage - 0.5) * 100; //Sonda temperatura kit Arduino
Serial.print("Temperatura Leida: ");
Serial.println(temperature);
Serial.println("connecting to server...");
if (client.connect(url, 80)) {
Serial.println("connected");
client.print("GET /servicios/datos/grabaDatos.php?arduino=" + (String)NUM_ARDUINO + "&dato=");
client.print(temperature);
client.println(" HTTP/1.1");
client.println("Host: www.aprendiendoarduino.com");
client.println("Connection: close");
client.println();
}
else {
Serial.println("connection failed");
}
}
You can’t perform that action at this time.