当前位置:网站首页>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失败
边栏推荐
- Global attribute lang attribute
- 射频内容学习
- C language stepping on the pit: document coding error, resulting in Base64 Chinese coding error
- Pyqt5 setting window top left Icon
- 百度URL參數之LINK?URL參數加密解密研究(代碼實例)
- C语言 踩坑:文档编码错误,导致base64中文编码错误
- Jour 04 projet de santé mentale - gestion des rendez - vous - gestion des forfaits
- Home address exchange
- Day_ 09 smart health project - mobile terminal development - Mobile quick login and permission control
- How to build a data application system based on overall value for energy enterprises
猜你喜欢

业务逻辑安全思路总结

Summary of business logic security ideas
百度URL参数之LINK?URL参数加密解密研究(代码实例)

Index - MySQL

Difference between MySQL read committed and repeatability

Day_10 传智健康项目-权限控制、图形报表

Day_ 05 smart communication health project - appointment management - appointment settings

11、 Realization of textile fabric off shelf function

Day_ 07 smart communication health project FreeMarker

Day_03 传智健康项目-预约管理-检查组管理
随机推荐
如何实现与FDA保持邮件通信安全加密?
Paper notes: multi label learning lsml
SQL statement error caused by the same SQL table name and function name.
解析创客教育中的个性化学习进度
百度URL参数之LINK?URL参数加密解密研究(代码实例)
mongodb 4. X binding multiple IP startup errors
图解 Google V8 # 18 :异步编程(一):V8是如何实现微任务的?
Find the number of nodes in the widest layer of a binary tree
Sorting out common problems after crawler deployment
Day_12 传智健康项目-JasperReports
qt creater搭建osgearth环境(osgQT MSVC2017)
Home address exchange
Global attribute lang attribute
Coordinate transformation
How to build a data application system based on overall value for energy enterprises
Redis sentry
[DaVinci developer topic] -41-app how SWC reads and writes NVM block data
Laravel log channel grouping configuration
WordPress Core 5.8.2 - 'WP_ Query'SQL injection
Simple about fastdfs