当前位置:网站首页>Haas506 2.0 development tutorial -sntp (only versions above 2.2 are supported)
Haas506 2.0 development tutorial -sntp (only versions above 2.2 are supported)
2022-06-23 06:38:00 【Zhiyunfu】
haas506 2.0 Development tutorial -sntp
1. Network timing
Case description
- Use sntp Conduct network timing , Get server time .
- network connections ( Insert SIM card )
- Parameters can be added to the new version , No parameter is to use the default server .
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 to the Internet first
connect_network()
# Timing
sntp.settime('ntp.aliyun.com')
# Get the current time
t=time.localtime()
# The obtained time format is ( year , month , Japan , when , branch , second , Sunday , Year day )
print(" current time :",t)
# Output time in a certain format
#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)
- Output :
network register successed
current time : (2021, 11, 25, 2, 33, 36, 4, 328)
2.Class-sntp
| settime |
|---|
| Network timing |
sntp - Simple network time protocol
Module function : A protocol for synchronizing time across a wide area network or local area network , High accuracy ( Tens of milliseconds ).
matters needing attention : You need to ensure that the network connection is successful , Please use the following example code to connect to the network :
settime - Network timing
The functionality : Network timing
matters needing attention : Make sure this network is connected
The function prototype :
sntp.settime(ntpserver)
- Parameter description :
| Parameters | explain |
|---|---|
| No parameter | Indicates that the default server is used for timing |
| ntpserver | Fill in the time server address |
- Return value : 1 success ,0 Failure
边栏推荐
- Haas 506 2.0 Tutoriel de développement - bibliothèque de composants avancés - modem. SMS (ne prend en charge que les versions supérieures à 2,2)
- LeetCode笔记:Weekly Contest 298
- Day_ 06 smart health project - mobile terminal development - physical examination appointment
- Day_ 09 smart health project - mobile terminal development - Mobile quick login and permission control
- 了解学习 JSX 的工作方式
- Sklearn classification in sklearn_ Report & accuracy / recall /f1 value
- CVE-2021-20038
- 2.17 haas506 2.0 development tutorial system (only versions above 2.2 are supported)
- [resolved] "the unity environment took too long to respond. make sure that: \n“
- 百度URL参数之LINK?URL参数加密解密研究(代码实例)
猜你喜欢

haas506 2.0开发教程-hota(仅支持2.2以上版本)

如何查看本机IP

Illustration Google V8 18: asynchronous programming (I): how does V8 implement micro tasks?

Day_ 02 smart communication health project - appointment management - inspection item management
Link of Baidu URL Parameters? Recherche sur le chiffrement et le décryptage des paramètres d'URL (exemple de Code)

Docker practice - redis cluster deployment and micro service deployment project

Home address exchange

把CSMA/CD、Token Bus、Token Ring说清楚

C # database reports errors. Let's have a look

bootstrap如何清除浮动的样式
随机推荐
Haas506 2.0 development tutorial - Advanced Component Library -modem Sim (only supports versions above 2.2)
mysql如何将日期转为数字
Programmers' real ideas | daily anecdotes
Detailed explanation of redis persistence, master-slave and sentry architecture
Gridsearchcv (grid search), a model parameter adjuster in sklearn
Day_ 01 smart communication health project - project overview and environmental construction
Synchronous switching power supply reduces EMI layout dv/dt di/dt
C language removes line breaks (or other characters) at the end of strings
程序员的真实想法 | 每日趣闻
Day_ 04 smart health project - appointment management - package management
Give up Visio, this drawing tool is really fragrant!
Repeated DNA sequences for leetcode topic resolution
Qt 中 QVariant 使用总结
百度URL参数之LINK?URL参数加密解密研究(代码实例)
Global attribute lang attribute
C language obtains second, millisecond, subtle and nanosecond timestamps
Qt使用多线程编译项目的方法
Jour 13 Projet de santé mentale - chapitre 13
中台库存中的实仓与虚仓的业务逻辑设计
json转化为proto