OK Costas and many thanks for your time and effort to test it.
The bool V31Timer = false : was a mistake during the transfer… ; is in the sketch of course .
I will try to isolate what is so wrong…
Thanks again!
OK Costas and many thanks for your time and effort to test it.
The bool V31Timer = false : was a mistake during the transfer… ; is in the sketch of course .
I will try to isolate what is so wrong…
Thanks again!
What exactly is happening or not happening at your end?
For reference I modified your V21 as shown below to check the sketch (might be worth you trying this) :
BLYNK_WRITE(V21)
{
Serial.println("Running V21");
TimeInputParam t(param);
int dayadjustment = -1;
if(weekday() == 1){
dayadjustment = 6; // needed for Sunday, Time library is day 1 and Blynk is day 7
}
for (int i = 1; i <= 7; i++) { // Process weekdays (1. Mon, 2. Tue, 3. Wed, ...)
if (t.isWeekdaySelected(i)) {
Serial.println(String("Day ") + i + " is selected");
}
}
Serial.print("Time library adjusted day number is ");
Serial.println(weekday() + dayadjustment);
if(t.isWeekdaySelected((weekday() + dayadjustment))){ //Time library starts week on Sunday, Blynk on Monday
now1seconds = ((hour() * 3600) + (minute() * 60) + second());
Serial.print("Time now in seconds is ");
Serial.println(now1seconds);
start1secondswd = (t.getStartHour() * 3600) + (t.getStartMinute() * 60);
if(now1seconds >= start1secondswd){
if(now1seconds <= start1secondswd + 40 ){
if(V31Timer == true){ /// V31 Virtual switch widget to select RL1 or RL2 for Timer 1 V31 /// /// RL1 activation ///
digitalWrite(12,HIGH);
Blynk.virtualWrite(V16, (digitalRead(12)));
Serial.println("GP12 HIGH");
digitalWrite(TestLED, LOW); // LED ON
} else { /// V31 Virtual switch widget to select RL1 or RL2 for Timer 1 V31 /// /// RL2 activation ///
digitalWrite(13,HIGH);
Blynk.virtualWrite(V17, (digitalRead(13)));
Serial.println("GP13 HIGH");
digitalWrite(TestLED, LOW); // LED ON
}
}
}
stop1secondswd = (t.getStopHour() * 3600) + (t.getStopMinute() * 60);
if(now1seconds >= stop1secondswd){
if(now1seconds <= stop1secondswd + 40){ // 40s on 20s timer ensures 1 trigger command is sent
if(V31Timer == true){ /// RL1 de-activation ///
digitalWrite(12,LOW);
Blynk.virtualWrite(V16, (digitalRead(12)));
Serial.println("GP12 LOW");
digitalWrite(TestLED, HIGH); // LED OFF
} else { /// RL2 de-activation ///
digitalWrite(13,LOW);
Blynk.virtualWrite(V17, (digitalRead(13)));
Serial.println("GP13 LOW");
digitalWrite(TestLED, HIGH); // LED OFF
}
}
}
}
}
/// END of Timer1 function for V21 ///
Costas, as you have seen in my code there are not “printings” so I have not a clear indication what is wrong…
My project is using timers and virtual switches in order to activate , de-activate two relays.
Till yesterday was working fine with the exception of Sunday a bug that corrected from you (anyway the related code is coming from you ).
Starting from yesterday evening, the Relays are not activated from timers at all. nothing nada!
If you wish, I can send you all my sketch and Blynk sharing, just ask me and I will do it.
I will have time to test your routine with debugging code ( I will change it to terminal.print … because I have not easy access to hardware ). today very late or tomorrow…
Thanks.
Send the sketch and the Blynk Clone (not share) and I will take a look.
Actually regular relays are one of the things I don’t have. I have lots of RF controlled relays though but they are not really required to debug your sketch.
Well the sketch is:
///#define Blynk_DEBUG /// for debugging it slow down the system a lot ///
///#define Blynk_PRINT Serial /// it is used bellow in the blynk section ///
/// Blynk Project ELIAS Automation
#define Version "r1.8"
#define Author "Mike Kranidis"
#define WellcomeLine2 "Ver. rel. 1.8"
#define Project "2 Relays automation & OTA NTP/RTC cmd's"
/// 1st release 25/09/2016 ///
/// NEW version: associated with: Client Name: ESP_C602E2 / MAC Address: 5C:CF:7F:C6:02:E2 ///
/// SSID = BIKY PASSWORD = F15AF77245
/// WeMos ESP-12E/F matching ///
/// D0 <==> GPIO16 /// 10k Pull-up, WeMos BUILTIN_LED on board LED
/// D1 <==> GPIO05 /// ( SCL )
/// D2 <==> GPIO04 /// ( SDA )
/// D3 <==> GPIO00 /// ( 10k Pull-up )
/// D4 <==> GPIO02 /// ( ??? build in LED for ESP-12F ???)
/// D5 <==> GPIO14 /// ( SCK )
/// D6 <==> GPIO12 /// ( MISO ) Relay1
/// D7 <==> GPIO13 /// ( MOSI ) Relay2
/// D8 <==> GPIO15 /// ( 10k Pull-down )
/// All IO have interrupt/pwm/I2C/one-wire supported(except D0)
/// Blynk related setup ///
/// Blynk color definition
/// http://www.rapidtables.com/web/color/RGB_Color.htm ///
#define GREEN "#23C48E"
#define BLUE "#04C0F8"
#define YELLOW "#ED9D00"
#define RED "#D3435C"
#define DARK_BLUE "#5F7CD8"
#define BLACK "#000000"
#define WHITE "#FFFFFF"
/// V1 RUN? LED widget flashing once per second to give the running impression on V1 ///
/// V4 S/W version button on V4 and blynk version on V14 WidgetTerminal ///
/// V5 PIN_UPTIME UPTIME on Value Display widget on V5 ///
/// V7 widget, (switch to ADVANCED mode), on V7 ///
/// 16 SW1-LED1 (of Board) switch on 16 ///
/// * Value Display widget on V12 currentTime ///
/// * Value Display widget on V13 currentDate ///
/// WidgetTerminal terminal(V14) ///
/// Not Used Yet V15 switch to activate ArduinoOTA.handle() on demand ///
/// Relay 1: gp12 <--> virtual switch V16, Relay 2: gp13 <--> virtual switch V17 ///
/// V20 virtual switch to print timer1 time settings on demand V20 ///
///////////////////////////////////////
/// Timer1 & Timer2 controls Relay1 ///
/// V21 Timer1 TimeInput widget V21 ///
/// V22 Timer2 TimeInput widget V22 ///
///////////////////////////////////////
/// Timer3 & Timer4 controls Relay2 ///
/// V23 Timer3 TimeInput widget V23 ///
/// V24 Timer4 TimeInput widget V24 ///
///////////////////////////////////////
/// V31 Virtual switch widget to select RL1 or RL2 for Timer 1 V31 ///
/// V32 Virtual switch widget to select RL1 or RL2 for Timer 2 V32 ///
/// V33 Virtual switch widget to select RL1 or RL2 for Timer 3 V33 ///
/// V34 Virtual switch widget to select RL1 or RL2 for Timer 4 V34 ///
#include <ESP8266WiFi.h>
/// OTA dependencies ///
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
/// WiFiManager dependencies ///
#include <DNSServer.h> //Local DNS Server used for redirecting all requests to the configuration portal
#include <ESP8266WebServer.h> //Local WebServer used to serve the configuration portal
#include <WiFiManager.h> //https://github.com/tzapu/WiFiManager WiFi Configuration Magic
/// blynk dependencies ///
/// #define BLYNK_PRINT Serial // Comment this out to disable prints and save space
/// it is used above /// #include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
/// NTP dependencies and declarations///
#include <TimeLib.h>
/// it is used above /// #include <ESP8266WiFi.h>
/// it is used above /// #include <WiFiUdp.h>
// NTP Servers:
static const char ntpServerName[] = "gr.pool.ntp.org";
const int timeZone = 3; /// Greek European Time
WiFiUDP Udp;
unsigned int localPort = 8888; // local port to listen for UDP packets
time_t getNtpTime();
// Use Virtual pin 5 for uptime display
#define PIN_UPTIME V5
/// global vartiable for looping counting ///
int loopCount = 0; /// print after 2 interation this message Type ? or help to get help...
int loopCount1 = 0; /// Send date to the App after 10 times of time ///
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "XXXX";
boolean ledBlink = true;
bool debugPrint = false;
/// decration variables for Timer1 - Timer4 ///
char Date1[12], Date2[12], Date3[12], Date4[12];
char Time1[10], Time2[10], Time3[10], Time4[10];
long start1secondswd, start2secondswd, start3secondswd, start4secondswd; // weekday start time in seconds
long stop1secondswd, stop2secondswd, stop3secondswd, stop4secondswd; // weekday stop time in seconds
long now1seconds, now2seconds, now3seconds, now4seconds; // time now in seconds
/// RL1 or RL2 for Timer 1,2,3,4 selection for Virtual Switches V31, V32, V33, V34 ///
/// V31Timer if false => RL1, true => RL2 ... ///
bool V31Timer = false, V32Timer = false, V33Timer = false, V34Timer = false;
/// digitalRead12 & digitalRead13 holding the previous state of the hardware pins gp 12 & gp 13 that is the relay1 & relay2 driving pins ///
int digitalRead12=0, digitalRead13=0;
WidgetLED led1(V1);
WidgetLCD lcd(V7);
SimpleTimer timer;
/// start of WiFiManager Global Start here... ////
WiFiManager wifiManager;
// Attach virtual serial terminal to Virtual Pin V14
WidgetTerminal terminal(V14);
/// This temp./humd. report function be called every 30 seconds ///
void sendTemperatureHumidity()
{
/// Read the Temp and Humidity from DHT
/// float h = dht.readHumidity();
/// float t = dht.readTemperature();
/// Generate random temperature value 12.0 to 35.0 (for example)
float t = float(random(120, 350))/10;
float h = float(random(200, 600))/10;
String strV6 = String(t, 1);
String strT = String(t, 1) + "°C";
String strH = String(h, 1) + "%";
String strV9 = String(h, 1);
// Send it to the server
/// Blynk.virtualWrite(V6, strV6);
/// Blynk.virtualWrite(V9, strV9);
lcd.clear(); //Use it to clear the LCD Widget
lcd.print(0, 0, "The temp/hum are");
lcd.print(1, 1, strT); // use: (position X: 0-15, position Y: 0-1, "Message you want to print")
lcd.print(9, 1, strH); // use: (position X: 0-15, position Y: 0-1, "Message you want to print")
if(loopCount <= 2){
loopCount++;
} else {
loopCount = 0;
terminal.println("Type ? or help to get help...");
terminal.println();
terminal.flush();
}
}
/// This blink LED function be called every second by SimpleTimer ///
void blinkLedWidget()
{
if (led1.getValue()) {
led1.off();
///BLYNK_LOG("LED1: off");
} else {
if(WiFi.RSSI() < -83){
Blynk.setProperty(V1, "color", RED);
}
else if(WiFi.RSSI() > -57){
Blynk.setProperty(V1, "color", GREEN);
}
else{
Blynk.setProperty(V1, "color", YELLOW);
}
led1.on();
///BLYNK_LOG("LED1: on");
}
/// put the routine here to blink HARDWARE LED gp 16 each second ///
if (ledBlink) {
digitalWrite(16, !(digitalRead(16)));
}
}
/// Digital clock display SimpleTimer timer function of the time updating every 2 seconds ///
void clockDisplay()
{
// You can call hour(), minute(), ... at any time
// Please see Time library examples for details
/// String currentTime = String(hour()) + ":" + minute() + ":" + second();
/// String currentDate = String(day()) + "/" + month() + "/" + year();
/// s for second, m for minute, h for hour, d for day, M for month ///
String s, m, h, d, M;
if (second() < 10) { s = "0" + String(second()); }
else { s = String(second()); }
if (minute() < 10) { m = "0" + String(minute()); }
else { m = String(minute()); }
if (hour() < 10) { h = "0" + String(hour()); }
else { h = String(hour()); }
if (day() < 10) { d = "0" + String(day()); }
else { d = String(day()); }
if (month() < 10) { M = "0" + String(month()); }
else { M = String(month()); }
String currentTime = String(h) + ":" + m + ":" + s;
String currentDate = String(d) + "/" + M + "/" + year();
// Send time to the App
Blynk.virtualWrite(V12, currentTime);
// Send date to the App after 10 times of time
if(loopCount1 <= 10) {
loopCount1++;
} else {
loopCount1=0;
Blynk.virtualWrite(V13, currentDate);
}
}
void sendNTPpacket(IPAddress &address);
/// SimpleTimer timer function, check each 500 mSec for the real status of Relay1 gp 12 and Relay2 gp 13 and report at the V16 & V17 with colors! ///
void statusCheck() {
if(digitalRead12 != digitalRead(12)) {
digitalRead12 = digitalRead(12);
if (digitalRead12 == HIGH)
{ Blynk.setProperty(V16, "color", RED);
}
else
{ Blynk.setProperty(V16, "color", GREEN);
}
}
if(digitalRead13 != digitalRead(13)) {
digitalRead13 = digitalRead(13);
if (digitalRead13 == HIGH)
{ Blynk.setProperty(V17, "color", RED);
}
else
{ Blynk.setProperty(V17, "color", GREEN);
}
}
}
/// simpletimer function, check every 10 seconds the blynk connection and if necessary do connect ///
void reconnectBlynk() {
if (!Blynk.connected()) {
if(Blynk.connect()) {
BLYNK_LOG("Reconnected...!");
} else {
BLYNK_LOG("Not reconnected###");
}
}
}
/// ===> START OF SETUP <=== ///
void setup() {
Serial.begin(115200);
Serial.println("Booting...");
/// on board LED ///
pinMode(16, OUTPUT);
digitalWrite(16, HIGH); /// initializing internal WeMos led to off (HIGH => OFF) ///
/// Relay 1 @ pin 12 ///
pinMode(12, OUTPUT);
/// Relay 2 @ pin 13 ///
pinMode(13, OUTPUT);
/// not needed because this can be handled by wifiManager ///
/// WiFi.mode(WIFI_STA);
/// WiFi.begin(ssid, password);
//WiFiManager
//Local intialization. Once its business is done, there is no need to keep it around
/// WiFiManager wifiManager;
//fetches ssid and pass from eeprom and tries to connect
//if it does not connect it starts an access point with the specified name
//here "AutoConnectAP"
//and goes into a blocking loop awaiting configuration
wifiManager.autoConnect("mikek-AP");
//if you get here you have connected to the WiFi
Serial.println("connected...yesss! :)");
/// while (WiFi.waitForConnectResult() != WL_CONNECTED) {
Serial.println("Connection Failed! Rebooting...");
/// delay(5000);
/// ESP.restart();
/// }
// Port defaults to 8266
// ArduinoOTA.setPort(8266);
// Hostname defaults to esp8266-[ChipID]
// ArduinoOTA.setHostname("myesp8266");
// No authentication by default
// ArduinoOTA.setPassword((const char *)"123");
ArduinoOTA.onStart([]() {
Serial.println("Start OTA");
});
ArduinoOTA.onEnd([]() {
Serial.println("\nEnd OTA");
});
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 OTA");
Serial.print("IP address OTA: ");
Serial.println(WiFi.localIP());
/// consider to use Blynk.config(auth); that is now ssid, password hard code specific ///
/// due to WiFiManager framework the bellow credentials are not needed anymore... ///
/// Blynk.begin(auth, ssid, password);
Blynk.config(auth);
while (Blynk.connect() == false) {
// Wait until connected
}
/// START of SimpleTimer timer Functions
/// This blink LED function be called every second
timer.setInterval(1000L, blinkLedWidget);
/// This temp./humd. report function be called every 30 seconds
timer.setInterval(30000L, sendTemperatureHumidity);
/// Display digital clock every 2 seconds
timer.setInterval(2000L, clockDisplay);
/// Check the status of the Relays Relay 1: gp12 <--> V16 , Relay 2: gp13 <--> V17 every 500 mS ///
timer.setInterval(500L, statusCheck);
/// Check timers for activetoday ? function ///
timer.setInterval(15000L, activetoday); // check every 15 seconds if schedule should run today
/// Check blynk connection ///
timer.setInterval(10000L, reconnectBlynk); // check every 10s if still connected to server
/// END of SimpleTimer timer Functions
lcd.clear(); //Use it to clear the LCD Widget
lcd.print(0, 0, Author);
lcd.print(0, 1, WellcomeLine2);
/// lcd.print(13, 1, Version); // use: (position X: 0-15, position Y: 0-1, "Message you want to print")
/*
// This will print Blynk Software version to the Terminal Widget when
// your hardware gets connected to Blynk Server
terminal.println(F("Blynk v" BLYNK_VERSION ": Device started"));
/// terminal.println("-------------");
terminal.println(Author);
terminal.print(WellcomeLine2);
terminal.println(Version);
terminal.println(Project);
terminal.flush();
*/
/// NTP related ///
Serial.println("Starting UDP");
Udp.begin(localPort);
Serial.print("Local port: ");
Serial.println(Udp.localPort());
Serial.println("waiting for sync");
setSyncProvider(getNtpTime);
setSyncInterval(300); /// set sync timer at 300 seconds = 5 minutes
}
/// ===> END OF SETUP <=== ///
BLYNK_READ(PIN_UPTIME) /// this is readed every 5 seconds using Blynk Android App pull request ///
{
// This command writes Arduino's uptime in seconds to Virtual Pin (V5)
unsigned long ticks = millis() / 1000;
/// presentation value reset (moduled %) each day = 86400 , week = 604800 so put this value on module ///
ticks = ticks % 604800; /// modulo each 7 days ///
Blynk.virtualWrite(PIN_UPTIME, ticks);
}
// You can send commands from Terminal to your hardware. Just use
// the same Virtual Pin as your Terminal Widget
BLYNK_WRITE(V14)
{
/// take "commands" from the terminal and acting accordingly ///
/// https://www.arduino.cc/en/Tutorial/StringSubstring ///
/// (stringOne.equalsIgnoreCase(stringTwo)) ///
/// stringOne.trim(); ///
/// int strgLenght = param.getLength(); /// get the string lenght ///
String getString = param.asStr(); /// get the string ///
getString.trim(); /// cut off the blank spece(s) at the end of the string ///
/// terminal.print("String Lenght= ") ;
/// terminal.println(strgLenght);
/// getString.toUpperCase(); /// convert all string characters to uppercase ///
if (getString.equalsIgnoreCase("relaystop")) {
terminal.println("You said: relaystop , OK I will do nothing!") ;
;
} else if (getString.equalsIgnoreCase("relaystart")) {
terminal.println("You said: relaystart , OK I will do nothing!") ;
;
} else if (getString.equalsIgnoreCase("Clear")) {
terminal.println("You said: clear , OK I will !") ;
lcd.clear();
for(int i=1; i<8; i++) {
terminal.println();
}
terminal.flush();
} else if (getString.equalsIgnoreCase("Startled")) {
terminal.println("You said: startled , OK I will !") ;
ledBlink = true;
} else if (getString.equalsIgnoreCase("Stopled")) {
terminal.println("You said: stopled , OK I will !") ;
ledBlink = false;
digitalWrite(16, 0); /// switch off the internal led /// turn off the LED. It is the default state... ///
} else if (getString.equalsIgnoreCase("Diags")) {
terminal.println("You said: Diags , OK I will !") ;
diagnostics();
} else if (getString.equalsIgnoreCase("restart")) {
terminal.println("You said: restart , OK I will !") ;
yield();
yield();
delay(1000);
ESP.restart();
} else if (getString.equalsIgnoreCase("?") || getString.equalsIgnoreCase("help")) {
terminal.println("The regognised commands are: ") ;
terminal.println("relaystart, relaystop, clear, startled, stopled, diags, restart") ;
} else {
// Send it back
terminal.print("You said:");
terminal.write(param.getBuffer(), param.getLength());
terminal.println();
terminal.println("Type ? or help to get help...") ;
terminal.println();
}
// Ensure everything is sent
terminal.flush();
}
/// START of diagnostics function ///
void diagnostics()
{
/// diagnostics print here ///
/// termPrint=false; /// shall I implement in this sketch ???
terminal.println(WellcomeLine2);
//terminal.println(Version);
terminal.println(Project);
terminal.print("Last RST?: ");
terminal.println (ESP.getResetReason());
/// not working /// terminal.printf("Last RST?: %s \n", ESP.getResetReason());
terminal.printf("ESP ID? : %d \n", ESP.getChipId());
terminal.printf("ESP free heap? : %d \n", ESP.getFreeHeap());
terminal.printf("WiFi Signal: %d dBm \n", WiFi.RSSI());
///terminal.print("ESP flash chip frequency? : ");
///terminal.println(ESP.getFlashChipSpeed()); /// returns the flash chip frequency, in Hz.
// Ensure everything is sent
terminal.flush();
}
/// END of diagnostics function ///
/// press V4 button in order to get the Software Version printed on app's screen ///
BLYNK_WRITE(V4)
{
if (param.asInt()) {
lcd.clear(); //Use it to clear the LCD Widget
lcd.print(0, 0, Author);
lcd.print(0, 1, WellcomeLine2);
/// lcd.print(13, 1, Version); // use: (position X: 0-15, position Y: 0-1, "Message you want to print")
// This will print Blynk Software version to the Terminal Widget when
// your hardware gets connected to Blynk Server
terminal.printf("\nBlynk Ver. %s Device started \n", BLYNK_VERSION);
terminal.printf("%s / %s\n%s\n", Author, WellcomeLine2, Project);
terminal.flush();
}
}
/// START routine for manual (on demend) requesting OTA The Virtual Button SW V15 is used ///
BLYNK_WRITE(V15)
{
if (param.asInt()) {
ArduinoOTA.handle();
///for(int c = 0; c < 100; c++) {
///ArduinoOTA.handle();
///}
}
/// else {
/// do nothing ///
/// }
}
/// END routine for manual (on demend) requesting OTA The Virtual Button SW V15 is used ///
/// START routine for reading V16 (Relay 1 Virtual Button) and drive / change gp 12 accordingly ///
BLYNK_WRITE(V16)
{
if (param.asInt()) {
digitalWrite(12,HIGH);
}
else {
digitalWrite(12,LOW);
}
}
/// END routine for reading V16 (Relay 1 Virtual Button) and drive / change gp 12 accordingly ///
/// START routine for reading V17 (Relay 2 Virtual Button) and drive / change gp 13 accordingly ///
BLYNK_WRITE(V17)
{
if (param.asInt()) {
digitalWrite(13,HIGH);
}
else {
digitalWrite(13,LOW);
}
}
/// END routine for reading V17 (Relay 2 Virtual Button) and drive / change gp13 accordingly ///
/// START of temporary function to print timer1 all variables ///
BLYNK_WRITE(V20) {
/// timer1StartHour , timer1StartMinute , timer1StartSecond , timer1Timezone;
/// timer1StopHour , timer1StopMinute , timer1StopSecond ;
if (param.asInt()) {
/*
terminal.print("Tmr1 Start H: "); terminal.println(timer1StartHour);
terminal.print("Tmr1 Start M: "); terminal.println(timer1StartMinute);
terminal.print("Tmr1 Start S: "); terminal.println(timer1StartSecond);
terminal.flush();
terminal.print("Tmr1 Stop H: "); terminal.println(timer1StopHour);
terminal.print("Tmr1 Stop M: "); terminal.println(timer1StopMinute);
terminal.print("Tmr1 Stop S: "); terminal.println(timer1StopSecond);
terminal.println("Days processing not implemented yet...");
terminal.flush();
*/
}
}
/// END of temporary function to print timer1 all variables ///
/// START of Timer1 function for V21 ///
BLYNK_WRITE(V21)
{
TimeInputParam t(param);
int dayadjustment = -1;
if(weekday() == 1){
dayadjustment = 6; // needed for Sunday, Time library is day 1 and Blynk is day 7
}
if(t.isWeekdaySelected((weekday() + dayadjustment))){ //Time library starts week on Sunday, Blynk on Monday
/// sprintf(Date1, "%02d/%02d/%04d", day(), month(), year());
/// sprintf(Time1, "%02d:%02d:%02d", hour(), minute(), second());
now1seconds = ((hour() * 3600) + (minute() * 60) + second());
start1secondswd = (t.getStartHour() * 3600) + (t.getStartMinute() * 60);
if(now1seconds >= start1secondswd){
if(now1seconds <= start1secondswd + 40){ // 40s on 15s timer ensures 1 trigger command is sent
if(V31Timer == true){ /// RL1 activation ///
digitalWrite(12,HIGH);
Blynk.virtualWrite(V16, (digitalRead(12)));
} else { /// RL2 activation ///
digitalWrite(13,HIGH);
Blynk.virtualWrite(V17, (digitalRead(13)));
}
}
}
stop1secondswd = (t.getStopHour() * 3600) + (t.getStopMinute() * 60);
if(now1seconds >= stop1secondswd){
if(now1seconds <= stop1secondswd + 40){ // 40s on 15s timer ensures 1 trigger command is sent
if(V31Timer == true){ /// RL1 de-activation ///
digitalWrite(12,LOW);
Blynk.virtualWrite(V16, (digitalRead(12)));
} else { /// RL2 de-activation ///
digitalWrite(13,LOW);
Blynk.virtualWrite(V17, (digitalRead(13)));
}
}
}
}
}
/// END of Timer1 function for V21 ///
/// START of Timer2 function for V22 ///
BLYNK_WRITE(V22)
{
TimeInputParam t(param);
int dayadjustment = -1;
if(weekday() == 1){
dayadjustment = 6; // needed for Sunday, Time library is day 1 and Blynk is day 7
}
if(t.isWeekdaySelected((weekday() + dayadjustment))){ //Time library starts week on Sunday, Blynk on Monday
///sprintf(Date2, "%02d/%02d/%04d", day(), month(), year());
///sprintf(Time2, "%02d:%02d:%02d", hour(), minute(), second());
now2seconds = ((hour() * 3600) + (minute() * 60) + second());
start2secondswd = (t.getStartHour() * 3600) + (t.getStartMinute() * 60);
if(now2seconds >= start2secondswd){
if(now2seconds <= start2secondswd + 40){ // 40s on 20s timer ensures 1 trigger command is sent
if(V32Timer == true){ /// RL1 activation ///
digitalWrite(12,HIGH);
Blynk.virtualWrite(V16, (digitalRead(12)));
} else { /// RL2 activation ///
digitalWrite(13,HIGH);
Blynk.virtualWrite(V17, (digitalRead(13)));
}
}
}
stop2secondswd = (t.getStopHour() * 3600) + (t.getStopMinute() * 60);
if(now2seconds >= stop2secondswd){
if(now2seconds <= stop2secondswd + 40){ // 40s on 15s timer ensures 1 trigger command is sent
if(V32Timer == true){ /// RL1 de-activation ///
digitalWrite(12,LOW);
Blynk.virtualWrite(V16, (digitalRead(12)));
} else { /// RL2 de-activation ///
digitalWrite(13,LOW);
Blynk.virtualWrite(V17, (digitalRead(13)));
}
}
}
}
}
/// END of Timer2 function for V22 ///
/// START of Timer3 function for V23 ///
BLYNK_WRITE(V23)
{
TimeInputParam t(param);
int dayadjustment = -1;
if(weekday() == 1){
dayadjustment = 6; // needed for Sunday, Time library is day 1 and Blynk is day 7
}
if(t.isWeekdaySelected((weekday() + dayadjustment))){ //Time library starts week on Sunday, Blynk on Monday
///sprintf(Date3, "%02d/%02d/%04d", day(), month(), year());
///sprintf(Time3, "%02d:%02d:%02d", hour(), minute(), second());
now3seconds = ((hour() * 3600) + (minute() * 60) + second());
start3secondswd = (t.getStartHour() * 3600) + (t.getStartMinute() * 60);
if(now3seconds >= start3secondswd){
if(now3seconds <= start3secondswd + 40){ // 40s on 15s timer ensures 1 trigger command is sent
if(V33Timer == false){ /// RL1 activation ///
digitalWrite(12,HIGH);
Blynk.virtualWrite(V16, (digitalRead(12)));
} else { /// RL2 activation ///
digitalWrite(13,HIGH);
Blynk.virtualWrite(V17, (digitalRead(13)));
}
}
}
stop3secondswd = (t.getStopHour() * 3600) + (t.getStopMinute() * 60);
if(now3seconds >= stop3secondswd){
if(now3seconds <= stop3secondswd + 40){ // 40s on 15s timer ensures 1 trigger command is sent
if(V33Timer == false){ /// RL1 de-activation ///
digitalWrite(12,LOW);
Blynk.virtualWrite(V16, (digitalRead(12)));
} else { /// RL2 de-activation ///
digitalWrite(13,LOW);
Blynk.virtualWrite(V17, (digitalRead(13)));
}
}
}
}
}
/// END of Timer3 function for V23 ///
/// START of Timer4 function for V24 ///
BLYNK_WRITE(V24)
{
TimeInputParam t(param);
int dayadjustment = -1;
if(weekday() == 1){
dayadjustment = 6; // needed for Sunday, Time library is day 1 and Blynk is day 7
}
if(t.isWeekdaySelected((weekday() + dayadjustment))){ //Time library starts week on Sunday, Blynk on Monday
///sprintf(Date4, "%02d/%02d/%04d", day(), month(), year());
///sprintf(Time4, "%02d:%02d:%02d", hour(), minute(), second());
now4seconds = ((hour() * 3600) + (minute() * 60) + second());
start4secondswd = (t.getStartHour() * 3600) + (t.getStartMinute() * 60);
if(now4seconds >= start4secondswd){
if(now4seconds <= start4secondswd + 40){ // 40s on 15s timer ensures 1 trigger command is sent
if(V34Timer == false){ /// RL1 activation ///
digitalWrite(12,HIGH);
Blynk.virtualWrite(V16, (digitalRead(12)));
} else { /// RL2 activation ///
digitalWrite(13,HIGH);
Blynk.virtualWrite(V17, (digitalRead(13)));
}
}
}
stop4secondswd = (t.getStopHour() * 3600) + (t.getStopMinute() * 60);
if(now4seconds >= stop4secondswd){
if(now4seconds <= stop4secondswd + 40){ // 40s on 15s timer ensures 1 trigger command is sent
if(V34Timer == false){ /// RL1 de-activation ///
digitalWrite(12,LOW);
Blynk.virtualWrite(V16, (digitalRead(12)));
} else { /// RL2 de-activation ///
digitalWrite(13,LOW);
Blynk.virtualWrite(V17, (digitalRead(13)));
}
}
}
}
}
/// END of Timer4 function for V24 ///
/// START of activetoday function check every 15 seconds if schedule should run today ///
void activetoday(){ // check if schedule should run today
{
Blynk.syncVirtual(V21); // sync timeinput widget
Blynk.syncVirtual(V22);
timer.setTimeout(1000L, activetoday1);
}
}
/// END of activetoday function ///
/// START of activetoday1 function check after 1 second from activetoday to see if schedule should run today ///
void activetoday1(){ // check if schedule should run today
Blynk.syncVirtual(V23);
Blynk.syncVirtual(V24);
}
/// END of activetoday1 function ///
/// START of RL 1 or RL 2 selection using V31 ///
/// V31,V32Timer if false => RL1, true => RL2 ... V33,V34Timer if false => RL2, true => RL1 ///
BLYNK_WRITE(V31)
{
if (param.asInt()) {
V31Timer = false;
} else {
V31Timer = true;
}
}
/// END of RL 1 or RL 2 selection using V31 ///
/// START of RL 1 or RL 2 selection using V32 ///
/// V31,V32Timer if false => RL1, true => RL2 ... V33,V34Timer if false => RL2, true => RL1 ///
BLYNK_WRITE(V32)
{
if (param.asInt()) {
V32Timer = false;
} else {
V32Timer = true;
}
}
/// END of RL 1 or RL 2 selection using V32 ///
/// START of RL 1 or RL 2 selection using V33 ///
/// V31,V32Timer if false => RL1, true => RL2 ... V33,V34Timer if false => RL2, true => RL1 ///
BLYNK_WRITE(V33)
{
if (param.asInt()) {
V33Timer = false;
} else {
V33Timer = true;
}
}
/// END of RL 1 or RL 2 selection using V33 ///
/// START of RL 1 or RL 2 selection using V34 ///
/// V31,V32Timer if false => RL1, true => RL2 ... V33,V34Timer if false => RL2, true => RL1 ///
BLYNK_WRITE(V34)
{
if (param.asInt()) {
V34Timer = false;
} else {
V34Timer = true;
}
}
/// END of RL 1 or RL 2 selection using V34 ///
// Every time we connect to the cloud synchronize some of the values from Widgets...
// This function will run every time Blynk connection is established
BLYNK_CONNECTED() {
Blynk.syncAll();
}
/// ===> START OF LOOP <=== ///
void loop() {
ArduinoOTA.handle();
/// trick to check if connected first (instead of just Blynk.run();) from Costas ///
if (Blynk.connected()) { // to ensure that Blynk.run() function is only called if we are still connected to the server
Blynk.run();
}
/// Blynk.run();
timer.run();
}
/// ===> END OF LOOP <=== ///
/*-------- START of NTP code ----------*/
const int NTP_PACKET_SIZE = 48; // NTP time is in the first 48 bytes of message
byte packetBuffer[NTP_PACKET_SIZE]; //buffer to hold incoming & outgoing packets
time_t getNtpTime()
{
IPAddress ntpServerIP; // NTP server's ip address
while (Udp.parsePacket() > 0) ; // discard any previously received packets
Serial.println("Transmit NTP Request");
// get a random server from the pool
WiFi.hostByName(ntpServerName, ntpServerIP);
Serial.print("ntp Server Name: ");
Serial.print(ntpServerName);
Serial.print(" IP: ");
Serial.println(ntpServerIP);
sendNTPpacket(ntpServerIP);
uint32_t beginWait = millis();
while (millis() - beginWait < 1500) {
int size = Udp.parsePacket();
if (size >= NTP_PACKET_SIZE) {
Serial.println("Receive NTP Response");
Udp.read(packetBuffer, NTP_PACKET_SIZE); // read packet into the buffer
unsigned long secsSince1900;
// convert four bytes starting at location 40 to a long integer
secsSince1900 = (unsigned long)packetBuffer[40] << 24;
secsSince1900 |= (unsigned long)packetBuffer[41] << 16;
secsSince1900 |= (unsigned long)packetBuffer[42] << 8;
secsSince1900 |= (unsigned long)packetBuffer[43];
return secsSince1900 - 2208988800UL + timeZone * SECS_PER_HOUR;
}
}
Serial.println("No NTP Response :-(");
return 0; // return 0 if unable to get the time
}
// send an NTP request to the time server at the given address
/// void sendNTPpacket(IPAddress &address)
void sendNTPpacket(IPAddress &address)
{
// set all bytes in the buffer to 0
memset(packetBuffer, 0, NTP_PACKET_SIZE);
// Initialize values needed to form NTP request
// (see URL above for details on the packets)
packetBuffer[0] = 0b11100011; // LI, Version, Mode
packetBuffer[1] = 0; // Stratum, or type of clock
packetBuffer[2] = 6; // Polling Interval
packetBuffer[3] = 0xEC; // Peer Clock Precision
// 8 bytes of zero for Root Delay & Root Dispersion
packetBuffer[12] = 49;
packetBuffer[13] = 0x4E;
packetBuffer[14] = 49;
packetBuffer[15] = 52;
// all NTP fields have been given values, now
// you can send a packet requesting a timestamp:
Udp.beginPacket(address, 123); //NTP requests are to port 123
Udp.write(packetBuffer, NTP_PACKET_SIZE);
Udp.endPacket();
}
/*-------- END of NTP code ----------*/
To start using it:
Which ESP are you using as I notice you refer to the onboard LED as 16 whereas the WeMos is 2?
It doesn’t compile with my version 1.6.9 of the IDE (functions out of order issue) so I will try it on a machine with 1.6.12 that seems OK with Blynk. Which IDE are you using?
ESP12F
and for me compiled without any complain…
I use 1.6.9 and latest 3.2.0. esp environment
I think I have a bug in my 1.6.9, compiles OK with 1.6.12. just trying to get my head around your WiFi Manager implementation. I have Ken Taylor’s branch as the currently active library rather than @tzapulica’s master branch.
it is compiled ( I tried now) nicely even with Wemos D1 R2 & Mini as target… so yes, something wrong at your installation.
I bypassed WiFi Manager and just did a regular connection to a local server and all is fine here with 1.6.12 (sure it is with 1.6.9 too if I juggle the functions around in my buggy version of the IDE).
You do know that Blynk’s Cloud server is not yet running the latest version of the server don’t you?
Dear Costas,
yes I know it from a discussion you had with Dmitriy.
It is VERY strange why for me it stopped after many days that it was running perfectly …
Anyway, I thank you for your best support and kindness. Don’t laugh but I suspect hardware fault… ! (When at home, I will try another ESP…).
Again thanks and Best Regards,
Mike Kranidis
P.S. How did you find my project?
Project looks good.
Be sure to use code like:
#define TestLED 2
Rather than using pins 2 (or 16) everywhere and then it is just a single line to change.
Like the SW Version button. I must look at your code for this as most of the time when I send so much text to Terminal I only see part of it. Nice use of random for temperature and humidity simulation on SECONDARY tab. I was thrown a bit when I saw actual readings in the LCD.
@Dmitriy what’s all this ASIA/Nicosia stuff in the RTC widget? My system defaults to Asia/Nicosia when I use the widget until I tell it that Nicosia is actually in Europe. Not just Nicosia, there are lots of places in Europe that are also in “ASIA”.
@Dmitriy
Dear Costas and Dmitriy,
I will drive me to mad!!!
Here at work, I have one WeMos hanging around and I stole a little time to send my sketch ( exactly the same as Costas tried ) because I suspected my home hardware (ESP12F).
The result, the Blynk did the same!!! Same problems…
@Dmitriy Please tell me, is it possible this problem to have the root cause in the Blynk public server??? Ex corruption in my server profile?
I state it again, without touching a single line in my sketch, this problem come up yesterday 18:30 ( and beyond ) Greek local time?
@Costas please create separate topic if you see some issues. I can’t follow all this big thread.
@mikekgr same here. This Time Input issue or not anymore?
Dear @Dmitriy , the problem is that Idon’t know from where this problem came to my project. Is it Time Input widget? I don’t know. For this reason I asked you the question: “is it possible this problem to have the root cause in the Blynk public server??? Ex corruption in my server profile?”.
Can you comment please?
Thanks
No. We did nothing to servers in last few days. Maybe app update has something to do with it?
Done.
I am not sure… Is there by any mean profile corruption or something like this?
I can share or clone the under testing project to you for better debugging from you. What do you thing?