From f4cd40ef9229a38136ae4b15cb1ec38c07969793 Mon Sep 17 00:00:00 2001 From: yinsuo Date: Fri, 20 May 2022 19:54:57 +0800 Subject: [PATCH] support sntp interface. #1657 --- .../py_engine/modules/sntp/aos/modsntp.c | 3 +- .../py_engine/modules/sntp/esp32/modsntp.c | 2 +- .../python/docs/haas_extended_api/sntp.md | 33 +++++++++++++++++++ 3 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 haas_lib_bundles/python/docs/haas_extended_api/sntp.md diff --git a/components/py_engine/modules/sntp/aos/modsntp.c b/components/py_engine/modules/sntp/aos/modsntp.c index e18e718fa8..67c2dc8bb8 100644 --- a/components/py_engine/modules/sntp/aos/modsntp.c +++ b/components/py_engine/modules/sntp/aos/modsntp.c @@ -33,8 +33,7 @@ STATIC mp_obj_t mp_sntp_settime(size_t n_args, const mp_obj_t *args) tz.tz_minuteswest = -480; tz.tz_dsttime = 0; sntp_set_timezone(&tz); - - return MP_OBJ_NEW_SMALL_INT(0); + return mp_const_none; } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_sntp_settime_obj, 0, 2, mp_sntp_settime); diff --git a/components/py_engine/modules/sntp/esp32/modsntp.c b/components/py_engine/modules/sntp/esp32/modsntp.c index c413c249ac..6b02c7520c 100644 --- a/components/py_engine/modules/sntp/esp32/modsntp.c +++ b/components/py_engine/modules/sntp/esp32/modsntp.c @@ -76,7 +76,7 @@ STATIC mp_obj_t mp_sntp_settime(size_t n_args, const mp_obj_t *args) strftime(strftime_buf, sizeof(strftime_buf), "%c", &timeinfo); ESP_LOGI(TAG, "The current date/time in China is: %s", strftime_buf); - return MP_OBJ_NEW_SMALL_INT(0); + return mp_const_none; } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_sntp_settime_obj, 0, 2, mp_sntp_settime); diff --git a/haas_lib_bundles/python/docs/haas_extended_api/sntp.md b/haas_lib_bundles/python/docs/haas_extended_api/sntp.md new file mode 100644 index 0000000000..6da03d6d65 --- /dev/null +++ b/haas_lib_bundles/python/docs/haas_extended_api/sntp.md @@ -0,0 +1,33 @@ +# sntp - 获取并设定ntp时间 + + +- 模块功能: +获取并设定ntp时间 + +## setTime - 设置时间 + +- 函数功能: +指定时区(默认“CST-8”)或者授时服务器(默认“cn.pool.ntp.org”),获取并设定ntp时间。 + +- 函数原型: +> sntp.setTime([zone], [ntp_server_addr]) + +- 参数说明: + +| 参数 | 类型 | 必选参数? | 说明 | +| --- | --- | --- | --- | +| zone | string | 否 | 时区信息 | +| ntp_server_addr | string | 否 | 授时服务器地址 | + + +- 返回值: +无 + +- 示例: + +```python +import sntp + +sntp.setTime("CST-8", "cn.pool.ntp.org") + +``` \ No newline at end of file -- GitLab