Garage Monitor project

Okay, so I have been working on this project for a long time and have hit a road block that I just cannot get past. I am hoping someone will have a solution for me here. This is my first time posting, so I will try to be complete and informative.
My project is to create a garage door opener, temperature monitor and furnace controller using the Blynk application as an interface. I have a local Blynk server setup and running on a Windows laptop.
I am using a NodeMCU (ESP8266) over Wifi and the app is used in Android based mobile phone.

Phase 1 - Create a Local Blynk server with auto-connection to wifi. COMPLETE
Phase 2 - Create a button widget to activate a relay and open the door. COMPLETE
Phase 3 - Create a text widget to indicate the the door is OPEN or CLOSED. I can get this to indicate LOW or HIGH only.
Phase 4 - Create a Temperature and Humidity widget to display in the app.
Phase 5 - Add a Slider to adjust the temperature to control the furnace.

You will notice that I have some bits of code included for future phases of this project, but the only thing that is currently working is the door opener relay.

Here is the code below that I have so far. Please help me diagnose phase 3 and 4 to start with. I think this should be rather simple, but I have been stuck on this for a long time without any results.

Thank you very much for any assistance you can offer, as I am losing all my hair over this project.

‘’’
//-------------- Configuration for WiFi network setup (OnDemandConfig) -------------------

// Reference filename " " for wiring schematic
// Code Revision date 11/22/18

//-------------------------Needed for LIBRARY SETUP --------------------------------------
#include <ESP8266WiFi.h>          //https://github.com/esp8266/Arduino
#include <ESP8266WebServer.h>
#include <DNSServer.h>
#include <WiFiManager.h>          //https://github.com/tzapu/WiFiManager
#include <SPI.h>

#define TRIGGER_PIN 0 //(GPIO 0 = D3, GPIO 2 = D4)

//----------------------------- BLYNK SETUP ------------------------------
#include <WiFiClient.h>
#include <BlynkSimpleEsp8266.h>
#include <Ethernet.h>
#include <SimpleTimer.h>
#include <DHT.h>

#define BLYNK_PRINT Serial
#define DHTPIN 2 //pin gpio13(D7) in sensor
#define DHTTYPE DHT22   // DHT 22 Change this if you have a DHT11

DHT dht(DHTPIN, DHTTYPE);
ESP8266WebServer server(8080);
SimpleTimer timer;

char auth[] = "83d1a698426e48c4a1b9531f1bdd03b3";  // Put your Auth Token here WiFi

