timer.setInterval and setSyncInterval togather not working

You can use it but you have to change timer.setInterval to simpletimer.setInterval

  simpleTimer.setInterval(500L, blinkLedWidget);
  simpleTimer.setInterval(2200L, LDRAndPIR);``` This is what I am doing.  Still not working. 

This is just for testing.
```dateTime = dsRtc.now();
  if (!dsRtc.lostPower()) // This is for testing to see if the time is getting set. 
  {
    Serial.println("RTC lost power, lets set the time!");
    dsRtc.adjust(DateTime(year(), month(), year(), hour(), minute(), second()));
  }```

Do you use SimpleTimer library ?
I think there is a conflict with BlynkTimer
The question is : why do you need an external timer ?
BlynkTimer do the job as well as DS3231

I am not using SimpleTimer library as per doc, It was told Blynk Library is using SimpleTimer Library. .

If the internet goes down, I can use the DS3231 to trigger it. It is just a try.

So why do you use SimpleTimer.run instead of timer.run ?

I have the device, Trying to see if we can integrate with it.

I really donā€™t understand .
You are talking about DS3231 , you have to use this 2 libraries
#include <Wire.h>
#include <DS3231.h>
nothing to see with timer.run :thinking:

#include <RTClib.h> #include <Wire.h>

I am using the lib, But after commenting out this line it works
RTC_DS3231 dsRtc;

Iā€™m rapidly losing the will to live with this topic.
I started-out as a question about an LDR sensor and a PIR sensor and ha now morphed into a discussion about RTC modules and synchronisation with the Blynk RTC widget, with random snippets of code being tossed around like confetti.
It doesnā€™t help that @manojgct84 often gives cryptic one line responses to complex questions.

@manojgct84 Iā€™d suggest that you begin with a very simple piece of code - one which is only focussed on your hardware RTC module and the Blynk RTC widget - and try to get whatever it is that you are trying to achieve working correctly.
If you need assistance with this element of your project then explain clearly what your goals are, what hardware you are using and how its connected together, what code you are running and what issues you are having.

That way you are likely to get focussed assistance with your specific issue, and the regulars here wonā€™t get bored and walk away.

Pete.

1 Like
#include <ds3231.h>
#define BLYNK_PRINT Serial
#include <Wire.h>
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <SoftwareSerial.h>
#include <WidgetRTC.h>

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

// Your WiFi credentials for home network
char ssid[] = "2.4-XXXX";
char pass[] = "XXXX";

//Software Serial on Uno, Nano... - This is were the ESP-01 module will communicate
SoftwareSerial EspSerial(2, 3); // RX, TX

// Your ESP8266 baud rate:
#define ESP8266_BAUD 9600

//Real Time Date
BlynkTimer timer;
WidgetRTC rtc;

ESP8266 wifi(&EspSerial);

volatile boolean isRelayModuleOn = false;
struct ts t;

WidgetLED led0(V1);
WidgetLED led1(V0);

BLYNK_CONNECTED() {
  // Synchronize time on connection
  rtc.begin();
  Blynk.syncAll();
}

// This function will be called every time Slider Widget
// in Blynk app writes values to the Virtual Pin V1
BLYNK_WRITE(V5)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  if (pinValue == 1) {
    Serial.println("Light is on");
    isRelayModuleOn = true;
  }
  else if (pinValue == 0) {
    Serial.println("Light is off");
    isRelayModuleOn = false;
  }
}
// V1 LED Widget is blinking
void blinkLedWidget()
{
  if (!isRelayModuleOn) {
    led0.off();
    led1.on();
  } else {
    led0.on();
    led1.off();
  }
}

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  // Set ESP8266 baud rate
  EspSerial.begin(ESP8266_BAUD);
  delay(10);
  //Send connected to the blynk.
  Blynk.begin(auth, wifi, ssid, pass);
  delay(100);
  setSyncInterval(60 * 60 * 60); // Sync interval in seconds
  timer.setInterval(1000, blinkLedWidget);
  timer.setInterval(2200, showTime);
  DS3231_init(0);
}

void loop() {
  // put your main code here, to run repeatedly:
  Blynk.run();
  timer.run();
}

void showTime() {
  t.hour = hour();
  t.min = minute();
  t.sec = second();
  t.mday = day();
  t.mon = month();
  t.year = year();

  DS3231_set(t);

  Serial.print("Time:");
  Serial.print(t.hour);
  Serial.print(':');
  Serial.print(t.min);
  Serial.print(':');
  Serial.print(t.sec);
  Serial.print("    ");
  Serial.print(" ");
  Serial.println();
}

I am trying to use my device DS3231. I donā€™t want to offen sync with Blynk Server. DS3231 slows down in min. So to correct , I wanted to Blynk server to correct the clock. After that I wanted to use DS3231 only for time control.

If you add any RTC library[ds3231.h, RTCLib.h] the BlynkTimer stops working.

It seems that you disagree with my advice to provide information about your hardware and how everything is wired-up, and to simplify your sketch to focus just on the time synchronisation process?

Pete.

DS3231 is wired with Arduino Uno and ESP-01 is used as WiFi shield.

I am trying to do the same here also.

This also seems not working for me - [SOLVED] Cannot synchronize ds3231 with RTC widget

Better use esp8266 , itā€™s a all in one for only 3$

This tells us nothing of use. If you arenā€™t prepared to put a bit of effort in to describing the interconnections between your hardware then Iā€™m walking away from this discussion.

Pete.

1 Like

The reason why I am using this concept is, I donā€™t have stable internet in my village.It may go down any time and it will be out for hours. So I wanted to use DS3231 as my timer. I wanted to sync with Blynk Server one in day to avoid time issue with my setup.

I ON my outside house light in the even after 6PM. I ran into issue when there was no internet and light didnt on as i was not able to sync with the Blynk Server.

I think we all understand the reason behind the use of an external RTC module, and I use one in a very similar scenario.
What we donā€™t understand is why you arenā€™t prepared to share your wiring schematic, or to use a simplified version of your code which focuses on just the external RTC and the Blynk RTC widget.

Pete.

1 Like

If your internet connection goes down anytime, you canā€™t use Blynk cloud , no more Blynk app.
You have better use your own Blynk server. :wink:

But it does make sense in some circumstances.
I have some solar powered garden lights that are controlled by my local Node-Red server. The solar controller is in an area where the WiFi signal is rather weak, despite using an external booster.
If the lights are turned-on successfully, but the controller loses WiFi connectivity while they are on, then the lights could stay on until the solar battery is drained - or until the controller re-connects.
Adding an external RTC to the setup allowed me to ensure that the lights would turn on and off at the correct times even if there is no WiFi connectivity.
Iā€™ve since adopted a different approach, where the controller monitors the output from the solar panel and turns the lights on/off based on this information if there is no WiFi connection.

Pete.

1 Like