Last Updated on : 2024-06-03 10:19:34download
This topic describes the local schedule feature.
Compared to cloud-based schedules, the local schedule feature enables Bluetooth devices to run a schedule locally without requiring internet access.
Features
A data point (DP) acts as a trigger.
Multiple types of schedules are supported, including regular, random, recurring, and countdown.
The accuracy of the schedule depends on the precision of the local clock.
After the app connects to the Bluetooth device, it queries device information. When responding to this query, the Bluetooth device adds a field to enable the local schedule feature.
When users open the app’s schedule interface, check if a sync is required depending on whether the local schedule feature is enabled.
The app requests the number of schedules as well as the maximum number of schedules allowed per transfer, which is determined by the device.
The app reads the schedules accordingly and compares the schedule ID and CRC32 checksum from the device with those in the cloud. If they do not match, the app syncs the differences with the device.
typedef struct {
uint16_t type;
uint32_t data_len;
uint8_t* p_data;
} tuya_ble_app_passthrough_data_t;
type
: The type of data pass-through. For local schedules, its value is fixed as 0x0000
.
data_len
: The data length of the local schedule.
p_data
: The content of the local schedule.
typedef struct {
uint8_t type;
uint16_t len;
uint8_t year; // the lower two bits
uint8_t month;
uint8_t day;
uint8_t hour;
uint8_t minute;
uint8_t loop;
uint32_t timer_id;
uint8_t* dp_data;
uint32_t crc32;
} tal_local_timer_info_t;
type
: The type of the local schedule.
0x01
: Regular schedule.0x02
: Random schedule (not yet supported by the panel).0x03
: Recurring schedule (not yet supported by the panel).0x04
: Countdown (not yet supported by the panel).len
: The length of the data.
year
: Year (the lower two bits).
month
: Month.
day
: Day.
hour
: Hour.
minute
: Minute.
loop
: Recurring.
0x00
: Saturday.0x01
: Friday.0x02
: Thursday.0x03
: Wednesday.0x04
: Tuesday.0x05
: Monday.0x06
: Sunday.0x07
: Reserved.timer_id
: The schedule ID.
dp_data
: The DP, multiple DPs allowed.
dp_id
(1 byte): The dp_id
of the DP defined on the Developer Platform.
dp_type
: 1 byte.
dp_len
(1 byte): The length of the data, up to 255 bytes.
dp_data
: The data, dp_len
long.
crc32
: The CRC32 checksum.
API description
uint32_t tal_local_timer_init(void);
API description
uint32_t tal_local_timer_handler(tuya_ble_app_passthrough_data_t* data);
Description
Parameter | Description |
---|---|
data | See the description of tuya_ble_app_passthrough_data_t in the preceding section. |
Implement your logic for processing local schedule events.
API description
void tal_local_timer_parser_event(void);
For simplicity, the demo uses tbs_storage_ib.c
to store schedule data. It is recommended that you use your own storage logic.
API description
uint32_t tal_local_timer_storage_init(void);
Store the schedule data.
API description
uint32_t tal_local_timer_info_write(tal_local_timer_info_t* data);
Description
Parameter | Description |
---|---|
data | See the description of tal_local_timer_info_t in the preceding section. |
Delete the schedule data.
API description
uint32_t tal_local_timer_info_delete(uint32_t timer_id);
Description
Parameter | Description |
---|---|
timer_id | The ID of the local schedule. |
Read the DP event associated with the schedule.
API description
uint32_t tal_local_timer_dp_item_read(uint8_t id, uint8_t* buf, uint32_t size);
Description
Parameter | Description |
---|---|
id | The storage ID. |
buf | The DP data. |
size | The length of the DP data. |
Clear all schedule data.
API description
uint32_t tal_local_timer_info_delete_all(void);
API description
uint32_t tal_local_timer_get_num(void);
For more information, see tuyaos_demo_local_timer
.
tuyaos_demo_local_timer
.Communicate with the mobile app using a host that simulates a real device.
Add the target device to the Tuya Smart app.
Tap the + button.
Create a schedule.
The host software looks like this:
The schedule runs at the specified time of 19:08.
If you have any problems with host usage, see Logic Host User Guide.
If you have any problems with TuyaOS development, you can post your questions in the Tuya Developer Forum.
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback