Hi Everyone,
This is my first post, so forgive me if I get anything wrong.
I am working on a scheduler for a thermostat project, and have run into a problem using Blynk.virtualWrite to write a time value back to the Time Input Widget on pins V16, V19, and V22. I am using the same the same code to write back to Value displays on pins V15, V18, and V21, and it works fine. I’ve looked at and tried everything I can find on the Internet, and for the life of me, I can’t seem to make it work. By the way, I did try the “Update Time Input State on UI” example sketch with the same board and UI, and it works fine - which is even more confusing!
I am using a nodeMCU board and iOS UI.
If anyone can shed some light on this it would be much appreciated. Thanks in advance!
Code
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
//#include <TimeLib.h>
//#include <WidgetRTC.h>
//#include "DHT.h"
char auth[] = "";
char ssid[] = "";
char pass[] = "";
//DHT dht1(D3, DHT22); //outdoor sensor
//DHT dht2(D4, DHT22); //indoor sensor (main)
//DHT dht3(D5, DHT22); //sleep sensor (sleep)
//BlynkTimer timer;
//WidgetRTC rtc;
// Widgit Setup
WidgetLED wifiLED(V0);
WidgetLED fanLED(V1);
WidgetLED coolLED(V2);
WidgetLED heatLED(V3);
//Variables
int schDayFlag; //1 = Monday...7 = Sunday
long schTimeAway [7]; //1 = Monday...7 = Sunday
long schTimeHome [7]; //1 = Monday...7 = Sunday
long schTimeSleep [7]; //1 = Monday...7 = Sunday
int schTempAway [7]; //1 = Monday...7 = Sunday
int schTempHome [7]; //1 = Monday...7 = Sunday
int schTempSleep [7]; //1 = Monday...7 = Sunday
//Functions
void SchRefreshFN();
BLYNK_WRITE(V14){ //Capture a day index flag
schDayFlag = (param.asInt()); //capture the index value for day selected in menu
SchRefreshFN(); //refresh schedule display on UI
}
BLYNK_WRITE(V16){ //Time Input Widget: Save new start time for Away Setting, refresh UI
schTimeAway[schDayFlag] = param[0].asLong();
SchRefreshFN();
}
BLYNK_WRITE(V19){ //Time Input Widget: Save new start time for Away Setting, refresh UI
schTimeHome[schDayFlag] = param[0].asLong();
SchRefreshFN();
}
BLYNK_WRITE(V22){ //Time Input Widget: Save new start time for Away Setting, refresh UI
schTimeSleep[schDayFlag] = param[0].asLong();
SchRefreshFN();
}
BLYNK_WRITE(V17){ //set temp for Away, refresh UI
switch (param.asInt())
case 1:{
schTempAway[schDayFlag]++;
SchRefreshFN();
break;
case -1:
schTempAway[schDayFlag]--;
SchRefreshFN();
break;
}
}
BLYNK_WRITE(V20){ //set temp for Home, refresh UI
switch (param.asInt())
case 1:{
schTempHome[schDayFlag]++;
SchRefreshFN();
break;
case -1:
schTempHome[schDayFlag]--;
SchRefreshFN();
break;
}
}
BLYNK_WRITE(V23){ //set temp for Sleep, refresh UI
switch (param.asInt())
case 1:{
schTempSleep[schDayFlag]++;
SchRefreshFN();
break;
case -1:
schTempSleep[schDayFlag]--;
SchRefreshFN();
break;
}
}
void SchRefreshFN(){ //, refresh UI
switch (schDayFlag)
case 1:{
Blynk.virtualWrite(V15, schTempAway[1]);
Blynk.virtualWrite(V18, schTempHome[1]);
Blynk.virtualWrite(V21, schTempSleep[1]);
Blynk.virtualWrite(V16, schTimeAway[1]);
Blynk.virtualWrite(V19, schTimeHome[1]);
Blynk.virtualWrite(V22, schTimeSleep[1]);
break;
case 2:
Blynk.virtualWrite(V15, schTempAway[2]);
Blynk.virtualWrite(V18, schTempHome[2]);
Blynk.virtualWrite(V21, schTempSleep[2]);
Blynk.virtualWrite(V16, schTimeAway[2]);
Blynk.virtualWrite(V19, schTimeHome[2]);
Blynk.virtualWrite(V22, schTimeSleep[2]);
break;
case 3:
Blynk.virtualWrite(V15, schTempAway[3]);
Blynk.virtualWrite(V18, schTempHome[3]);
Blynk.virtualWrite(V21, schTempSleep[3]);
Blynk.virtualWrite(V16, schTimeAway[3]);
Blynk.virtualWrite(V19, schTimeHome[3]);
Blynk.virtualWrite(V22, schTimeSleep[3]);
break;
case 4:
Blynk.virtualWrite(V15, schTempAway[4]);
Blynk.virtualWrite(V18, schTempHome[4]);
Blynk.virtualWrite(V21, schTempSleep[4]);
Blynk.virtualWrite(V16, schTimeAway[4]);
Blynk.virtualWrite(V19, schTimeHome[4]);
Blynk.virtualWrite(V22, schTimeSleep[4]);
break;
case 5:
Blynk.virtualWrite(V15, schTempAway[5]);
Blynk.virtualWrite(V18, schTempHome[5]);
Blynk.virtualWrite(V21, schTempSleep[5]);
Blynk.virtualWrite(V16, schTimeAway[5]);
Blynk.virtualWrite(V19, schTimeHome[5]);
Blynk.virtualWrite(V22, schTimeSleep[5]);
break;
case 6:
Blynk.virtualWrite(V15, schTempAway[6]);
Blynk.virtualWrite(V18, schTempHome[6]);
Blynk.virtualWrite(V21, schTempSleep[6]);
Blynk.virtualWrite(V16, schTimeAway[6]);
Blynk.virtualWrite(V19, schTimeHome[6]);
Blynk.virtualWrite(V22, schTimeSleep[6]);
break;
case 7:
Blynk.virtualWrite(V15, schTempAway[7]);
Blynk.virtualWrite(V18, schTempHome[7]);
Blynk.virtualWrite(V21, schTempSleep[7]);
Blynk.virtualWrite(V16, schTimeAway[7]);
Blynk.virtualWrite(V19, schTimeHome[7]);
Blynk.virtualWrite(V22, schTimeSleep[7]);
break;
}
}
void setup() {
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
while (Blynk.connect() == false) {}// wait for Blynk to connect
//rtc.begin();
Blynk.virtualWrite(V24,"Away Temperature");
Blynk.virtualWrite(V25,"Home Temperature");
Blynk.virtualWrite(V26,"Sleep Temperature");
}
void loop() {
Blynk.run();
}