Ir al contenido principal









codigo arduino ide para nodemcu con dht11

/*  ----------------------------------------------------------------
    www.prometec.net

    Leyendo la temperatura y humedad con un sensor DHT11
    y subir los valores a un sercidor mediante WiFi con el esp8266.
  --------------------------------------------------------------------
*/

#include
#include

DHT11 dht11(D4);

const char* ssid     = "xxxxxxxxx";
const char* password = "xxxxxxxxxxxx";

const char* host = "xxxxxxxxx.ddns.net";

void setup()
{
  Serial.begin(9600);
  // We start by connecting to a WiFi network

  Serial.println();
  Serial.println();
  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());
}

void loop()
{
  int err;
  float temperatura, humedad;
  if ((err = dht11.read(humedad, temperatura)) == 0)
  {
    Serial.print("Temperatura: ");
    Serial.print(temperatura);
    Serial.print(" Humedad: ");
    Serial.print(humedad);
    Serial.println();
  }
  else
  {
    Serial.println();
    Serial.print("Error Num :");
    Serial.print(err);
    Serial.println();
  }


  Serial.print("connecting to ");
  Serial.println(host);

  // Use WiFiClient class to create TCP connections
  WiFiClient client;
  const int httpPort = 80;
  if (!client.connect(host, httpPort)) {
    Serial.println("connection failed");
    return;
  }

  // We now create a URL for the request
  String url = "/enviardatos.php";
  String key = "?pass=";
  String dato1 = "&Temperatura=";
  String dato2 = "&Humedad=";

  Serial.print("Requesting URL: ");
  Serial.println(url);

  // This will send the request to the server
  client.print(String("GET ") + url + key + dato1 + temperatura + dato2 + humedad + " HTTP/1.1\r\n" +
               "Host: " + host + "\r\n" +
               "Connection: close\r\n\r\n");
  unsigned long timeout = millis();
  while (client.available() == 0) {
    if (millis() - timeout > 5000) {
      Serial.println(">>> Client Timeout !");
      client.stop();
      return;
    }
  }

  // Read all the lines of the reply from server and print them to Serial
  while (client.available()) {
    String line = client.readStringUntil('\r');
    Serial.print(line);
  }

  Serial.println();
  Serial.println("closing connection");

  delay(60000);
}

Comentarios

Entradas populares de este blog

Shield L293D

Algún que otro problema a la hora de conectarlo...

He conectado los 5v para el arduino y los 9v para el shield L293D el modulo bluetooth no esta encendido ¿? *** SOLUCIONADO, tenia el HC-05 a 9600 en el codigo y estaba configurado a 38400.  Estas son las conexiones realizadas; Pin 2 - el Echo del sensor ultrasonico HC-SR04 Pin 13 - Trig del sensor ultrasonico HC-SR04 Cable Blanco positivo del sensor HC-SR04 Cable Gris negativo del sensor HC-SR04 He realizado unas soldaduras en el Shield L293D, Pin 0 y Pin 1 para el modulo Bluetooth He realizado dos soldaduras para poder conectar el modulo de bluetooth al shield L293D. Positivo y negativo del modulo.