Interrupts @ specific time of day from Arduino IDE

grylearn
Posts: 3
Joined: Mon Mar 05, 2018 6:02 am

Interrupts @ specific time of day from Arduino IDE

Postby grylearn » Mon Mar 05, 2018 6:19 am

I am a beginner in all these micro controller programming. Very recently started with Arduino and quickly stumbled upon ESP32 and has attracted a lot my interest. So if my questions sounds novice, please pardon me.

Below is my H/W and S/W configuration:

ESPWRoom32 3V3
Using a I2C OLED 128X64 display
Arduino IDE
A sensor that generated data.

My question where I need help:

I want to write the sensor data to google sheets at a specific time each day. I am able to create the code (from the help from web) to write to google, but that is working in the main loop as of now. how could I make a block that would be triggered at predefined time of the day, everyday?

Thank you so much for your help.

-Ganga

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: Interrupts @ specific time of day from Arduino IDE

Postby kolban » Mon Mar 12, 2018 4:41 am

If this were not an ESP32, but (say) an Arduino Uno, would you know how to solve the puzzle?

It seems that there is a library called Simple Timer that allows one to define a timer that will fire periodically. Assuming your app knows the current time, you could calculate how many milliseconds until your trigger time is reached at which point a callback will fire. You can then do your work and start a new timer for 24 hours hence.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

grylearn
Posts: 3
Joined: Mon Mar 05, 2018 6:02 am

Re: Interrupts @ specific time of day from Arduino IDE

Postby grylearn » Thu Mar 29, 2018 9:03 am

Thank you Kolban. That was very helpful. I have not tried the specific time part, but the trigger is working at a fixed interval.

Just a followup question? is there limitation on number of milliseconds we can specify in the timer? The reason I am asking this question is below:

When I was testing the device, I had used a 1hour timer and it was working fine. With no code change, I just changed the timer to 172800000 milliseconds to have the event triggered once in 2 days. I have started it last night at 20:45:12. So theoretically the next trigger is to happen 30 Mar 20:45. But I see that it is triggered twice this morning at 05:45:36 & 05:45:53 and once at 05:59:54.

I am not able to figure out any pattern in this erratic behavior. Any help in this regard will be very helpful.

-Ganga

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: Interrupts @ specific time of day from Arduino IDE

Postby kolban » Fri Mar 30, 2018 4:55 am

Unfortunately, I have nothing to add about the internals of the library ... I haven't studied. Normally integers are represented as 32 bits which, if my arithmetic is good, seems to be about 49 days worth of milliseconds so 24 hours shouldn't be an issue. To go deeper, we'd have to look at the internal implementation. For example, does it use a timer or does it poll the current time asking if the desired trigger time is > than the current time. To debug, we might want to log what the ESP32 thinks is the current time and also the value of millis(). Do this when the timer is initialized and when it fires and see what numbers are produced.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

grylearn
Posts: 3
Joined: Mon Mar 05, 2018 6:02 am

Re: Interrupts @ specific time of day from Arduino IDE

Postby grylearn » Fri Mar 30, 2018 9:42 am

Thank you Kolban. Will try that.

-Ganga

Who is online

Users browsing this forum: forrest and 118 guests