当前位置:网站首页>haas506 2.0开发教程-sntp(仅支持2.2以上版本)
haas506 2.0开发教程-sntp(仅支持2.2以上版本)
2022-06-23 05:12:00 【智云服】
haas506 2.0开发教程-sntp
1.网络校时
案例说明
- 使用sntp进行网络校时,获取服务器时间。
- 网络连接(插入SIM卡)
- 新版本校时可以添加参数,无参数是使用默认服务器。
main.py
import utime as time
import network
import sntp
g_connect_status = False
def on_4g_cb(args):
global g_connect_status
pdp = args[0]
netwk_sta = args[1]
if netwk_sta == 1:
g_connect_status = True
else:
g_connect_status = False
def connect_network():
global net,on_4g_cb,g_connect_status
net = network.NetWorkClient()
g_register_network = False
if net._stagecode is not None and net._stagecode == 3 and net._subcode == 1:
g_register_network = True
else:
g_register_network = False
if g_register_network:
net.on(1,on_4g_cb)
net.connect(None)
else:
print('network register failed')
while True:
if g_connect_status:
print('network register successed')
break
time.sleep_ms(20)
if __name__=='__main__':
#先连上网
connect_network()
#校时
sntp.settime('ntp.aliyun.com')
#获取当前时间
t=time.localtime()
#获取到的时间格式是 (年,月,日,时,分,秒,周日,年日)
print("当前时间:",t)
#按照一定格式输出时间
#t_time="{:04d}-{:02d}-{:02d} {:02d}:{:02d}:{:02d}".format(t[0],t[1],t[2],t[3],t[4],t[5])
#print("t_time:",t_time)
- 输出:
network register successed
当前时间: (2021, 11, 25, 2, 33, 36, 4, 328)
2.Class-sntp
| settime |
|---|
| 网络校时 |
sntp - 简单网络时间协议
模块功能: 用于跨广域网或局域网同步时间的协议,具有较高的精确度(几十毫秒)。
注意事项: 需要确保网络连接成功,请使用下面的示例代码连接网络:
settime - 网络校时
函数功能: 网络校时
注意事项: 需确保此网络已经连接
函数原型:
sntp.settime(ntpserver)
- 参数说明:
| 参数 | 说明 |
|---|---|
| 无参数 | 表示使用默认服务器校时 |
| ntpserver | 填入校时服务器地址 |
- 返回值: 1成功,0失败
边栏推荐
- Day_11 传智健康项目-图形报表、POI报表
- Laravel log channel grouping configuration
- Progress of layer 2 technical scheme
- 解读创客教育中的团结协作精神
- C language stepping on the pit: document coding error, resulting in Base64 Chinese coding error
- 如何实现与FDA保持邮件通信安全加密?
- 【踩坑记录】数据库连接未关闭连接,释放资源的坑
- RF content learning
- C language obtains second, millisecond, subtle and nanosecond timestamps
- mongodb 4. X binding multiple IP startup errors
猜你喜欢
随机推荐
How to query fields separated by commas in MySQL as query criteria - find_ in_ Set() function
How to add libraries for Arduino ide installation
如何为 Arduino IDE 安装添加库
Day_ 13 smart health project - Chapter 13
Day_10 传智健康项目-权限控制、图形报表
C语言 踩坑:文档编码错误,导致base64中文编码错误
Shutter style
Day_13 传智健康项目-第13章
【踩坑记录】数据库连接未关闭连接,释放资源的坑
CVE-2021-20038
The central network and Information Technology Commission issued the National Informatization Plan for the 14th five year plan, and the network security market entered a period of rapid growth
[resolved] "the unity environment took too long to respond. make sure that: \n“
sklearn sklearn中classification_report&精确度/召回率/F1值
Fastdata pole | insight report on e-commerce consumption of young Chinese users 2021
又到半年总结时,IT人只想躺平
Detailed explanation of redis persistence, master-slave and sentry architecture
下载oss文件并修改文件名
Leetcode topic resolution remove nth node from end of list
Day_ 10 smart health project - permission control, graphic report
Jour 04 projet de santé mentale - gestion des rendez - vous - gestion des forfaits
![[cocos2d-x] custom ring menu](/img/fd/c18c39ae738f6c1d2b76b6c54dc654.png)







