Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions en-us/api/QuecPythonClasslib.md
Original file line number Diff line number Diff line change
Expand Up @@ -12467,3 +12467,64 @@ if __name__ == '__main__':

```



#### uping-(ICMP)ping包

Module function: Simulate sending icmp-ping packets



##### ping

- Precautions

There may be exceptions here, because the host address cannot resume the exception of the socket connection

Periodically send Ping packet mechanism through `COUNT` and `INTERVAL` in initialization parameters

> **import uping**
>
> **up = uping.ping(HOST, SOURCE=None, COUNT=4, INTERVAL=1000, SIZE=64, TIMEOUT=5000, quiet=False)**

- parameter

| parameter | type | illustrate |
| --------- | ---- | ------------------------------------------------------------ |
| HOST | str | The domain name address to be pinged, such as "baidu.com" |
| SOURCE | str | Source address, used for binding, generally does not need to be passed |
| COUNT | int | The default is 4 times, send 4 ping packets |
| INTERVAL | int | Interval time, the default is ms, the default is 1000ms |
| SIZE | int | The default packet size of each read is 64, no need to modify |
| TIMEOUT | int | Timeout time, the unit is ms, the default is 5000ms or 5s |
| quiet | bool | Default fasle, print output, after setting True, the printed value obtained after calling start will be converted into an object and returned, rather than displayed by printing |



example of use

```python
# method one
# printout method
import uping
uping.ping('baidu.com')

# The following is the output of uping.start(), no return value
#72 bytes from 49.49.48.46: icmp_seq=1, ttl=53, time=1169.909000 ms
#72 bytes from 49.49.48.46: icmp_seq=2, ttl=53, time=92.060000 ms
#72 bytes from 49.49.48.46: icmp_seq=3, ttl=53, time=94.818000 ms
#72 bytes from 49.49.48.46: icmp_seq=4, ttl=53, time=114.879000 ms
#4 packets transmitted, 4 packets received, 0 packet loss
#round-trip min/avg/max = 92.06000000000001/367.916/1169.909 ms




# Method 2
# Setting quiet will get the output
import uping
result = uping.ping('baidu.com', quiet=True)
# result can get the corresponding data
# result(tx=4, rx=4, losses=0, min=76.93899999999999, avg=131.348, max=226.697)
```

102 changes: 102 additions & 0 deletions en-us/api/QuecPythonThirdlib.md
Original file line number Diff line number Diff line change
Expand Up @@ -2248,6 +2248,108 @@ sys_bus.unsubscribe("test")



#### uwebsocket use

Module: Mainly used for websocket connection use



##### Client connection

> **import uwebsocket**
>
> **ws_client = uwebsocket.Client.connect(uri, headers=None, debug=False)**

- paramter

| parameter | type | illustrate |
| --------- | ---- | ------------------------------------------------------------ |
| uri | str | The connection address of websocket, generally exists in the form of "ws://xxx/" or "wss://xxx/" |
| headers | dict | Additional headers that need to be added are used to allow users to pass additional headers in addition to the standard headers |
| debug | bool | The default is False, when it is True, the log will be output |



##### send data

> **ws_client.send(msg)**

- paramter

| parameter | type | illustrate |
| --------- | ---- | ------------ |
| msg | str | data to send |

- return value

None



##### recv data

> **ws_client.recv()**

- paramter

None

- return value

| return value | type | illustrate |
| ------------ | ---- | ------------------------------------------------------------ |
| result | str | The returned result is the result of recv. When a null value or None is accepted, the connection is closed. |



##### close connect

> **ws_client.close()**

- paramter

None

- return Value

None



##### Example of use

```python
from usr import uwebsocket
import _thread


def recv(cli):
while True:
# Infinite loop to receive data
recv_data = cli.recv()
print("recv_data = {}".format(recv_data))
if not recv_data:
# The server closes the connection or the client closes the connection
print("cli close")
client.close()
break


# Create a client, debug=True to output logs, ip and port need to be filled in by yourself, or a domain name
client = uwebsocket.Client.connect('ws://xxx/', debug=True)

# Thread receives data
_thread.start_new_thread(recv, (client,))

# send data
client.send("this is a test msg")

```





#### ussl-SSL Algorithm
Note: The BC25PA platform does not support this module function.

Expand Down
60 changes: 60 additions & 0 deletions zh-cn/api/QuecPythonClasslib.md
Original file line number Diff line number Diff line change
Expand Up @@ -12905,3 +12905,63 @@ if __name__ == '__main__':

```



