Local Schedule

Last Updated on : 2024-01-18 08:25:14download

A local schedule is downloaded to the device for execution. The device checks if the timer has expired to run a scheduled task. A local schedule does not depend on a cloud connection and can run as expected even if the device goes offline.

Types of schedules

There are two types of schedules based on how they are updated:

  • Wi-Fi and wired based schedules

    If the device is connected to the internet, it will proactively request the schedule from the cloud when there are updates to scheduled tasks.

  • Bluetooth based schedules

    If a Wi-Fi and Bluetooth combo device is offline from the internet but connected over Bluetooth, it receives scheduled tasks through the app instead of directly from the cloud. In this case, when users add, delete, or modify a schedule, the app sends the update to the device over a Bluetooth connection. The device is passively notified of the schedule information.

Features

  • Up to 30 scheduled tasks can be added.
  • Schedules can be repeated on a weekly basis.
  • Scheduled tasks can run when the device is offline.

How it works

DeviceAppCloudStart the timer for querying scheduled tasks.Add, delete, or modify a scheduled task.The scheduled task is updated.Download the latest scheduled task.opt[Wi-Fi and wired based schedules]Add, delete, or modify a scheduled task.Add, delete, or modify a scheduled task.opt[Bluetooth based schedules]Check if a scheduled task is due.The framework notifies the application oftask processing.alt[The scheduled task is due.]loopDeviceAppCloud

Development guide

Runtime environment

Open tuya_iot_config.h and check if the following macro is defined.

All the Networked Product Development Frameworks support Wi-Fi and wired based schedules.

#define ENABLE_BT_TIMER 1   // Bluetooth based schedule

Reference the header

  • tuya_cloud_com_defs.h

How to use

  1. Create a product on the Tuya IoT Development Platform and then enter the product development process. Click the Function Definition tab, scroll down to Advanced Functions, and enable Cloud Timing.

    If you cannot find Cloud Timing in advanced functions, this is because the product solution does not have this function bound. To request binding it with your product, contact your account manager or submit a service ticket.

    Local Schedule
  2. During device initialization, the application registers the callbacks for processing object-type and raw-type DP commands.

  3. The TuyaOS framework initializes, adds, deletes, or modifies the scheduled task, without involving the application.

  4. When a scheduled task is due, the framework will notify the application using the DP command callback. The command source cmd_tp in the DP data receiving struct is DP_CMD_TIMER.

FAQs

Why is the scheduled task being delayed?

  • A 15-second delay is implemented for each scheduled task to minimize frequent write operations on flash memory.
  • Another reason is that certain software timer task takes up too much time, causing a delay in local scheduled tasks.

Can a local schedule be executed offline?

Once a schedule has been downloaded to the device, it can be executed without an internet connection.

Does the local schedule support daylight saving time (DST)?

Yes, it supports DST. The framework will check if DST is in effect before executing a schedule. If DST is in effect, the schedule will be executed according to DST.

What is the maximum number of schedules?

Up to 30 local schedules are supported.