diff --git a/docs/API_reference/en/networklib/umqtt.md b/docs/API_reference/en/networklib/umqtt.md index 40e42e56b6450f9133e0343275e661d92ffd9da0..375778c3b820aa7718c71d5f390a542d501b11ea 100644 --- a/docs/API_reference/en/networklib/umqtt.md +++ b/docs/API_reference/en/networklib/umqtt.md @@ -15,7 +15,7 @@ QoS2 – Only once. Highest level. The message is guaranteed to be received by t ### `MQTTClient` ```python -MQTTClient(client_id, server, port=0, user=None, password=None, keepalive=0, ssl=False, ssl_params={},reconn=True,version=4) +MQTTClient(client_id, server, port=0, user=None, password=None, keepalive=60, ssl=False, ssl_params={},reconn=True,version=4) ``` Creates MQTT clients. @@ -29,7 +29,7 @@ Creates MQTT clients. | port | Integer | Server port (optional). Default value: 1883. The default port of MQTT over SSL/TLS is 8883. | | user | String | Username registered on the server (optional). | | password | String | Password registered on the server (optional). | -| keepalive | Integer | Timeout of keep-alive (optional). Default value: 0. Unit: s. | +| keepalive | Integer | Timeout of keep-alive (optional). Default value: 60. Unit: s. | | ssl | bool | Enable or disable SSL/TSL encryption. | | ssl_params | String | SSL/TLS parameter (optional). | | reconn | bool | Enable or disable the internal reconnection mechanism (optional). Default value: True (enable). | @@ -251,6 +251,8 @@ MQTTClient.wait_msg() Blocks waiting for a message response from the MQTT server. +>If this method is called in a thread, it is necessary to ensure that the thread stack created is >= 16K. For details, please refer to the mqtt reconnection sample code. + * Parameter None @@ -381,6 +383,7 @@ import net import _thread import checkNet import dataCall +import uos from umqtt import MQTTClient PROJECT_NAME = "QuecPython_MQTT_example" @@ -552,7 +555,18 @@ class MqttClient(): return -1 def loop_forever(self): + task_stacksize =_thread.stack_size() + name,platform = uos.uname()[1].split("=",1) + if platform == "EC600E" or platform == "EC800E": + _thread.stack_size(8 * 1024) + elif platform == "FCM362K": + _thread.stack_size(3 * 1024) + else: + _thread.stack_size(16 * 1024) + # Before creating a thread, modify the thread stack space according to the platform. _thread.start_new_thread(self.__listen, ()) + # After the thread is created successfully, the platform thread stack default size is restored. + _thread.stack_size(task_stacksize) if __name__ == '__main__': ''' diff --git a/docs/API_reference/zh/networklib/umqtt.md b/docs/API_reference/zh/networklib/umqtt.md index 5358e766c9e8c588510a704b1de2813b5668d183..ca074da9cd1f83d55175bf07e73b57614c40fdc2 100644 --- a/docs/API_reference/zh/networklib/umqtt.md +++ b/docs/API_reference/zh/networklib/umqtt.md @@ -15,7 +15,7 @@ QoS2 – 有且仅有一次,是最高级别;保证消息送达且仅送达 ### `umqtt.MQTTClient` ```python -class umqtt.MQTTClient(client_id, server, port=0, user=None, password=None, keepalive=0, ssl=False, ssl_params={},reconn=True,version=4) +class umqtt.MQTTClient(client_id, server, port=0, user=None, password=None, keepalive=60, ssl=False, ssl_params={},reconn=True,version=4) ``` 构建mqtt连接对象。 @@ -32,7 +32,7 @@ class umqtt.MQTTClient(client_id, server, port=0, user=None, password=None, keep * `password` - (可选) 在服务器上注册的密码,字符串类型。 -* `keepalive` - (可选)客户端的keepalive超时值,整数类型,默认为0。 +* `keepalive` - (可选)客户端的keepalive超时值,整数类型,默认为60。 * `ssl` - (可选)是否使能 SSL/TLS 支持,布尔值类型。 @@ -222,6 +222,7 @@ MQTTClient.wait_msg() 阻塞等待服务器消息响应。 +>该方法如果在线程中调用时,需保证创建线程栈空间>=16K,具体请参照mqtt重连示例代码. ### `MQTTClient.get_mqttsta` @@ -339,6 +340,7 @@ import net import _thread import checkNet import dataCall +import uos from umqtt import MQTTClient PROJECT_NAME = "QuecPython_MQTT_example" @@ -510,7 +512,18 @@ class MqttClient(): return -1 def loop_forever(self): + task_stacksize =_thread.stack_size() + name,platform = uos.uname()[1].split("=",1) + if platform == "EC600E" or platform == "EC800E": + _thread.stack_size(8 * 1024) + elif platform == "FCM362K": + _thread.stack_size(3 * 1024) + else: + _thread.stack_size(16 * 1024) + # 创建线程之前,按照平台,修改线程栈空间。 _thread.start_new_thread(self.__listen, ()) + # 线程创建成功后,恢复平台线程栈默认大小。 + _thread.stack_size(task_stacksize) if __name__ == '__main__': ''' diff --git a/docs/Application_guide/zh/network-comm/net-protocols/README.md b/docs/Application_guide/zh/network-comm/net-protocols/README.md deleted file mode 100644 index b678e1880dade231caf5f8efef0d58980ed5e76b..0000000000000000000000000000000000000000 --- a/docs/Application_guide/zh/network-comm/net-protocols/README.md +++ /dev/null @@ -1,10 +0,0 @@ -# 网络协议应用指导 - -该部分文档主要包含 TCP/UDP、HTTP、MQTT、FTP 等协议的应用指导,文档内容囊括协议讲解、应用场景、应用流程、疑难解答等部分,深入浅出地对网络应用协议做了讲解。 - -该部分文档的目录如下: - -- [TCP/UDP 协议应用指导](./tcp-udp.md) -- [HTTP 协议应用指导](./http.md) -- [MQTT 协议应用指导](./mqtt.md) -- [FTP 协议应用指导](./ftp.md)