Using Timers

Timers are very simple to create, update, and delete. Let’s give it a go. For our example, we’ll deal with a common use case within the ClearBlade platform: Polling an external internet site for information on a regular basis. Specifically, let’s pretend we’re polling a weather service such as NOAA for the daily weather report in your area.

For the sake of this example, we won’t actually write the code to do that. Just assume we have a ClearBlade code service called “myWeatherForcast” that can download weather forcasts for your area.

Creating a Timer

The first thing you need to do is, in the “Code” section of your application, find and select the “myWeatherForcast” code service. Once you’ve done that, locate and click on the Cog Icon icon and select the “Timers” tab. You should see a window like this:

Add Timer

Now, set “Logging enabled” to “Yes”. This simplifies the debugging process. Once you’ve finished debugging the timer, you can disable logging.

Now, click on “Add Timer +”. You should now see this:

Create Timer

Now, follow the following steps:

  1. In the “Name:” text box, give the timer a name. It must be unique within your system. You can also optionally enter a description.
  2. We’ll run our timer for a year, so enter “365” in the “Repetitions” text box.
  3. In the “Frequency” text box, enter “1”. In the “Frequency” pulldown menu, select “Days”.
  4. Tap in the box next to “Start Time” and select tomorrow’s date. In the time boxes below, enter 12 00 AM.

Now, your window should look something like this (the date will obviously be different):

Almost Done Timer

Tap on Apply. The timer is now ready to run. Note: You’ll want to debug your code service first to make sure it works. Otherwise, you have to wait until the first scheduled time to know if your code is correct.

Updating a Timer

Suppose we love this timer so much that we want to run it forever. You can accomplish this by following these steps:

  1. Locate and select the “myWeatherForcast” code service in your application.
  2. Click on the Cog icon and select the “Timers” tab.
  3. Locate the timer you created above.
  4. Either make the “Repetitions” textbox blank or set it to “-1”.
  5. Table the “Apply” button, and tap the “Confirm” button in the popup dialog.

Deleting a Timer

Normally, you don’t have to delete a timer. They delete themselves when they expire. However, if you have a timer that runs for a long time, or forever, you might want to get rid of it at some point.

To delete a timer, follow steps 1-3 in the “Updating a Timer” section above. Next, find and tap the Trash Can icon. Next, tap the “Confirm” button in the pop up dialog.