Need help with code

Hello there i have written code to notify me when temp goes down using wemos and dht22.

the code does not want to compile for some reason. other code compile and upload fine. i have changed cables. please help




#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <DHT.h>

DHT dht(12, DHT22);


char auth[] = "";  // Put your Auth Token here. (see Step 3 above)
bool temperatureMoved = true; // means it moved below 20C

SimpleTimer timer;

void setup()
{
  Serial.begin(9600); // See the connection status in Serial Monitor
  Blynk.begin(auth, "", ""); //insert here your SSID and password
  pinMode(5, OUTPUT);

  // Setup a function to be called every second
  timer.setInterval(10000L, sendUptime);
}

void sendUptime()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  //Read the Temp and Humidity from DHT
  float h = dht.readHumidity();
  float t = dht.readTemperature();

  Blynk.virtualWrite(10, t); // virtual pin
  Blynk.virtualWrite(11, h); // virtual pin

  if ((t < 20) && (temperatureMoved == true)) {
    temperatureMoved = false;
    Blynk.notify(String("Frost im Gartenhaus : ") + t + String("°C"));
    digitalWrite(5, 1);
  }
  if ((t >= 20) && (temperatureMoved == false)) {
    temperatureMoved = true;
    digitalWrite(5, 0);
  }
}

void loop()
{
  Blynk.run();
  timer.run();
}

it gives error compiling for board wemos d1 r2 and mini.

how is this Blynk related?

the error relates to your DHT.h library… work on that aspect…

kindly let me know how did you figure out that problem i was struggling with it for few hours and since i didnt get anywhere i thought i post for help. what do i need to do with dht.h library?

it tells you in the error messages in the compiler.

i have no idea, sorry!

in the arduino i have it only tells me error compiling for board wemos d1 r2 and mini. exit status 1 and error compiling for board wemos d1 r2 and mini.

if you can point exactly where it would show me error is related to dht.h library i wont ask dumb question like this these in future…:slight_smile:

Can you paste the copy of the entire error here?

yay! real help has arrived, i am outa here, byes!

I have changed the code above to include this…still getting error compiling for board wemos d1 r2 and mini

#include <DHT.h>
#define DHTPIN 12 //pin gpio 12 in sensor
#define DHTTYPE DHT22   
DHT dht(DHTPIN, DHTTYPE);

loll…haha

1 Like

the way you exited and said byes it reminded me of jake peralta character from Brooklyn nine nine. love that show

how do i copy the entire error code? i only get the short version of error code.

Well, even the pasted short version would be better than a screenshot of text… I hate reading those :stuck_out_tongue_winking_eye: but thank you for the assist @Dave1829

In File -> Preferences you can checkmark Show verbose output during compilation

But… your posted code compiles just fine on my end, so I suspect you have a corrupt or missing DHT.h library

Build options changed, rebuilding all
In file included from C:\Users\Home\Documents\Arduino\libraries\DHT-sensor-library-master\DHT_U.cpp:22:0:

C:\Users\Home\Documents\Arduino\libraries\DHT-sensor-library-master\DHT_U.h:25:29: fatal error: Adafruit_Sensor.h: No such file or directory

 #include <Adafruit_Sensor.h>

                             ^

compilation terminated.

exit status 1
Error compiling for board WeMos D1 R2 & mini.

where can i download a good version of dht library ? i went through couple of options but still no luck

There is your issue… you need to add this library as well.

i was showing WHERE to find the errors, not what the error was…

Well based on your prior answer I thought you were doing both… but as I didn’t read all of your screenshot, and my mind reading widget is broke again… I was unsure :stuck_out_tongue_winking_eye: But I stand corrected :smiley:

ok so here is the updated code after i was able to compile and upload after getting help from Gunner and Dave1829. I have added a slider widget so i can set a range for input but it does not seem to work. may you good folks can have a quick look at it and let me know if it make sense!?

also i have added the code of arduino OTA…can you also have a look at it and let me know if there are ways i can streamline this code to make it more efficient.

#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#define BLYNK_PRINT Serial
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <Adafruit_Sensor.h>
#include <DHT.h>

#define DHTPIN 12 //D6 wemos pin for sensor
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);

const char* ssid = ""; //wifi name for OTA sketch
const char* password = ""; // wifi password for OTA sketch

char auth[] = ""; // hard auth code for blynk app

bool temperatureMoved = true; 
SimpleTimer timer;
int maxvalue = 0;


void setup() {
  Serial.begin(115200);
  Serial.println("Booting");
  WiFi.mode(WIFI_STA);
  
  timer.setInterval(1000L, sendUptime);

  WiFi.begin(ssid, password);
  Blynk.begin(auth, ssid, password); 
  while (WiFi.waitForConnectResult() != WL_CONNECTED) {
    Serial.println("Connection Failed! Rebooting...");
    delay(5000);
    ESP.restart();
  }

  ArduinoOTA.onStart([]() {
    String type;
    if (ArduinoOTA.getCommand() == U_FLASH)
      type = "sketch";
    else // U_SPIFFS
      type = "filesystem";

    // NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
    Serial.println("Start updating " + type);
  });
  ArduinoOTA.onEnd([]() {
    Serial.println("\nEnd");
  });
  ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
    Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
  });
  ArduinoOTA.onError([](ota_error_t error) {
    Serial.printf("Error[%u]: ", error);
    if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
    else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
    else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
    else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
    else if (error == OTA_END_ERROR) Serial.println("End Failed");
  });
  ArduinoOTA.begin();
  Serial.println("Ready");
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
}

BLYNK_WRITE(V0)   //for slider
{
   maxvalue == param.asInt();
}

void sendUptime()
{
  float t = dht.readTemperature();
  Blynk.virtualWrite(10, t); // virtual pin

  if ((t < maxvalue) && (temperatureMoved == true)) {
    temperatureMoved = false;
    Blynk.notify(String("Temperature Low ") + t + String("°C"));
    Blynk.email("XXXXX@gmail.com", "PIPE TEMP LOW", "Pipe Temperature LOW Warning");
      }
  if ((t >= maxvalue) && (temperatureMoved == false)) {
    temperatureMoved = true;
    Blynk.notify(String("Temperature is Normal ") + t + String("°C"));
      }
}


void loop() {
  ArduinoOTA.handle();
  Blynk.run();
  timer.run();
}