2

I have a method. I need to trigger it every hour passes.(Cron Job)

I mean;

10.00 p.m -> Trigger

11.00 p.m -> Trigger

12.00 p.m ->Trigger

...

...

Card: Arduino Uno + Wifi Shield.

Draft Code

  void setup() {

  }
  
  void onTimeChanged() {
      runTask();
  }
  
  void loop() {
     
  }
  
  
  /*run this method when:
  13.00 p.m
  14.00 p.m
  15.00 p.m
  ........
  ........    */
  void runTask() {

  }
6
  • It is unclear what you want. Wild guess: do you want an Arduino to connect to a server when the timezone the travelling Arduino is in changes? – ocrdu Nov 23 '20 at 21:30
  • Do you want the Arduino to determine in what timezone it is (by IP or GPS geolocation) or do you want the Arduino to determine when local Daylight Saving Time starts or ends? There are libraries available for both. – StarCat Nov 24 '20 at 7:42
  • I just want to make cron jobs. Such as; 10.00 pm,11.00 pm, 12.00pm -> Execute Method – Snefru Clone Nov 24 '20 at 7:48
  • 2
    Do you need the task to trigger at the exact hour (xx:00, full hour with zero minutes), or do you only care about the period being one hour (like at 10:23, 11:23, 12:23, 13:23...). In the former case, do you have an RTC? A GPS receiver? A WiFi module? – Edgar Bonet Nov 24 '20 at 8:26
  • 1
    I need to trigger at the exact hour. I don't have any of them. If needed, i can buy them. – Snefru Clone Nov 24 '20 at 8:44
1

An Arduino Uno doesn't have a Real Time Clock, but you could contact a NTP time server on the internet using the WiFi shield you mention, and get the time from there, and then keep track of time using millis(). Every so often, you should adjust the time with a new call to the NTP time server, because the Arduino's clock isn't all that accurate.

The easiest way would be to get a RTC module (I think the most accurate and still affordable at the moment are DS3231-based). They have a slot for a backup battery so they keep time even when there is no power supply.

Connect the module using I2C to your Arduino, install the appropriate library, and ask it every second (or however accurate you want to be) in your loop() for the exact time.

These modules usually also have an interrupt pin and can generate an interrupt when an alarm time is reached; you could use that also.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.