#### uping-(ICMP)ping包

模块功能: 模拟发送icmp-ping包



##### ping

- 注意事项

这里可能会存在异常, 由于host地址无法简历socket连接的异常

通过初始化参数中的`COUNT`和`INTERVAL`来周期性的发送Ping包机制

> **import uping**
>
> **up = uping.ping(HOST, SOURCE=None, COUNT=4, INTERVAL=1000, SIZE=64, TIMEOUT=5000, quiet=False)**

- 参数

| 参数 | 类型 | 说明 |
| -------- | ---- | ------------------------------------------------------------ |
| HOST | str | 所要ping的域名地址, 例如"baidu.com" |
| SOURCE | str | 源地址, 用于绑定, 一般情况下不需要传 |
| COUNT | int | 默认是4次, 发送4次ping包 |
| INTERVAL | int | 间隔时间, 默认是ms单位, 默认1000ms |
| SIZE | int | 每次读取的包大小默认64, 无需修改 |
| TIMEOUT | int | 超时时间, 单位是ms单位, 默认是5000ms即5s |
| quiet | bool | 默认fasle,打印输出, 设置True后, 调用start的后得到的打印的值会被转换成对象返回, 而不是通过打印显示 |

使用示例

```python
# 方式一
# 打印输出方式
import uping
uping.ping('baidu.com')

# 以下是uping.start()的输出, 无返回值
#72 bytes from 49.49.48.46: icmp_seq=1, ttl=53, time=1169.909000 ms
#72 bytes from 49.49.48.46: icmp_seq=2, ttl=53, time=92.060000 ms
#72 bytes from 49.49.48.46: icmp_seq=3, ttl=53, time=94.818000 ms
#72 bytes from 49.49.48.46: icmp_seq=4, ttl=53, time=114.879000 ms
#4 packets transmitted, 4 packets received, 0 packet loss
#round-trip min/avg/max = 92.06000000000001/367.916/1169.909 ms




# 方式二
# 设置quiet会得到输出结果
import uping
result = uping.ping('baidu.com', quiet=True)
# result可以拿到对应数据
# result(tx=4, rx=4, losses=0, min=76.93899999999999, avg=131.348, max=226.697)

```

102 changes: 102 additions & 0 deletions zh-cn/api/QuecPythonThirdlib.md
Original file line number Diff line number Diff line change
Expand Up @@ -2270,6 +2270,108 @@ sys_bus.unsubscribe("test")
[uasyncio文档中心](https://python.quectel.com/doc/doc/Advanced_development/zh/QuecPythonThird/asyncio.html)



#### uwebsocket使用

模块: 主要用于websocket连接使用



##### 客户端连接

> **import uwebsocket**
>
> **ws_client = uwebsocket.Client.connect(uri, headers=None, debug=False)**

- 参数

| 参数 | 类型 | 说明 |
| ------- | ---- | ------------------------------------------------------------ |
| uri | str | websocket的连接地址, 一般以"ws://xxx/"或"wss://xxx/"形式存在 |
| headers | dict | 额外需要添加的headers, 用于除了标准连接头之外, 允许用户自己传额外的头部 |
| debug | bool | 默认False, 当为True的情况下, 会输出日志 |



##### send发送数据

> **ws_client.send(msg)**

- 参数

| 参数 | 类型 | 说明 |
| ---- | ---- | -------------- |
| msg | str | 需要发送的数据 |

- 返回值




##### recv接收数据

> **ws_client.recv()**

- 参数


- 返回值

| 返回值 | 类型 | 说明 |
| ------ | ---- | ------------------------------------------------------------ |
| result | str | 返回的结果, 就是recv的结果, 当接受空值或None的时候, 为连接被关闭 |



##### 关闭连接

> **ws_client.close()**

- 参数


- 返回值




##### 使用示例

```python
from usr import uwebsocket
import _thread


def recv(cli):
while True:
# 死循环接收数据
recv_data = cli.recv()
print("recv_data = {}".format(recv_data))
if not recv_data:
# 服务器关闭连接或客户端关闭连接
print("cli close")
client.close()
break


# 创建客户端, debug=True输出日志, ip和端口需要自己填写, 或者是域名
client = uwebsocket.Client.connect('ws://xxx/', debug=True)

# 线程接收数据
_thread.start_new_thread(recv, (client,))

# 发送数据
client.send("this is a test msg")

```




#### ussl-SSL算法

* 注意
Expand Down