ESP 01 DHT11 and the AskSensors Cloud

Arduino tutorial: This module uses the ESP-01 or the ESP-01S as the master control, and the DHT11 ... Humidity Monitoring Using the ESP-01 & DHT and the AskSensors Cloud.

 DHT22 Temperature Humidity Sensor

Code

/*
 * DHT Temperature and humidity monitoring using ESP01 and the askSensors 
 * Description: This examples connects the ESP to wifi, and sends Temperature and humidity to askSensors IoT platfom over HTTPS GET Request.
 * Author: https://asksensors.com, 2018 - 2019
 * github: https://github.com/asksensors
 * DHT11 library (DHT11) found at https://github.com/winlinvip/SimpleDHT
 * More videos : https://www.youtube.com/channel/UCCC8DuqicBtP3A_aC53HYDQ/videos
 */

// includes
#include "ESP8266WiFi.h"
#include "WiFiClientSecure.h"
#include "SimpleDHT.h"

// user config: TODO
const char* wifi_ssid = "***********";             // SSID
const char* wifi_password = "***********";         // WIFI
const char* apiKeyIn = "***********";      // API KEY IN
const unsigned int writeInterval = 25000; // write interval (in ms)

// ASKSENSORS config.
const char* https_host = "api.asksensors.com";         // ASKSENSORS host name
const int https_port = 443;                        // https port
const char* https_fingerprint =  "B5 C3 1B 2C 0D 5D 9B E5 D6 7C B6 EF 50 3A AD 3F 9F 1E 44 75";     // ASKSENSORS HTTPS SHA1 certificate
// DHT config.
int pinDHT11 = 2;
SimpleDHT11 dht11(pinDHT11);
// create ASKSENSORS client
WiFiClientSecure client;

void getTem()
{
  byte temperature = 0;
  byte humidity = 0;
  int err = SimpleDHTErrSuccess;
  if ((err = dht11.read(&temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {
    delay(100);
    return;
  }
  if (!client.connect(https_host, https_port)) {
  delay(200);
  return;
  }
  // Create a URL for the request
  String url = "/write/";
  url += apiKeyIn;
    url += "?module1=";
  url += ((int)temperature);
  url += "&module2=";
  url += ((int)humidity);
  

  client.print(String("GET ") + url + " HTTP/1.1\r\n" +
               "Host: " + https_host + "\r\n" +
               "Connection: close\r\n\r\n");

  client.connected();
}
void setup() {
  WiFi.begin(wifi_ssid, wifi_password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
  }
  // Set Client to insecure
  client.setInsecure();
}

void loop() {
         getTem();
  delay(10000);

}

No comments:

Post a Comment