Hi! I’m try to get this to work on a particle argon: https://community.blynk.cc/t/time-input-widget-and-eventor/14868/17
Here’s what I’ve got so far:
// This #include statement was automatically added by the Particle IDE.
#include <SparkTime.h>
UDP UDPClient;
SparkTime rtc;
#include <blynk.h>
char auth[] = "***";
BlynkTimer timer;
WidgetTerminal terminal(V30);
//WidgetRTC rtc;
// Zone valves
#define valve1 3
#define valve2 4
#define valve3 5
#define valve4 7
#define valve5 8
int mode = 999;
int manuel1 = 0;
int lastmanuel1 = 3;
int auto1 = 0;
int lastauto1 = 3;
//int counts = 0;
#define GREEN "#008000"//#23C48E"
#define BLUE "#04C0F8"
#define YELLOW "#ED9D00"
#define RED "#FF033E" // "#D3435C"
#define DARK_BLUE "#5F7CD8"
WidgetLED led1(V1);
BLYNK_WRITE(V0) {
switch (param.asInt())
{
case 1: // OFF
//Serial.println("Item 1 selected");
mode = 1;
Blynk.virtualWrite(V25, mode);
shutoffall();
//led1.setColor(BLYNK_RED);
break;
case 2: // Manual Mode
Serial.println("Item 2 selected");
mode = 2;
Blynk.virtualWrite(V25, mode);
//led1.setColor(BLYNK_GREEN);
break;
case 3: // Automatic Mode
Serial.println("Item 3 selected");
mode = 3;
Blynk.virtualWrite(V25, mode);
break;
default:
Serial.println("Unknown item selected");
}
}
BLYNK_WRITE(V11)
{
manuel1 = param.asInt();
if (mode == 2 || mode == 3)
{
if (manuel1 == 1)
{
digitalWrite(valve1, LOW);
led1.on();
led1.setColor(GREEN);
}
else
{
digitalWrite(valve1, HIGH);
led1.on();
led1.setColor(RED);
}
}
if (mode == 1)
{
Blynk.virtualWrite(V11, 0);
Blynk.notify("Select Manual or Auto Mode");
}
}
BLYNK_WRITE(V21) { // Scheduler #1 Time Input widget
TimeInputParam t(param);
unsigned int nowseconds = ((hour() * 3600) + (minute() * 60) + second());
unsigned int startseconds = (t.getStartHour() * 3600) + (t.getStartMinute() * 60);
unsigned int stopseconds = (t.getStopHour() * 3600) + (t.getStopMinute() * 60);
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
//Schedule is ACTIVE today
if(nowseconds >= startseconds - 31 && nowseconds <= startseconds + 31 ){ // 62s on 60s timer ensures 1 trigger command is sent
Blynk.virtualWrite(V0, 255); // turn on virtual LED
Serial.println("Schedule 1 started");
}
if(nowseconds >= stopseconds - 31 && nowseconds <= stopseconds + 31 ){ // 62s on 60s timer ensures 1 trigger command is sent
Blynk.virtualWrite(V0, 0); // turn OFF virtual LED
Serial.println("Schedule 1 finished");
}
}
}
/*BLYNK_WRITE(V21) { // Called whenever setting Time Input Widget
TimeInputParam t(param);
int SThour = t.getStartHour();
int STmin = t.getStartMinute();
int STsec = t.getStartSecond();
int SPhour = t.getStopHour();
int SPmin = t.getStopMinute();
int SPsec = t.getStopSecond();
int now = millis();
Blynk.virtualWrite(V25, now);
terminal.println(SThour);
}*/
void setup()
{
Blynk.begin(auth);
rtc.begin(&UDPClient, "north-america.pool.ntp.org");
rtc.setTimeZone(-5);
timer.setInterval(60000L, activetoday); // check every 60s if ON / OFF trigger time has been reached
timer.setInterval(1000L, clockDisplay); // check every second if time has been obtained from the server
//timer.setInterval(5000L, sendinfo);
pinMode(valve1, OUTPUT);
}
void loop()
{
Blynk.run();
timer.run();
}
void shutoffall()
{
//shut it all down
}
void activetoday(){ // check if schedule #1 should run today
if(year() != 1970){
Blynk.syncVirtual(V1); // sync scheduler #1
}
}
void clockDisplay(){ // only needs to be done once after time sync
if((year() != 1970) && (clockSync == false)){
sprintf(currentTime, "%02d:%02d:%02d", hour(), minute(), second());
Serial.println(currentTime);
clockSync = true;
}
}
My problem: sprinklersystem.ino:88:36: ‘hour’ was not declared in this scope
Where can I go to learn about library’s and how they work? Or is that not my problem here?
I’ve tried the TimeLib.h , but couldn’t get it to work and blynk’s time library and RTCWidget doesn’t seem to be available on particle web IDE.
Thanks for taking the time to read through this!