Help advanced time input

hi, I would like a practical example ADVANCED TIME INPUT. I would like to turn on and off a led at a specific time and day of the week. Thanks so much

You are in luck!!!..

There is a couple of those already in this forum, and one fairly recent topic all about how it works, with examples… You should have no problem searching with the forum search icon at the top right of this page and using sneaky keywords like Time Input Widget :stuck_out_tongue_winking_eye:

1 Like

hi, it’s days that I’m crazy. you could give me an example code for mega arduino. thank you so much

@rok.kom you prefer the fish or being taught how to catch fish?

1 Like

unfortunately I work 12 hours a day and I have very little time available. If you can already have an example done for me it will be easier. Thank you for your availability

@rok.kom Everyone is busy and still take time out to support the community. Please put in your effort and all of us would be there to help. Spoonfeed is the worst form of help.

Look up https://examples.blynk.cc/?board=ESP32&shield=ESP32%20WiFi&example=Widgets%2FTimeInput%2FAdvancedTimeInput

2 Likes

So you typed all those words instead of the three I recommended (in the search tab)… yep… crazy :stuck_out_tongue:

OK try these search keywords to get you closer to one particular topic… you still need to read through the whole topic though :wink:

Missing something with attempt to understand Advanced Time Input

And yes, I am being purposely obtuse… I don’t really care for any “Gimmy, cuz I don’t wanna or can’t because…”. I appreciate getting solid answers… but I work hard to find them before asking.

Can anyone help me?
I have to turn on a led with ADVANCED TIME INPUT
my starting code is this

#define BLYNK_PRINT Serial


#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#include <TimeLib.h>
#include <EthernetUdp.h>



// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "6acef35206ee47918c6bfd84523e7071";

#define W5100_CS  10
#define SDCARD_CS 4

int Temp = 22;
float TempDes; 
float TempOffsetON;
float TempOffsetOFF;
float TempON;
float TempOFF;
int SThour;
int STmin;
int SPhour;
int SPmin;


byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; 
// NTP Servers:
IPAddress timeServer(193,204,114,232); // time-a.timefreq.bldrdoc.gov
// IPAddress timeServer(132, 163, 4, 102); // time-b.timefreq.bldrdoc.gov
// IPAddress timeServer(132, 163, 4, 103); // time-c.timefreq.bldrdoc.gov


const int timeZone = 1;     // Central European Time
//const int timeZone = -5;  // Eastern Standard Time (USA)
//const int timeZone = -4;  // Eastern Daylight Time (USA)
//const int timeZone = -8;  // Pacific Standard Time (USA)
//const int timeZone = -7;  // Pacific Daylight Time (USA)


EthernetUDP Udp;
unsigned int localPort = 8888;  // local port to listen for UDP packets


// This function will be called every time Slider Widget
// in Blynk app writes values to the Virtual Pin V2
BLYNK_WRITE(V2)
{
  float TempDes = param.asFloat(); // assigning incoming value from pin V1 to a variable
Serial.print (TempDes);
  // process received value
  if ((Temp-TempOffsetON)<TempDes)
  {
    digitalWrite(13, HIGH);
  }
  else if (Temp = TempDes+TempOffsetOFF)
  {
    digitalWrite(13, LOW);
  }
 }

// This function will be called every time Slider Widget
// in Blynk app writes values to the Virtual Pin V4
BLYNK_WRITE(V4)
{
  float TempOffsetON = param.asFloat(); // assigning incoming value from pin V1 to a variable
Serial.print (TempOffsetON);
  // process received value
}

// This function will be called every time Slider Widget
// in Blynk app writes values to the Virtual Pin V6
BLYNK_WRITE(V6)
{
  float TempOffsetOFF = param.asFloat(); // assigning incoming value from pin V1 to a variable
Serial.print (TempOffsetOFF);
  // process received value
}


