Using timer widget once a day

Hi,

I’m using the Timer widget to trigger a relay once every morning (Start at: 8:00:00 Stop at: 8:00:00 – no seconds used -).

The following code is working and the relay is triggering once, the volt meter is also showing a single pulse. However, the monitor is showing double pulse unless I’m reading it wrong. Shouldn’t the text be printed only once?

TIA

Text as shown in the monitor:

=== Relay on === Start run time: 744528
=== Relay on === Start run time: 744531
End run time: 745428
End run time: 745431

//   --- ESP8266-12E dev kit ---
//  #define D0 16
//  #define D1 5 // I2C Bus SCL (clock)
#define D2 4 // I2C Bus SDA (data)
//  #define D3 0
//  #define D4 2 // onboard LED, but inverted logic
//  #define D5 14 // SPI Bus SCK (clock)
//  #define D6 12 // SPI Bus MISO
//  #define D7 13 // SPI Bus MOSI
//  #define D8 15 // SPI Bus SS (CS)
//  #define D9 3 // RX0 (Serial console)
//  #define D10 1 // TX0 (Serial console)

#define BLYNK_PRINT Serial // Enables Serial Monitor
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>

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

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "xxx";
char pass[] = "xxx";

SimpleTimer timer;

BLYNK_WRITE(V5)
{
  // Gets a trigger at startTime.
  // This method will be triggered every day
  // until the widget is removed or project stopped or
  // cleaned stop/start fields of widget itself
  
  digitalWrite(D2, HIGH);  // turns on relay
  
  Serial.print("=== Relay on === ");  
  Serial.print("Start run time: ");   // tells me when it turns on
  Serial.println(millis());
  
  timer.setTimeout(900, TurnOffRelay);
  
}

void TurnOffRelay()
{
  digitalWrite(D2, LOW);
  Serial.print("End run time: ");  // tells me when it turns off
  Serial.println(millis());
}

void setup()
{

  pinMode(D2, OUTPUT);  // relay pin #
  digitalWrite(D2, LOW);  // make sure is not turned on at power-up

  Serial.begin(9600); // See the connection status in Serial Monitor
  delay(10);

  Blynk.begin(auth, ssid, pass);

  while (Blynk.connect() == false) {
    // Wait until connected
  }
}

void loop()
{

  Blynk.run(); // All the Blynk Magic happens here...
  timer.run();

}

Is there some purpose to this?

No it should be printed twice, once at start time 8am and once at stop time, also 8am.
You need param.asInt() and check for 1 or 0 if you just want the serial output once.

Why don’t you simply leave the Timer stop time blank (reset --/–) f you want it to run forever?

:smiley: well, I need a quick pulse, less than a second.

Ok, will try that. Didn´t know I could use that option. Thank you.

What kind of hardware are you using that requires a “quick” pulse?

As shown in my code, I’m generating a 900 ms pulse (I can go up to a second). With it, I’m activating a relay which is connected to a transmitter. The latter generates a pulse train. If the relay stays on for longer than a second, the pulse train is doubled which cannot happen.