/****************************************************/
//                  SENDIT
/****************************************************/
void sendIt()
{
  // You can send any value at any time.
  // Please don't send more than 1 value per second.
  // Read the Temp and Humidity from DHT
  
Serial.println("Running TEMP measurement check");
float hum = dht.readHumidity();
float tempC = dht.readTemperature();
  if (isnan(hum) || isnan(tempC)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

float tempReadingVAL = tempC*9/5+32;  // what is the temperature in degC
float currentTemp = digitalRead(tempReadingVAL);
Blynk.virtualWrite(V10, tempC); // virtual pin 10
BLYNK_WRITE(currentTemp);
Blynk.virtualWrite(V11, hum); // virtual pin 11

const int Heat = 16;  // D0 pin.  Cold warning LED
pinMode(Heat, OUTPUT);  // Cold temp warning, call for heat
int setTempSlider(V3);  //desired temperature setting for heat to come ON
Blynk.virtualWrite(V3, setTempSlider);
int furnaceDisp(V4);  //Furnace status indicator IDLE or RUNNING

Serial.print(tempReadingVAL);
Serial.print(currentTemp);
Serial.print(Heat);
WidgetLED Door1(V1);  // Blynk virtual pin 1
WidgetLED vHeat(V2);  // Blynk virtual pin 2

// Setup a function to be called every 2 seconds
timer.setInterval(2000L, sendIt);


/****************************************************/
//                  DOOR STATUS
/****************************************************/
//Serial.println("Running DOOR STATUS check 1");

int door1InputVAL;
const int door1Input = 4;  // D2 status pin. Door Open or Closed
pinMode(door1Input, INPUT);  // Is door1 open or closed

door1InputVAL = digitalRead(door1Input);
  if (door1InputVAL == HIGH)
  {
    Door1.off();  // Blynk virtual LED only
    Blynk.virtualWrite(V1, "Door is CLOSED");
  }
    else {
      Door1.on();  // Blynk virtual LED only
      Blynk.virtualWrite(V1, "Door1 is OPEN");
         }

//Serial.println("The door is currently " + (door1InputVAL));
//Serial.println("Running DOOR STATUS check 2");

/****************************************************/
//                  THERMOSTAT
/****************************************************/
//Serial.println("Running temperature setting status check 1");

BLYNK_WRITE(setTempSlider); //adjust for desired set temp
BLYNK_WRITE(tempReadingVAL); //added this line for testing
BLYNK_WRITE(currentTemp);  //removed this line for testing


tempReadingVAL = digitalRead(currentTemp);
  if ((tempReadingVAL) < (setTempSlider))
  {
  digitalWrite(Heat, HIGH); //Physical LED/furnace goes ON when temp drops below "setTempSlider"
  vHeat.on();
  Blynk.virtualWrite(furnaceDisp, "Furnace RUNNING");
  }
    else
        {
    digitalWrite(Heat, LOW);   //Physical LED goes OFF when temp is above "setTempSlider"
    vHeat.off();
    Blynk.virtualWrite(furnaceDisp, "Furnace IDLE");
        }

//Serial.println("Finished running UPTIME sequence ++++++++++++++++");
//Serial.println("Running temperature status check 2");
//Serial.println("Start Loop sequence");

}

/***************************************************/
//            WIFI AUTO-CONFIGURE CONNECTION SETUP
/***************************************************/
void setup()
{
// put your setup code here, to run once:
  Serial.begin(115200);
  //Serial.println("\n Starting");
pinMode(2, INPUT);
  pinMode(TRIGGER_PIN, INPUT);

WiFiManager wifiManager;

//first parameter is name of access point, second is the password
wifiManager.autoConnect("MyGarage", "");

Blynk.begin(auth, "", "", IPAddress(192,168,1,12), 8080);     //insert here your SSID and password
dht.begin();

  // is configuration portal requested?
  if ( digitalRead(TRIGGER_PIN) == LOW ) {
    //WiFiManager
    //Local intialization. Once its business is done, there is no need to keep it around
    //WiFiManager wifiManager;

    //reset settings - for testing
    //wifiManager.resetSettings();

    //sets timeout until configuration portal gets turned off
    //useful to make it all retry or go to sleep in seconds
    wifiManager.setTimeout(180);

    //it starts an access point with the specified name here  "MyGarage"
    //and goes into a blocking loop awaiting configuration

    //WITHOUT THIS, THE AP DOES NOT SEEM TO WORK PROPERLY WITH SDK 1.5 , update to at least 1.5.1
    WiFi.mode(WIFI_STA);
    
  if (!wifiManager.startConfigPortal("MyGarage")) {
      //Serial.println("failed to connect and hit timeout");
      delay(3000);
      //reset and try again, or maybe put it to deep sleep
      ESP.reset();
      delay(5000);
    }}
    
    Serial.println("Connected...yeey :)");
    Serial.println("Finished running SETUP sequence +++++++++++++++++");

}
/****************************************************/
//                     LOOP SEQUENCE
/****************************************************/
void loop()
{
//Serial.println("Running Loop sequence ++++++++++++++++++++");
  Blynk.run();
  timer.run();
}

It’s to clear from your information what widgets you have set-up in your app and what virtual pins they’re assigned to, but there seems to be an unissued here…

You appear to be treating pin V1 as both an LED and a text display (presumably a labelled value widget). It can’t be both, so presumably you’ve got your virtual pins in a muddle.

These three lines of close make no sense.
The BLYNK_WRITE(virtual pin) function should be just that - a FUNCTION. It needs opening and closing curly brackets and some code enclosed with in these brackets.
The BLYNK_WRITE function is automatically triggered by the Blynk magic when the value of the corresponding virtual pin changes in the app. So, if you have a slider attached to V20 and a function that says:

BLYNK_ WRITE(V20)
{
  // do this stuff when the slider value changes
}

then the code within the curly brackets will be executed whenever your slider value changes.
The param.asInt() command can be used to retrieve the value from the widget and assign it to an integer variable type. param.asFloat() does the same thing, but (as you’ve probably guessed) returns a float value instead…

BLYNK_ WRITE(V20)
{
  TargetTemperature = param.asInt();
  // do some other stuff if needed....
}

This would read the value from the slider attached to V20 and return the result to the global variable (that you will have defines outside of this function) called TargetTemperature.

I realise that this doesn’t answer your Phase 4 question and skips straight to Phase 5, but hopefully you’ll see how the current structure of your code isn’t working, but with a few tweaks you’ll be able to achieve your remaining goals.

Pete.

Pete,
Thank you very much for your assistance, however, I still am not able to get any result from the Door position.
To keep things simple to start with, I wish to have the application state the door is either “OPEN” or “CLOSED”. I am not able to get anything to display to the value widget.
I cleaned up the sketch a little for ease of debugging one section at a time. I think I understand what you are trying to tell me, but still no luck.

  1. Need door position result in text form for value widget.
  2. Need temp reading in gauge widget.

Below is the relevant section of code.

void sendIt()
{
  // You can send any value at any time.
  // Please don't send more than 1 value per second.
  // Read the Temp and Humidity from DHT
  
//Serial.println("Running TEMP measurement check");
float hum = dht.readHumidity();
float tempC = dht.readTemperature();
  if (isnan(hum) || isnan(tempC)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

float tempReadingVAL = tempC*9/5+32;  // what is the temperature in degC
float currentTemp = digitalRead(tempReadingVAL);
Blynk.virtualWrite(V10, currentTemp); // virtual pin 10
Blynk.virtualWrite(V11, hum); // virtual pin 11

const int Heat = 16;  // D0 pin.  Cold warning LED
pinMode(Heat, OUTPUT);  // Cold temp warning, call for heat

int setTempSlider(V3);  //desired temperature setting for heat to come ON
Blynk.virtualWrite(V3, setTempSlider);
int furnaceDisp(V4);  //Furnace status indicator IDLE or RUNNING

WidgetLED vHeat(V21);  // Blynk virtual pin 21

// Setup a function to be called every 2 seconds
timer.setInterval(2000L, sendIt);

/****************************************************/
//                  DOOR STATUS
/****************************************************/

int door1InputVAL;
const int door1Input = 4;  // D2 status pin. Door Open or Closed
pinMode(door1Input, INPUT);  // Is door1 open or closed

door1InputVAL = digitalRead(door1Input);
  if (door1InputVAL == HIGH)
  {
      //Door1.off();  // Blynk virtual LED only
      Blynk.virtualWrite(V20, "Door is CLOSED");
  }
    else {
      //Door1.on();  // Blynk virtual LED only
      Blynk.virtualWrite(V20, "Door1 is OPEN");
          }

/****************************************************/
//                  THERMOSTAT
/****************************************************/

tempReadingVAL = digitalRead(currentTemp);
  if ((tempReadingVAL) < (setTempSlider))
  {
  digitalWrite(Heat, HIGH); //Physical LED/furnace goes ON when temp drops below "setTempSlider"
  vHeat.on();
  Blynk.virtualWrite(furnaceDisp, "Furnace RUNNING");
  }
    else
        {
    digitalWrite(Heat, LOW);   //Physical LED goes OFF when temp is above "setTempSlider"
    vHeat.off();
    Blynk.virtualWrite(furnaceDisp, "Furnace IDLE");
        }

}

/****************************************************/
//                     LOOP SEQUENCE
/****************************************************/
void loop()
{
  Blynk.run();
  timer.run();
}

These should be in the void setup()

This typically would be at the top of your code near your global variable declarations, not inside a function.

Also it is always better to post the complete code instead of just portions of it.

Also, your wifi config on button press is a bit off. You should take a look at the wifimanager example. as you will note the detection of the button press should not be in the void setup(). Also, to be blynk compatible it should not go in the void loop(). It needs to go into its own timer routine that is initiated in the void setup() like the other timers.

I think you should read up a bit on simpletimer as well. As this is what the blynktimer is based off of.
https://playground.arduino.cc/Code/SimpleTimer

Thank you both so much for your help. Your feedback has helped me understand a bit more.
I will go through all of this code tonight and hopefully get most of it working. I will also review the SimpleTimer process.
I will post my complete sketch later if I need additional coaching.
Thanks again!!!
Shawn