BLYNK_WRITE(V3) {


  TimeInputParam t(param);

  // Process start time

  if (t.hasStartTime())
 
  {
   
   Serial.println(String("Start: ") +
                   t.getStartHour() + ":" +
                   t.getStartMinute() + ":" +
                   t.getStartSecond());
                  
  }
  else if (t.isStartSunrise())
  
  {
    
    Serial.println("Start at sunrise");
  }
  else if (t.isStartSunset())
  {
    Serial.println("Start at sunset");
  }
  else
  {
    // Do nothing
    
  }

  // Process stop time

  if (t.hasStopTime())
  {
    
    Serial.println(String("Stop: ") +
                   t.getStopHour() + ":" +
                   t.getStopMinute() + ":" +
                   t.getStopSecond());
                   
  }
  else if (t.isStopSunrise())
  {
    Serial.println("Stop at sunrise");
     
  }
  else if (t.isStopSunset())
  {
    Serial.println("Stop at sunset");
  }
  else
  {
    // Do nothing: no stop time was set
    
  }

  // Process timezone
  // Timezone is already added to start/stop time

  Serial.println(String("Time zone: ") + t.getTZ());

  // Get timezone offset (in seconds)
  Serial.println(String("Time zone offset: ") + t.getTZ_Offset());

  // Process weekdays (1. Mon, 2. Tue, 3. Wed, ...)

  for (int i = 1; i <= 7; i++) {
    if (t.isWeekdaySelected(i)) {
      Serial.println(String("Day ") + i + " is selected");
    }
  }

  Serial.println();

int SThour = t.getStartHour();
int STmin  = t.getStartMinute();
int SPhour = t.getStopHour();
int SPmin  = t.getStopMinute();


if ((hour()==SThour)&&(minute()==STmin))
{
  digitalWrite(13, HIGH);
}
else if ((hour()>=SPhour)&&(minute()>=SPmin))
{
  digitalWrite(13, LOW);
}
}

void setup()
{
  // Debug console
  Serial.begin(9600);

  while (!Serial) ; // Needed for Leonardo only
  delay(250);
  Serial.println("TimeNTP Example");
  if (Ethernet.begin(mac) == 0) {
    // no point in carrying on, so do nothing forevermore:
    while (1) {
      Serial.println("Failed to configure Ethernet using DHCP");
      delay(10000);
    }
  }
  Serial.print("IP number assigned by DHCP is ");
  Serial.println(Ethernet.localIP());
  Udp.begin(localPort);
  Serial.println("waiting for sync");
  setSyncProvider(getNtpTime);

  pinMode(13, OUTPUT);
  pinMode(SDCARD_CS, OUTPUT);
  digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card

  Blynk.begin(auth);
  // You can also specify server:
  //Blynk.begin(auth, "blynk-cloud.com", 8442);
  //Blynk.begin(auth, IPAddress(192,168,1,100), 8442);

  
}

time_t prevDisplay = 0; // when the digital clock was displayed

void loop()
{  

  Blynk.run();
  if (timeStatus() != timeNotSet) {
    if (now() != prevDisplay) { //update the display only if time has changed
      prevDisplay = now();
      digitalClockDisplay();  
    }
  }
}

void digitalClockDisplay(){
  // digital clock display of the time
  Serial.print(hour());
  Serial.print(minute());
  Serial.print(second());
  Serial.print(" ");
  Serial.print(day());
  Serial.print(" ");
  Serial.print(month());
  Serial.print(" ");
  Serial.print(year()); 
  Serial.println(); 


}

 
/*-------- 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()
{
  while (Udp.parsePacket() > 0) ; // discard any previously received packets
  Serial.println("Transmit NTP Request");
  sendNTPpacket(timeServer);
  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)
{
  // 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();
}

I helped format your code… three backticks and CPP @ beginning and threebackticks @ end (NOT commas)

Blynk - FTFC

in short, I want to use the advanced time widget with the time ntp library

In short… search this forum for these key words - Advanced Time Input :stuck_out_tongue_winking_eye:

Blynk - RE-SEAR-CH