Create scheduled events in Google Cloud Platform

304 views Asked by At

I am creating an IOT device where the user can set a particular time to trigger an action by an IOT device. For eg: At 01:00 PM, the Air Conditioner starts automatically. I am using Google Cloud Platform. I checked the Cron job in GCP, which triggers a particular URL at particular time or a specified interval. Since my trigger time is stored in the datastore so either i've to query the database after every minute using cron job where i can write the logic, to trigger the action if the time matches. but there will always be 59 seconds lag in worst case else i can call the URL after every second. Calling a ulr after every second will be very costly since i need to query the database every 1 second.. Is there any other efficient way to achieve this?

1

There are 1 answers

8
Gabe Weiss On

Just to be sure I'm understanding, the use-case you're trying to avoid, is a user setting the AC to go on at, say, 1PM, and set it at 13:00:01 (so they'd have to wait until 13:01:00 for the AC to turn on)?

Assuming that's the case, then, if you're using Firebase/Firestore, you can use a GCF (Google Cloud Function) to actually trigger the AC turning on (send an IoT Core config message to the device, for example, not sure how you're actually physically turning on the AC). The GCF can be triggered by either the CRON job which fires every minute, or have it respond (it's one of the event triggers) to a database value change in Firebase.

So the user sets the time for the AC to come on, which sets a value in the Firebase database, which triggers the GCF to check the value and see if it should be turning on the AC or not. That way you're not relying on the CRON job alone to turn on the AC, you also have a data-changed event to check the time as well. That should eliminate the 59 second wait time in your case.