当前位置:网站首页>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失败
边栏推荐
- Skilled use of slicing operations
- 去除防火墙和虚拟机对live555启动IP地址的影响
- Tencent security 2021 report white paper collection (download attached)
- Extend your kubernetes API using the aggregation API
- 从 WAN 到 SD-WAN 边缘设备的网络架构
- phpStudy设置301重定向
- A review: neural oscillation and brain stimulation in Alzheimer's disease
- Word pattern for leetcode topic analysis
- Microsoft interview question: creases in origami printing
- How to build a data application system based on overall value for energy enterprises
猜你喜欢

【Leetcode】431. Encode n-ary tree to binary tree (difficult)

11、 Realization of textile fabric off shelf function

Summary of business logic security ideas

Docker practice - redis cluster deployment and micro service deployment project
Link of Baidu URL Parameters? Recherche sur le chiffrement et le décryptage des paramètres d'URL (exemple de Code)

Day_13 傳智健康項目-第13章

Day_04 传智健康项目-预约管理-套餐管理

综合培养学生脑力思维的少儿编程

Day_13 传智健康项目-第13章

Day_ 07 smart communication health project FreeMarker
随机推荐
Machine learning 3-ridge regression, Lasso, variable selection technique
又到半年总结时,IT人只想躺平
解析创客教育中的造物原理
业务逻辑安全思路总结
Skilled use of slicing operations
Progress of layer 2 technical scheme
记一次GLIB2.14升级GLIB2.18的记录以及其中的步骤原理
Xray linkage crawlergo automatic scanning pit climbing record
射频内容学习
C # database reports errors. Let's have a look
SQL statement error caused by the same SQL table name and function name.
The softing datafeed OPC suite stores Siemens PLC data in an Oracle Database
QT creator builds osgearth environment (osgqt msvc2017)
Day_12 传智健康项目-JasperReports
Pyinstaller packaging pyttsx3 error
原址 交换
熟练利用切片操作
How to batch produce QR codes that can be read online after scanning
【Leetcode】431. Encode n-ary tree to binary tree (difficult)
Illuminate\Support\Collection 去重 unique 列表去重