I am using DS1307 as Real time RTC and Reading Input From RTC and Displaying on Blynk app. Its working fine with below code. Now i would like to use TimeInput Widget from virtual port. how to read Date,time , weekday from Virtual port
#include "Wire.h"
#define BLYNK_PRINT Serial
#include <BlynkSimpleEsp8266.h>
#define DS1307_ADDRESS 0x68
byte zero = 0x00; //workaround for issue #527
SimpleTimer timer;
char Date[16];
char Time[16];
//Local time date variables
static int local_day;
static int local_month;
static int local_year;
static int local_s;
static int local_h;
static int local_m;
void setup()
{
Wire.begin();
Serial.begin(115200);
pinMode(D4, OUTPUT);
pinMode(D5, OUTPUT);
pinMode(D6, OUTPUT);
}
void loop()
{
// put your main code here, to run repeatedly:
Blynk.run();
timer.run();
GetDateTime1();
sprintf(Date, "%04d/%02d/%02d", local_day , local_month , local_year);
sprintf(Time, "%02d:%02d:%02d", local_h, local_m, local_s);
Blynk.virtualWrite(V11, Date);
Blynk.virtualWrite(V10, Time);
}
byte decToBcd(byte val) {
// Convert normal decimal numbers to binary coded decimal
return ( (val / 10 * 16) + (val % 10) );
}
byte bcdToDec(byte val) {
// Convert binary coded decimal to normal decimal numbers
return ( (val / 16 * 10) + (val % 16) );
}
void GetDateTime1() {
// Reset the register pointer
Wire.beginTransmission(DS1307_ADDRESS);
Wire.write(zero);
Wire.endTransmission();
Wire.requestFrom(DS1307_ADDRESS, 7);
local_s = bcdToDec(Wire.read());
local_m = bcdToDec(Wire.read());
local_h = bcdToDec(Wire.read() & 0b111111); //24 hour time
int weekDay = bcdToDec(Wire.read()); //0-6 -> sunday - Saturday
local_day = bcdToDec(Wire.read());
local_month = bcdToDec(Wire.read());
local_year = bcdToDec(Wire.read());
}
Now i need Below part Need to be changed
BLYNK_WRITE(V4)//Monday-Friday
{
if (mondayfriday==1) {
sprintf(Date, "%02d/%02d/%04d", day(), month(), year());
sprintf(Time, "%02d:%02d:%02d", hour(), minute(), second());
TimeInputParam t(param);
terminal.print("M-F Checked schedule at: ");
terminal.println(Time);
terminal.flush();
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
terminal.println("Monday-Friday ACTIVE today");
terminal.flush();
if (t.hasStartTime()) // Process start time
{
terminal.println(String("Start: ") + t.getStartHour() + ":" + t.getStartMinute());
terminal.flush();
}
if (t.hasStopTime()) // Process stop time
{
terminal.println(String("Stop : ") + t.getStopHour() + ":" + t.getStopMinute());
terminal.flush();
}
// Display timezone details, for information purposes only
terminal.println(String("Time zone: ") + t.getTZ()); // Timezone is already added to start/stop time
// terminal.println(String("Time zone offset: ") + t.getTZ_Offset()); // Get timezone offset (in seconds)
terminal.flush();
for (int i = 1; i <= 7; i++) { // Process weekdays (1. Mon, 2. Tue, 3. Wed, ...)
if (t.isWeekdaySelected(i)) {
terminal.println(String("Day ") + i + " is selected");
terminal.flush();
}
}
nowseconds = ((hour() * 3600) + (minute() * 60) + second());
startsecondswd = (t.getStartHour() * 3600) + (t.getStartMinute() * 60);
//Serial.println(startsecondswd); // used for debugging
if(nowseconds >= startsecondswd){
terminal.print("Monday-Friday STARTED at");
terminal.println(String(" ") + t.getStartHour() + ":" + t.getStartMinute());
terminal.flush();
if(nowseconds <= startsecondswd + 90){ // 90s on 60s timer ensures 1 trigger command is sent
digitalWrite(TestLED, HIGH); // set LED ON
Blynk.virtualWrite(V2, 1);
// code here to switch the relay ON
}
}
else{
terminal.println("Monday-Friday Device NOT STARTED today");
terminal.flush();
}
stopsecondswd = (t.getStopHour() * 3600) + (t.getStopMinute() * 60);
//Serial.println(stopsecondswd); // used for debugging
if(nowseconds >= stopsecondswd){
digitalWrite(TestLED, LOW); // set LED OFF
Blynk.virtualWrite(V2, 0);
terminal.print("Monday-Friday STOPPED at");
terminal.println(String(" ") + t.getStopHour() + ":" + t.getStopMinute());
terminal.flush();
if(nowseconds <= stopsecondswd + 90){ // 90s on 60s timer ensures 1 trigger command is sent
digitalWrite(TestLED, LOW); // set LED OFF
Blynk.virtualWrite(V2, 0);
// code here to switch the relay OFF
}
}
else{
if(nowseconds >= startsecondswd){
digitalWrite(TestLED, HIGH); // set LED ON test
Blynk.virtualWrite(V2, 1);
terminal.println("Monday-Friday is ON");
terminal.flush();
}
}
}
else{
terminal.println("Monday-Friday INACTIVE today");
terminal.flush();
// nothing to do today, check again in 30 SECONDS time
}
terminal.println();
}
}