#define BLYNK_PRINT SwSerial
#include <SoftwareSerial.h>
SoftwareSerial SwSerial(10, 11); // RX, TX
#include <BlynkSimpleStream.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxxxxxxxxxxxxxxxxxxxxxx";
BLYNK_WRITE(V1) {
long startTimeInSecs = param[0].asLong();
SwSerial.println(startTimeInSecs);
SwSerial.println();
}
void setup()
{
// Debug console
SwSerial.begin(9600);
// Blynk will work through Serial
// Do not read or write this serial manually in your sketch
Serial.begin(9600);
Blynk.begin(Serial, auth);
}
void loop()
{
Blynk.run();
}
here is my code from “blynk example”. connection is via usb. I want to use blynk time input to light led. led is on D4. i need the code for it
Gunner
October 7, 2018, 8:19pm
2
You didn’t format your posted code as instructed…
Or search this forum as recommended…
In an attempt to understand how to use Advanced Time Input I searched and found @Costas Scheduler.ino-Thank you.
I attempted to modify it for a Wemos D1 Mini with the relay shield attached. Keep in mind that I am not an experienced programmer. I am using the latest Blynk app on iOS.
The issue is that no matter what time I set the Time Input to in the future, I never get a respons from the relay when the Start time begins. I have selected a Start Time, Finish Time and Day of the Week. I added …
Here you are. How can i put digital pin in code to light led with time inpit widget?
Gunner
October 8, 2018, 8:55am
4
Now click on that link above and read up on how the Time Input Widget works… you will also want to switch to Virtual Pins for that Widget and control the GPIO via code that responds to the Widgets received data.
A somewhat simpler Time controlled option would be the basic Timer Widget…
http://docs.blynk.cc/#widgets-controllers-timer
#define BLYNK_PRINT DebugSerial
#include <SoftwareSerial.h>
SoftwareSerial DebugSerial(2, 3); // RX, TX
#include <BlynkSimpleStream.h>
#define BLYNK_PRINT Serial
#include <WidgetRTC.h>
BlynkTimer timer;
char auth[] = "xxxxxxxxxxxxxxxxxx";
char currentTime[9];
char startTime[9];
char stopTime[9];
int SThour;
int STmin;
int STsec;
int SPhour;
int SPmin;
int SPsec;
WidgetRTC rtc; // Set RTC widget.
void setup()
{
pinMode(4, OUTPUT); // Built-in LED
digitalWrite(4, HIGH); // Turn OFF built-in LED
Serial.begin(9600); // Debug console
Blynk.begin(Serial, auth);
rtc.begin();
setSyncInterval(360);
timer.setInterval(30000L, TimeCheck); // Update Time Check every 30 seconds
}
BLYNK_CONNECTED() {
Blynk.syncVirtual(V1); // Synchronize Time Input Widget when connected
TimeCheck(); // Initial Time Check
}
void loop()
{
Blynk.run();
timer.run();
}
BLYNK_WRITE(V1) { // Called whenever setting Time Input Widget
TimeInputParam t(param);
SThour = t.getStartHour();
STmin = t.getStartMinute();
STsec = t.getStartSecond();
SPhour = t.getStopHour();
SPmin = t.getStopMinute();
SPsec = t.getStopSecond();
}
void TimeCheck() { // call with timer every 30 seconds or so
// Get RTC time
sprintf(currentTime, "%02d:%02d:%02d", hour(), minute(), second());
Serial.print("Current Time: ");
Serial.println(currentTime);
// Get Time Input Widget time
sprintf(startTime, "%02d:%02d:%02d", SThour, STmin, STsec);
Serial.print("Start Time: ");
Serial.println(startTime);
sprintf(startTime, "%02d:%02d:%02d", SPhour, SPmin, SPsec);
Serial.print("Stop Time: ");
Serial.println(startTime);
if (hour() == SThour) {
if (minute() == STmin) {
Serial.println("Doing something now");
digitalWrite(4, LOW); // Turn ON built-in LED
} else if (minute() < STmin) {
Serial.println("Will do something");
} else if (minute() > STmin) {
Serial.println("Did something");
} else {
Serial.println("Clueless");
}
}
if (hour() == SPhour) {
if (minute() == SPmin) {
Serial.println("Stopping something now");
digitalWrite(4, HIGH); // Turn OFF built-in LED
} else if (minute() < SPmin) {
Serial.println("Will stop something");
} else if (minute() > SPmin) {
Serial.println("Stopped something");
} else {
Serial.println("Clueless");
}
}
Serial.println("----------");
}
still not working. is there any mistake?
void TimeCheck() { // call with timer every 30 seconds or so
Blynk.syncVirtual(V1); // <------ Synchronize Time Input Widget every 30 seconds
// Get RTC time
sprintf(currentTime, "%02d:%02d:%02d", hour(), minute(), second());
Serial.print("Current Time: ");
Serial.println(currentTime);
Giorgi_Turdziladze:
erase this part?
no, add sync
void TimeCheck() { // call with timer every 30 seconds or so
Blynk.syncVirtual(V1); // <------ Synchronize Time Input Widget every 30 seconds
code consists of it-
BLYNK_CONNECTED() {
Blynk.syncVirtual(V1); // Synchronize Time Input Widget when connected
TimeCheck(); // Initial Time Check
}
only at first connect !
you have to sync each 30 sec
BLYNK_CONNECTED() {
Blynk.syncVirtual(V1); // Synchronize Time Input Widget when connected
TimeCheck(); // Initial Time Check
}
let me see your code and your serial monitor
#define BLYNK_PRINT DebugSerial
#include <SoftwareSerial.h>
SoftwareSerial DebugSerial(2, 3); // RX, TX
#include <BlynkSimpleStream.h>
#define BLYNK_PRINT Serial
#include <WidgetRTC.h>
BlynkTimer timer;
char auth[] = "xxxxxxxxxxxxxxxxxx";
char currentTime[9];
char startTime[9];
char stopTime[9];
int SThour;
int STmin;
int STsec;
int SPhour;
int SPmin;
int SPsec;
WidgetRTC rtc; // Set RTC widget.
void setup()
{
pinMode(4, OUTPUT); // Built-in LED
digitalWrite(4, HIGH); // Turn OFF built-in LED
Serial.begin(9600); // Debug console
Blynk.begin(Serial, auth);
rtc.begin();
setSyncInterval(360);
timer.setInterval(30000L, TimeCheck); // Update Time Check every 30 seconds
}
BLYNK_CONNECTED() {
Blynk.syncVirtual(V1); // Synchronize Time Input Widget when connected
TimeCheck(); // Initial Time Check
}
void loop()
{
Blynk.run();
timer.run();
}
BLYNK_WRITE(V1) { // Called whenever setting Time Input Widget
TimeInputParam t(param);
SThour = t.getStartHour();
STmin = t.getStartMinute();
STsec = t.getStartSecond();
SPhour = t.getStopHour();
SPmin = t.getStopMinute();
SPsec = t.getStopSecond();
}
void TimeCheck() { // call with timer every 30 seconds or so
// Get RTC time
Blynk.syncVirtual(V1);
sprintf(currentTime, "%02d:%02d:%02d", hour(), minute(), second());
Serial.print("Current Time: ");
Serial.println(currentTime);
// Get Time Input Widget time
sprintf(startTime, "%02d:%02d:%02d", SThour, STmin, STsec);
Serial.print("Start Time: ");
Serial.println(startTime);
sprintf(startTime, "%02d:%02d:%02d", SPhour, SPmin, SPsec);
Serial.print("Stop Time: ");
Serial.println(startTime);
if (hour() == SThour) {
if (minute() == STmin) {
Serial.println("Doing something now");
digitalWrite(4, LOW); // Turn ON built-in LED
} else if (minute() < STmin) {
Serial.println("Will do something");
} else if (minute() > STmin) {
Serial.println("Did something");
} else {
Serial.println("Clueless");
}
}
if (hour() == SPhour) {
if (minute() == SPmin) {
Serial.println("Stopping something now");
digitalWrite(4, HIGH); // Turn OFF built-in LED
} else if (minute() < SPmin) {
Serial.println("Will stop something");
} else if (minute() > SPmin) {
Serial.println("Stopped something");
} else {
Serial.println("Clueless");
}
}
Serial.println("----------");
}
ok but what do you see on serial monitor ?
I can’t use serial monitor because com3 port is busy because of blynk(i’m using usb connction)
I’m using the same com port to upload code and to see serial monitor.
it’s quiet normal, else you can’t see nothing
but you have to open serial monitor after upload completed
without opening blynk-ser.bat
nothing runs!
is there any issue when you upload the sketch?
Gunner
October 8, 2018, 8:20pm
19
Giorgi_Turdziladze:
i’m using usb connction
@Blynk_Coeur The OP is using the primary USP port for the actual Serial to networking connection to Blynk … it is in use full time.
@Giorgi_Turdziladze You can add in a software serial connection and using another TTL-USB adapter and a terminal program like termite to have a 2nd serial channel for debugging.
I got ît.
I just understood that it’s not an Ethernet connection.
1 Like