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