TLSR8258 zigbee SDK 3.6.0怎么获取云端时间
在zigbee SDK开发过程中,针对入睡计划等需要获取云端时间的,有什么函数接口可以调用?
现在能从网关处获取任务开始时间23:00,持续30分钟
在zigbee SDK开发过程中,针对入睡计划等需要获取云端时间的,有什么函数接口可以调用?
现在能从网关处获取任务开始时间23:00,持续30分钟
1.您可以查看 tal_time_sync.h 文件,使用该函数获取时间
Code: Select all
TIME_T tal_current_time_get(VOID_T);
2.子设备无法直接获取云端时间,需要保证的是,网关已经获取到了云端时间,这时子设备向网关获取时间,网关下发的就是云端时间
3.TLSR8258 zigbee SDK 3.7.1为目前最新开发框架版本,新增了错误码等功能,建议您更新使用,谢谢
TIME_T current_time;
current_time = tal_current_time_get();
TAL_PR_DEBUG("current_time = %d",current_time);
收到云端传下来的时间:这个时间格式如何转化位hh:mm:ss
行 39: [0732360027 TUYA D][app_cluster_color_control.c:201] current_time = 732360027[2023-03-17 09:20:49.187]
行 46: [0732360044 TUYA D][app_cluster_color_control.c:201] current_time = 732360044[2023-03-17 09:21:05.224]
该时间戳是从 2000年1月1日0时0与当前时间的差值,您可参考以下程序:
Code: Select all
#define SECONDS_IN_MINUTE 60
#define SECONDS_IN_HOUR 3600
#define SECONDS_IN_DAY (SECONDS_IN_MINUTE * 60 * 24)
#define SECONDS_IN_WEEK (SECONDS_IN_DAY * 7)
#define DURATION_FOREVER_U32 0xFFFFFFFFU
#define mYEAR_IS_LEAP_YEAR(year) ( ((year) % 4 == 0) && (((year) % 100 != 0) || ((year) % 400 == 0)) )
const uint8_t emberAfDaysInMonth[] =
{ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
uint32_t emberAfGetUtcFromTimeStruct(EmberAfTimeStruct *time)
{
// Construct a UTC timestamp given an EmberAfTimeStruct structure.
uint32_t utcTime = 0;
uint16_t daysThisYear;
uint32_t i;
if ( (time == NULL) || (time->year < 2000) || (time->month == 0)
|| (time->month > 12) || (time->day == 0) || (time->day > 31) ) {
return 0xFFFFFFFFU; // Invalid parameters
}
for ( i = 2000; i < time->year; i++ ) {
utcTime += (365 * SECONDS_IN_DAY);
if ( mYEAR_IS_LEAP_YEAR(i) ) {
utcTime += SECONDS_IN_DAY;
}
}
//emberAfAppPrintln("Seconds in %d years=%d", i, utcTime);
// Utc Time now reflects seconds up to Jan 1 00:00:00 of current year.
daysThisYear = 0;
for ( i = 0; i < time->month - 1; i++ ) {
daysThisYear += emberAfDaysInMonth[i];
if ( (i == 1) && (mYEAR_IS_LEAP_YEAR(time->year)) ) {
daysThisYear++;
}
}
daysThisYear += time->day - 1;
utcTime += SECONDS_IN_DAY * daysThisYear;
//emberAfAppPrintln("daysThisYear=%d, total Sec=%d (0x%4x)", daysThisYear, utcTime, utcTime);
// Utc Time now reflects seconds up to last completed day of current year.
for ( i = 0; i < time->hours; i++ ) {
utcTime += SECONDS_IN_HOUR;
}
//for( i=0; i<time->minutes; i++ ){
//iutcTime += 60;
//}
utcTime += (60 * time->minutes);
utcTime += time->seconds;
return utcTime;
}
void emberAfFillTimeStructFromUtc(uint32_t utcTime,
EmberAfTimeStruct* returnTime)
{
bool isLeapYear = true; // 2000 was a leap year
uint32_t i;
uint32_t daysSince2000 = utcTime / SECONDS_IN_DAY;
uint32_t secToday = utcTime - (daysSince2000 * SECONDS_IN_DAY);
returnTime->hours = (uint8_t)(secToday / SECONDS_IN_HOUR);
returnTime->minutes = (uint8_t)((secToday
- (returnTime->hours * SECONDS_IN_HOUR)) / 60);
returnTime->seconds = (uint8_t)(secToday
- ((returnTime->hours * SECONDS_IN_HOUR)
+ (returnTime->minutes * 60)));
returnTime->year = 2000;
returnTime->month = 1;
returnTime->day = 1;
// march through the calendar, counting months, days and years
// being careful to account for leapyears.
for (i = 0; i < daysSince2000; i++) {
uint8_t daysInMonth;
if (isLeapYear && (returnTime->month == 2)) {
daysInMonth = 29;
} else {
daysInMonth = emberAfDaysInMonth[returnTime->month - 1];
}
if (daysInMonth == returnTime->day) {
returnTime->month++;
returnTime->day = 1;
} else {
returnTime->day++;
}
if (returnTime->month == 13) {
returnTime->year++;
returnTime->month = 1;
if (returnTime->year % 4 == 0
&& (returnTime->year % 100 != 0
|| (returnTime->year % 400 == 0))) {
isLeapYear = true;
} else {
isLeapYear = false;
}
}
}
}
Code: Select all
typedef struct {
uint16_t year;
uint8_t month;
uint8_t day;
uint8_t hours;
uint8_t minutes;
uint8_t seconds;
} EmberAfTimeStruct;
你好,如果需要新增生物节律、随机定时等DP点功能,3.6.0版本的SDK定时任务底层是不是需要自己实现?我看SDK里面没有相关逻辑。
1.生物节律等应用功能, SDK功能不包含此块,协议是公开的,需要应用自己实现
2.TLSR8258 zigbee SDK 3.7.1为目前最新开发框架版本,新增了错误码等功能,建议您更新使用,谢谢