diff --git a/docs/Getting_started/zh/clouds/README.md b/docs/Getting_started/zh/clouds/README.md index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..edefdb2ae1c04ddbc2d629842faf1b07bbf5cdd9 100644 --- a/docs/Getting_started/zh/clouds/README.md +++ b/docs/Getting_started/zh/clouds/README.md @@ -0,0 +1,13 @@ +# 云平台对接应用开发 + +云平台对接应用开发主要介绍模组连接各个云平台的步骤和通信测试结果,本部分内容主要介绍基本概念和理论,实际操作验证通过文章最后的链接跳转到应用文档。 + +# 云平台对接应用开发文档目录 + +- [云平台对接-移远云连接教程](云平台对接-移远云连接教程.md) +- [云平台对接-阿里云连接教程](云平台对接-阿里云连接教程.md) +- [云平台对接-腾讯云连接教程](云平台对接-腾讯云连接教程.md) +- [云平台对接-华为云](云平台对接-华为云.md) +- [云平台对接-亚马逊云](云平台对接-亚马逊云.md) +- [云平台对接-移动云](云平台对接-移动云.md) +- [云平台对接-电信云](云平台对接-电信云.md) \ No newline at end of file diff --git a/docs/Getting_started/zh/clouds/aws.md b/docs/Getting_started/zh/clouds/aws.md new file mode 100644 index 0000000000000000000000000000000000000000..430758d69680c689b9d9426d28ea44d396636e54 --- /dev/null +++ b/docs/Getting_started/zh/clouds/aws.md @@ -0,0 +1,232 @@ +# 云平台对接-AWS应用开发 + +## 什么是云平台AWS + +AWS 全称Amazon web service(亚马逊网络服务),是亚马逊公司旗下云计算服务平台,为全世界各个国家和地区的客户提供一整套基础设施和云解决方案。 AWS面向用户提供包括弹性计算、存储、数据库、物联网在内的一整套云计算服务,帮助企业降低IT投入和维护成本,轻松上云 从概念是来看,AWS提供了一系列的托管产品,帮助我们在没有物理服务器的情况下,照样可以正常完成软件开发中的各种需求,也就是我们常说的云服务。 + +## 怎么使用云平台AWS + +#### 【进入平台】 + +[亚马逊云首页](https://amazonaws-china.com/cn/)点击【产品】---【物联网】---【AWS IoT Core】 + +![image-20230301153819079](../media/clouds/clouds.aws.01.png) + +![image-20230301154126556](../media/clouds/clouds.aws.02.png) + +![image-20230301154323459](../media/clouds/clouds.aws.03.png) + +#### 【创建策略】 + +![image-20230301154602272](../media/clouds/clouds.aws.04.png) + +![image-20230301155516253](../media/clouds/clouds.aws.05.png) + +#### 【创建物品】 + +![image-20230301161042093](../media/clouds/clouds.aws.06.png) + +![image-20230301161125928](../media/clouds/clouds.aws.07.png) + +![image-20230301161323026](../media/clouds/clouds.aws.08.png) + +![image-20230301161410209](../media/clouds/clouds.aws.09.png) + +![image-20230301161505534](../media/clouds/clouds.aws.10.png) + +![image-20230301161743688](../media/clouds/clouds.aws.11.png) + +![image-20230301161854690](../media/clouds/clouds.aws.12.png) + +至此完成“创建物品”。用证书连接AWS IoT平台,同一个证书可以用于多个设备,不同设备的Client ID保持唯一。 + + + +#### 【设备通信】 + +获取AWS服务器的MQTT连接地址、端口: + +![image-20230301163235249](../media/clouds/clouds.aws.13.png) + +使用MQTT.fx工具测试通信,在订阅主题栏填写“#”,表示接收所有主题。 + +![13](../media/clouds/clouds.aws.14.png) + +![12](../media/clouds/clouds.aws.15.png) + + + + + +### 软件应用 + +看到代码在创建MQTTClient的时间,设置了ssl=True,"cert": certificate_content,"key": private_content 等关键参数,其中证书是在AWS平台下载获取。 + +```python +from umqtt import MQTTClient +import modem +import _thread +import checkNet +import utime +from misc import Power + +CLIENT_ID = b'Chic_001' +SERVER = b'ambzd54j67b7h-ats.iot.us-west-2.amazonaws.com' +PORT = 8883 +USER = None # b'' +PASSWORD = None # b'' + +# 1. 数字证书 (certificate.crt) +# 2. 私钥 (private.pem) + +certificate_content = """ +-----BEGIN CERTIFICATE----- +MIIDWjCCAkKgAwIBAgIVAKxYi7zakXXKtbz5k2T72amn9k0GMA0GCSqGSIb3DQEB +CwUAME0xSzBJBgNVBAsMQkFtYXpvbiBXZWIgU2VydmljZXMgTz1BbWF6b24uY29t +IEluYy4gTD1TZWF0dGxlIFNUPVdhc2hpbmd0b24gQz1VUzAeFw0yMjA2MDYwNzU1 +MzNaFw00OTEyMzEyMzU5NTlaMB4xHDAaBgNVBAMME0FXUyBJb1QgQ2VydGlmaWNh +dGUwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDW9JpDiRLvYBt/62o7 +1fGfXG+MH9fC4+AnjPT1Kn4l1jKulEyix6ICGXL2+Ms77GXJrB+uIpMb4NgxG2D1 +qeA/xDKkh2QHXWvXsVf2KqWjRekprHLLNDWjZuig14cOhaDrIRlQfPoMMFsnehBZ +BUwyZZferg9u/GXor5hKAkLSpmCLsMAex6tn1f/ZpNwrrXABumLD+GX64L0XUla9 +kzj7b7qc2bSLirQVCmS44tk3Jvu2B3eS8Xf05CNkTLvdlHWhjepLtyDbukj9/HIJ ++CC0uYk7OYmfz85RhfVM0jbmFd2ebFS9yLnTsM0MZ/9weV/1NbEbQwwNnajKy3Q9 +LcsHAgMBAAGjYDBeMB8GA1UdIwQYMBaAFBruG06tF4R5Jac0d3Vq+WPmtW8hMB0G +A1UdDgQWBBSzpZijfWVvj/e9yy/+mYFP46lPgjAMBgNVHRMBAf8EAjAAMA4GA1Ud +DwEB/wQEAwIHgDANBgkqhkiG9w0BAQsFAAOCAQEAIxfbQzXNn8wnSOd/O1mEKdpu +nqw1FScwBSrKAx5IMb4LouOwl2OiLvPRNyCvKF5vVRsLHlCVFC2F4epJ2GgUhkid +rE0aiIACPgmtjF1vzHRU8nMOLKMsqE0gehw5zlqWaVKICIBe8ZrzTspipONeJL/B +MUWc5Jc1LoR37CmUKe2M//b3dh1Q4/aaSYEWG1J1cAk0mpKogBhJzK/JIsnzoW8D +Ho9pMvj8hdd5/PVx4Euj02IkG/uoxLqAcUu7TPotu5kTa5SWPhk7PANv84rlN5Xn +FyqMdt3hj3kHutTAv+MjAvjp/nmoi80NVEHhNlXYb2Cs4b877xxHMv/uzmZI7A== +-----END CERTIFICATE----- +""" + +private_content = """ +-----BEGIN RSA PRIVATE KEY----- +MIIEogIBAAKCAQEA1vSaQ4kS72Abf+tqO9Xxn1xvjB/XwuPgJ4z09Sp+JdYyrpRM +oseiAhly9vjLO+xlyawfriKTG+DYMRtg9angP8QypIdkB11r17FX9iqlo0XpKaxy +yzQ1o2booNeHDoWg6yEZUHz6DDBbJ3oQWQVMMmWX3q4Pbvxl6K+YSgJC0qZgi7DA +HserZ9X/2aTcK61wAbpiw/hl+uC9F1JWvZM4+2+6nNm0i4q0FQpkuOLZNyb7tgd3 +kvF39OQjZEy73ZR1oY3qS7cg27pI/fxyCfggtLmJOzmJn8/OUYX1TNI25hXdnmxU +vci507DNDGf/cHlf9TWxG0MMDZ2oyst0PS3LBwIDAQABAoIBAEqP7FbS3HOWRdO4 +iFAbJUYfHT5g6UncG6v8dBf61mkvhMMUBAVO9D6AL2XF5VFy7dfn0dFogtjfxH48 +PgTZGUVlPB/gKu13FWprRNTJ9EzPelKPU/5yrMxybO0l9d4usiP9hjdqMp45w9TM +vZDzinvMy8JdZFMeUAdHqa66XA2PL99kaRbptzWx3nX60auDMIIvzO7mORdl+TwU +AFX5VA7ixkIWl55gH45exU6U1Px93WeUaG05QtECtj69MjQevgcT+xJ8bk7qZYjD +nHsyuf3MRdt5mASNG29dA3/WIbBPfn+65RdZFNm2KdGV78pDsoLQEZJU+iGqPq2E +QNcZeBECgYEA9845Qo4O0adLxStNwBszSROWp2zmitF1dAEBb8Ycjdngy/XplwLO +0+1xJAyek2Vjam8oHEmvGNr3QUqlIIP8xKBZs2zZyxiYYo/E4h4J5QIV1uQL/Zqe +wE+2wfVCgfMhjOnXDPjuSyV9NkwQxYYsHQv4X6RKN3QrYysyqDVoDFkCgYEA3hBK +F2C9jm7OOO0M77EQGwAb4aSIlSfJFXcl6ef18Rgido2oiA3GssckorssxorGdnhj +0lIgFK84SPokGYFVc5xh93zL9hskSEyrHDceeVAfsnp/xTmwk4Z+ngJrfCpP6mrx +I8DGVxc2MgurXYsVS8Gx7zqmqe9Uvchf0qAcJl8CgYAifd/WdbN2VxTi0s41qROQ +Xluf3jaQp+rzRJiQmECtNeBmQ0pKLKfhM7GF1QPVfE1EKUip90+Z5BB6VAt75SMv +syoJIWOHM1syjNRYrNmvuISVrpRErlreZboIcTzanZ7T4FCAi72PVB6Dij7jX3OQ +b3QYy+NQqKjJWt/oLdbXsQKBgFO1rkhrxmkn6gNZkPPWOm0DOH9x567aZZn65Ubs +kzDEWVF5ixtmng2MtonFp1Zcv/2u2mpRXRiPCNexu+QFdjHztJZ36+clSiMbC7HC +MXGnu5srRHkTizXBkH9+CAixZpjGoYpJxDrWXC63aW0E3g1Fwg6dfHA48Sftnfmn +M5VfAoGAUUBGEbg7kImiSx1r357EMB2Vt4UwgWdY5idiaajYEJNSPIlrsBbi5WZH +X6R85MWT+UD9Y7FSiZo2acf/rO4CUWZcqSI22KgErBB4boBpwtVLMpF+MGFR9b5G +as/T8DAMikugyGkzogMGMZEK7DLfXwSA7VuiQ/uiSA3kMCLHesM= +-----END RSA PRIVATE KEY----- +""" + + +IMEI = None # modem.getDevImei() +SUB_TOPIC = '{}' +PUB_TOPIC = SUB_TOPIC + +def sub_cb(topic, msg): + global c + print( + "Subscribe Recv: Topic={},Msg={}".format( + topic.decode(), + msg.decode())) + + +def wait_msg(): + global c + while True: + if c is not None: + c.wait_msg() + # ret = c.get_mqttsta() + # print('wait_msg get_mqttsta:', ret) + utime.sleep_ms(100) + + +def MQTT_PUB(): + global c + while True: + try: + if c is not None: + c.publish(PUB_TOPIC.format(IMEI), "Hello World!") + # c.publish(PUB_TOPIC.format(IMEI), bytearray(b'\x30\x31\x32\x33\x00\x01\x02\x03')) + utime.sleep_ms(3000) + # ret = c.get_mqttsta() + # print('MQTT_PUB get_mqttsta:', ret) + except BaseException as e: + print('BaseException, Resatrting...', e) + + +def MQTT_Init(): + global c + + # 创建一个mqtt实例 + c = MQTTClient( + client_id=CLIENT_ID, + server=SERVER, + port=PORT, + user=USER, + password=PASSWORD, + keepalive=30, + ssl=True, + ssl_params={ + "cert": certificate_content, + "key": private_content}) + # 设置消息回调 + c.set_callback(sub_cb) + # 设置遗嘱消息 + c.set_last_will( + topic='set_last_will', + msg='set_last_will', + retain=False, + qos=1) + # 建立连接 + c.connect() + # 订阅主题 + c.subscribe(SUB_TOPIC.format(IMEI)) + # 发布消息 + c.publish(PUB_TOPIC.format(IMEI), "Hello World!") + + # 关闭连接 + # c.disconnect() + + +def GetDevImei(): + global IMEI + IMEI = modem.getDevImei() + print(IMEI) + + +def main(): + GetDevImei() + MQTT_Init() + _thread.start_new_thread(MQTT_PUB, ()) + _thread.start_new_thread(wait_msg, ()) + + +if __name__ == '__main__': + stagecode, subcode = checkNet.wait_network_connected(30) + print('stagecode = {}, subcode = {}'.format(stagecode, subcode)) + if stagecode == 3 and subcode == 1: + print('Network connection successful!') + else: + print('Not Net, Resatrting...') + utime.sleep_ms(200) + Power.powerRestart() + + main() + +``` + diff --git a/docs/Getting_started/zh/clouds/huawei.md b/docs/Getting_started/zh/clouds/huawei.md new file mode 100644 index 0000000000000000000000000000000000000000..cbfa3ff107981e4f65cfe7070d11d6116b288de8 --- /dev/null +++ b/docs/Getting_started/zh/clouds/huawei.md @@ -0,0 +1,265 @@ +# 云平台对接-华为云 + +## 什么是华为云平台 + +HuaweiCloud华为云,HuaweiCloud设备接入服务(IoTDA)是华为云的物联网平台,提供海量设备连接上云、设备和云端双向消息通信、批量设备管理、远程控制和监控、OTA升级、设备联动规则等能力,并可将设备数据灵活流转到华为云其他服务。 +下面主要从QuecPython的MQTT连接方式讲解,通过阅读本文,您将了解到QuecPython连接HuaweiCloud的过程操作和验证实验理论。 + +## 怎么使用云平台AWS + +### 云端设置 + +打开华为云连接 [www.huaweicloud.com](http://www.huaweicloud.com) + +### 进入平台 + +在首页点击【产品】---【IoT物联网】---【设备接入IoTDA】 + +![](../media/clouds/clouds.HuaweiCloud.01.png) + +### 创建产品 + +点击【产品】---【创建产品】 + +![](../media/clouds/clouds.HuaweiCloud.02.png) + +产品的“协议类型”选择MQTT + +![](../media/clouds/clouds.HuaweiCloud.03.png) + +产品【模型定义】 + +![](../media/clouds/clouds.HuaweiCloud.04.png) + +### 添加设备 + +点击【设备】---【所有设备】 + +> [https://console.huaweicloud.com/iotdm/?region=cn-north-4\#/dm-portal/device/all-device](https://console.huaweicloud.com/iotdm/?region=cn-north-4#/dm-portal/device/all-device) + +![](../media/clouds/clouds.HuaweiCloud.05.png) + +注册设备后自动生成的【设备ID】和【设备密钥】,记下来用于下一步骤生成连接平台的信息。 + +![](../media/clouds/clouds.HuaweiCloud.06.png) + +### 生成连接信息 + +访问[这里](https://iot-tool.obs-website.cn-north-4.myhuaweicloud.com/),填写[注册设备](https://support.huaweicloud.com/qs-iothub/iot_05_0006.html#ZH-CN_TOPIC_0251997880__li1261073102011)后生成的设备ID(DeviceId)和密钥(DeviceSecret),生成连接信息(ClientId、Username、Password)。 + + + +![](../media/clouds/clouds.HuaweiCloud.07.png) + +``` +CLIENT_ID = b'5fbbb784b4ec2202e982e643_868540050954037_0_0_2021011909' + +SERVER = b'a15fbbd7ce.iot-mqtts.cn-north-4.myhuaweicloud.com' + +PORT = 1883 + +USER = b'5fbbb784b4ec2202e982e643_868540050954037' + +PASSWORD =b'8001a12405743199b3396943a2ed397286117a9ebab4f5dfda8dd6fafe341d94' +``` + +![](../media/clouds/clouds.HuaweiCloud.08.png) + +![](../media/clouds/clouds.HuaweiCloud.09.png)说明: + +针对不支持用域名接入的设备,通过在cmd命令框中执行“ping +域名”获取IP地址,用IP地址接入平台。由于IP地址不固定,您需要将IP地址做成可配置项。 + +a15fbbd7ce.iot-mqtts.cn-north-4.myhuaweicloud.com + +1883 + +使用生成工具生成的clientId格式,默认不校验时间戳:设备ID_0_0\_时间戳。 + +- 当采用“HMACSHA256”校验时间戳方式时,会先校验消息时间戳与平台时间是否一致,再判断密码是否正确。 + +- 当采用“HMACSHA256”不校验时间戳方式时,鉴权消息也必须带时间戳,但不检验时间是否准确,仅判断密码是否正确。 + +### 上报数据 + +填写接口地址,此处以“\$oc/devices/{device_id}/sys/properties/report”为例,如“\$oc/devices/5e4e2e92ac-164aefa8fouquan1/sys/properties/report”。 + +![](../media/clouds/clouds.HuaweiCloud.10.png) + +\$oc/devices/{device_id}/sys/properties/report + +\$oc/devices/5fbbb784b4ec2202e982e643_868540050954037/sys/properties/report + +![](../media/clouds/clouds.HuaweiCloud.11.png) + +### 下发数据 + +下发数据只能通过应用端的API请求。 + +URI + +请求方法 POST + +URI /v5/iot/{project_id}/devices/{device_id}/messages + +传输协议 HTTPS + +下发数据说明: + + + +API调试页面: + + + +![](../media/clouds/clouds.HuaweiCloud.12.png) + +Topic: \$oc/devices/{device_id}/sys/messages/down + +\$oc/devices/5fbbb784b4ec2202e982e643_1234567890123456789/sys/messages/down + +![](../media/clouds/clouds.HuaweiCloud.13.png) + +### 下发命令 + +$oc/devices/{device_id}/sys/commands/request_id={request_id} + +- 设备侧订阅带{request_id}参数的topic时,可以使用通配#。如设备侧订阅命令下发请求的topic $oc/devices/{device_id}/sys/commands/request_id={request_id}时,可以用$oc/devices/{device_id}/sys/commands/# + +![](../media/clouds/clouds.HuaweiCloud.14.png) + +![](../media/clouds/clouds.HuaweiCloud.15.png) + +![](../media/clouds/clouds.HuaweiCloud.16.png) + +$oc/devices/{device_id}/sys/commands/request_id={request_id} + +$oc/devices/5fbbb784b4ec2202e982e643_869537055157730/sys/commands/# + +![](../media/clouds/clouds.HuaweiCloud.17.png) + +### 响应命令 + +下行: $oc/devices/{device_id}/sys/commands/request_id={request_id} + +上行:$oc/devices/{device_id}/sys/commands/response/request_id={request_id} + +平台下发命令后,需要设备及时将命令的执行结果返回给平台,如果设备没回响应,平台会认为命令执行超时。 + +![](../media/clouds/clouds.HuaweiCloud.18.png) + +## 软件设计 + +在HuaweiCloud平台取得ClientId、Username、Password之后,即可通过QuecPython的umqtt连接云平台,连接云平台的地址和端口固定不变,接下来就可以编写代码实验了。 + +示例代码: + +```python +import checkNet +from umqtt import MQTTClient +import modem +from machine import UART +import sim +import hmac +from hashlib import sha256 +import utime + +IMEI = modem.getDevImei() +E_SN = modem.getDevSN() +ESIM = sim.getImsi() + +DeviceName = IMEI +DeviceSecret = 'ac4263b86eaf6442997a' +DeviceID = "5fbbb784b4ec2202e982e643" + +CLIENT_ID = DeviceID + "_" + DeviceName + "_0_0_2022010507" +SERVER = "a15fbbd7ce.iot-mqtts.cn-north-4.myhuaweicloud.com" +PORT = 1883 +USER = DeviceID + "_" + DeviceName +PASSWORD = hmac.new( + "2022010507".encode('utf-8'), + DeviceSecret.encode('utf-8'), + digestmod=sha256).hexdigest() +DEVICE_ID = DeviceID + "_" + DeviceName + +state = 0 + +def sub_cb(topic, msg): + global state + global c + print( + "Subscribe Recv: Topic={},Msg={}".format( + topic.decode(), + msg.decode())) + topic = topic.decode() + msg = b'''{ + "result_code": 0 + }''' + if r'/sys/commands/request_id=' in topic: + c.publish('$oc/devices/{}/sys/commands/response/request_id={}'.format(DEVICE_ID,(topic.split("=")[-1])),msg) + state = 1 + + +def MQTT_Init(): + global c + c = MQTTClient( + client_id=CLIENT_ID, + server=SERVER, + port=PORT, + user=USER, + password=PASSWORD, + keepalive=30) + + c.set_callback(sub_cb) + try: + c.connect() + c.subscribe('$oc/devices/{}/sys/commands/#'.format(DEVICE_ID)) + + msg = b'''{ + "services": [{ + "service_id": "WaterMeterControl", + "properties": { + "state": "T:15c, H: 85% " + } + } + ] + }''' + c.publish('$oc/devices/{}/sys/properties/report'.format(DEVICE_ID), msg) + except BaseException: + print('except') + print('Waiting command') + while True: + c.wait_msg() + if state == 1: + utime.sleep_ms(300) + break + + c.disconnect() + + +def main(): + MQTT_Init() + + +if __name__ == "__main__": + main() + +``` + +接下来就可以下载验证了,python代码不需要编译,直接通过QPYcom工具把.py文件下载到模块中运行。 + +## 下载验证 + +下载.py文件到模组运行: + +![](../media/clouds/clouds.HuaweiCloud.19.png) + +下载之后,手动让脚本运行起来。 + +![](../media/clouds/clouds.HuaweiCloud.20.png) + +发送数据后,看到实验结果: + +![](../media/clouds/clouds.HuaweiCloud.21.png) + + diff --git a/docs/Getting_started/zh/clouds/tencent.md b/docs/Getting_started/zh/clouds/tencent.md new file mode 100644 index 0000000000000000000000000000000000000000..24692b9ed8bd000f8a329db4f97c40254251e659 --- /dev/null +++ b/docs/Getting_started/zh/clouds/tencent.md @@ -0,0 +1,191 @@ +# 云平台对接-腾讯云 + +## 什么是腾讯云平台 + +腾讯云物联网通信(Internet of Things Hub, IoT Hub)旨在提供一个安全、稳定、高效的连接平台,帮助开发者低成本、快速地实现“设备-设备”、“设备-用户应用”、“设备-云服务”之间可靠、高并发的数据通信。不仅可以实现设备之间的互动、设备的数据上报和配置下发,还可以基于规则引擎和腾讯云产品打通,方便快捷地实现海量设备数据的存储、计算以及智能分析。下面主要从MQTT连接方式讲解,通过阅读本文,您将了解到QuecPython连接TencentCloud的过程操作和验证实验理论。 + +## 怎么使用腾讯云平台 + + +腾讯云首页: + +### 进入平台 + +点击右上角的“控制台” + +![](../media/clouds/clouds.tencent.01.png) + +点击“云产品”---“物联网通信” + +![](../media/clouds/clouds.tencent.02.png) + +### 创建产品 + +在创建产品时的“认证方式”选择“密钥认证” + +![](../media/clouds/clouds.tencent.03.png) + +### 添加设备 + +1.点击图中的“产品名”进入添加设备界面 + +![TencentCloud_04](../media/clouds/clouds.tencent.04.png) + +2.按图操作添加设备 + +![TencentCloud_05](../media/clouds/clouds.tencent.05.png) + +### 生成连接信息 + +对于一机一密的话,三元组需要关注以下几点: + +**“productID”**位置如下(下图的3位置) + +![TencentCloud_06](../media/clouds/clouds.tencent.06.png) + +**“devicename”**和**“devicePsk”**位置如下(下图的3、4位置) + +![TencentCloud_07](../media/clouds/clouds.tencent.07.png) + +### 规则引擎 + +规则引擎用于主题消息转发,本文的规则引擎配置如下: + +规则引擎1(相同topic的规则转发): + +![TencentCloud_08](../media/clouds/clouds.tencent.08.png) + +规则引擎2(不同topic的规则转发): + +![TencentCloud_09](../media/clouds/clouds.tencent.09.png) + +## 软件设计 + +示例代码如下,在此做几点解释: + +(1)本代码使用腾讯云套件测试,对于一机一密的腾讯云连接只需要配置相应的三元组,即**productID、devicename、devicePsk**(具体如何找到对应的信息参考上面“**生成连接信息**”) + +(2)本代码做了两个简单的规则转发示例,具体原理是:代码中向**topic = "3ICA4ULOXI/QuecPython_test/data"**发布消息,同时会订阅到此主题的数据(原因是做了规则转发且此主题支持发布与订阅);代码中向**pub_topic = "3ICA4ULOXI/QuecPython_test/event"**发布消息,会订阅到**sub_topic = "3ICA4ULOXI/QuecPython_test/control"**主题的消息(原因是做了规则转发) + +```python + +import utime +import checkNet +from TenCentYun import TXyun +import _thread +import sys_bus + +class SYSTOPIC_Class(object): + RRPC = "rrpc" + OTA = "ota" + PUB = "pub" + SUB = "sub" + +class TXyun_Class(object): + def __init__(self): + self.productID = "X3Z30XABBU" # 产品标识 + self.devicename = "001" # 设备名称 + self.devicePsk = None # 设备密钥(一型一密认证此参数传入None) + self.ProductSecret = 'TeXbX8bZ40vutWHGxfUGJEZS' # 产品密钥(一机一密认证此参数传入None) + + # 输入自定义的Topic + self.subscribe_topic1 = 'X3Z30XABBU/{}/data'.format(self.devicename) + self.publish_topic1 = 'X3Z30XABBU/{}/data'.format(self.devicename) + + self.tenxun = TXyun( + self.productID, + self.devicename, + self.devicePsk, + self.ProductSecret) # 创建连接对象 + self.tenxun.setMqtt() # 设置mqtt + self.tenxun.setCallback(self.sub_cb) # 设置消息回调函数 + + def sub_cb(self, topic, msg): # 云端消息响应回调函数 + if topic.decode().find(SYSTOPIC.RRPC) != -1: + sys_bus.publish(SYSTOPIC.RRPC, {"topic": topic, "msg": msg}) + elif topic.decode().find(SYSTOPIC.OTA) != -1: + sys_bus.publish(SYSTOPIC.OTA, {"topic": topic, "msg": msg}) + else: + sys_bus.publish(SYSTOPIC.SUB, {"topic": topic, "msg": msg}) + + def TXyun_start(self): + # 运行 + self.tenxun.start() + print('start') + + def TXyun_subscribe_topic(self): + # 订阅主题 + self.tenxun.subscribe(self.subscribe_topic1, qos=0) + # self.tenxun.subscribe(self.subscribe_topic2, qos=0) + + def TXyun_publish(self, topic, msg): + try: + self.tenxun.publish(msg.get('topic'), msg.get("msg"), qos=0) + except BaseException: + print('!!!!!!!!!!发送失败') + +class Handler(object): + @classmethod + def sub(cls, topic, msg): + print( + "Subscribe Recv: Topic={},Msg={}".format( + msg.get('topic').decode(), + msg.get("msg").decode())) + + @classmethod + def pub(cls, msg): + while True: + sys_bus.publish(SYSTOPIC.PUB, msg) + utime.sleep_ms(2000) + + @classmethod + def ota(cls, topic, msg): + """处理完ota的信息后,同步发送""" + msg = {"topic": "xxx", "msg": "xxx"} + """同步publish,同步情况下会等待所有topic对应的处理函数处理完才会退出""" + sys_bus.publish_sync(SYSTOPIC.PUB, msg) + + @classmethod + def rrpc(cls, topic, msg): + """发布rrpc执行下列操作""" + msg = {"topic": "xxx", "msg": "xxx"} + """异步publish, """ + sys_bus.publish(SYSTOPIC.PUB, msg) + +if __name__ == '__main__': + PROJECT_NAME = "QuecPython" + PROJECT_VERSION = "1.0.0" + checknet = checkNet.CheckNetwork(PROJECT_NAME, PROJECT_VERSION) + checknet.poweron_print_once() + checknet.wait_network_connected() + + TXyunClass = TXyun_Class() + TXyunClass.TXyun_subscribe_topic() + + SYSTOPIC = SYSTOPIC_Class() + sys_bus.subscribe(SYSTOPIC.RRPC, Handler.rrpc) + sys_bus.subscribe(SYSTOPIC.OTA, Handler.ota) + sys_bus.subscribe(SYSTOPIC.SUB, Handler.sub) + sys_bus.subscribe(SYSTOPIC.PUB, TXyunClass.TXyun_publish) + + msg = '{{"DeviceName":"{}","msg":"test publish"}}'.format(TXyunClass.devicename) + tuple = ({"topic": TXyunClass.publish_topic1, "msg": msg},) + _thread.start_new_thread(Handler.pub, tuple) + + TXyunClass.TXyun_start() + +``` + +接下来就可以下载验证了,QuecPython代码不需要编译,直接通过QPYcom工具把.py文件下载到模块中运行。 + +## 下载验证 + +下载.py文件到模组中: + +![TencentCloud_10](../media/clouds/clouds.tencent.10.png) + +下载之后,手动让脚本运行起来,查看现象如下。 + +![TencentCloud_11](../media/clouds/clouds.tencent.11.png) + + diff --git a/docs/Getting_started/zh/hardware-advanced/ext-wifi.md b/docs/Getting_started/zh/hardware-advanced/ext-wifi.md new file mode 100644 index 0000000000000000000000000000000000000000..6780e21cd109b3086253c85b58c82142f3e72190 --- /dev/null +++ b/docs/Getting_started/zh/hardware-advanced/ext-wifi.md @@ -0,0 +1,165 @@ +# 外挂WiFi应用开发 + +## 什么是外挂WiFi + +由于模组主要功能是4G联网,自身并不具备WiFi联网功能,而对于某些应用场景既需要4G又需要WiFi,就可以用模组+外挂ESP8266来实现。 + +## 怎么使用外挂WiFi + +### 硬件设计 + +准备一块模组和ESP8266,模组的UART:Rx、Tx、GND和ESP8266的Tx、Rx、GND交叉对接,注意电平需要匹配。本次实验使用的是“封”开发板,板子上的UART1和ESP8266已经连接好,可以直接使用。 + +![核心板_封](../../zh/media/hardware-advanced/ext-wifi/hardware-advanced.ext-wifi.01.jpg) + +应用电路可以参考QuecPython的开发板,开发板可以通过天猫旗舰店、京东旗舰店等移远通信官方销售渠道获取,开发板的硬件设计同样是参考的上述硬件文档。 + +### 软件应用 + +模组搭配ESP8266实现ap模式、station模式,还可以提供给用户配网的web模式。作为station模式时,还可以设置网卡走4G还是走WiFi。 + + +## 外挂WiFi功能测试 + +以下逐个功能演示, +ap模式: + +把ap.py和 WLAN.py文件下载到usr区,执行ap.py即可看到实验现象。 + +```python +from usr.WLAN import ESP8266 +from machine import UART +import dataCall + +# 初始化esp8266网卡 +esp8266 = ESP8266(UART.UART1, ESP8266.AP) +# 启动esp8266以ap模式启动 +esp8266.ap('Chic_ap', '123456999') +# 获取当前网卡状态 4表示网卡已启用,可以进行下一步操作 +# 0: esp8266设备不存在 +# 1: esp8266 station模式已连接 +# 2: esp8266 station模式未连接 +# 3: esp8266 web配网模式 +# 4: esp8266 ap模式 +esp8266.status() +# 获取拨号信息 +Info = dataCall.getInfo(1, 0) +# 设置默认网卡 +esp8266.set_default_NIC(Info[2][2]) +# 添加路由信息,设置网卡转发规则,默认ap的网段192.168.4.0,子网掩码255.255.255.0 +esp8266.router_add('192.168.4.0', '255.255.255.0') + +# esp8266.ipconfig() +# esp8266.stop() + +''' +UART.UART1 +''' +``` + +![image-20230227171405884](../../zh/media/hardware-advanced/ext-wifi/hardware-advanced.ext-wifi.02.jpg) + +![image-20230227171659764](../../zh/media/hardware-advanced/ext-wifi/hardware-advanced.ext-wifi.03.jpg) + + + +station模式: + +```python +from usr.WLAN import ESP8266 +from machine import UART + + +# 初始化esp8266网卡 +esp8266=ESP8266(UART.UART1, ESP8266.STA) +# 启动esp8266以staion模式启动 +esp8266.station('iPhone 12 mini', '123456999') +# esp8266.station('QQ', '123456999') +# 获取当前网卡状态 4表示网卡已启用,可以进行下一步操作 +# 0: esp8266设备不存在 +# 1: esp8266 station模式已连接 +# 2: esp8266 station模式未连接 +# 3: esp8266 web配网模式 +# 4: esp8266 ap模式 +esp8266.status() +# 设置dns服务器地址 +esp8266.set_dns('8.8.8.8', '114.114.114.114') +# 设置esp8266作为默认网卡,使用esp8266进行网络连接 +ip = esp8266.ipconfig()[0] +esp8266.set_default_NIC(ip) + +# esp8266.ipconfig() +# esp8266.stop() + +''' +UART.UART1 +''' +``` + +![image-20230227172655914](../../zh/media/hardware-advanced/ext-wifi/hardware-advanced.ext-wifi.04.jpg) + +执行station.py后,可查询连接状态,返回1: esp8266 station模式已连接 + +```python +>>> esp8266.status() +1 +>>> +``` + +![image-20230227172557721](../../zh/media/hardware-advanced/ext-wifi/hardware-advanced.ext-wifi.05.jpg) + + + +web模式: + +```python +from usr.WLAN import ESP8266 +from machine import UART + +# 初始化esp8266网卡 +#若使用web配置ap模式,需把以下模式ESP8266设置为ESP8266.AP +esp8266=ESP8266(UART.UART1, ESP8266.STA) +# 使esp8266以web配网模式启动 +esp8266.web_config('Chic_web','123456999') # 配网网址:192.168.4.1 +# 获取当前网卡状态 返回4表示已连接,可以使用esp8266进行下一步操作 +# 0: esp8266设备不存在 +# 1: esp8266 station模式已连接 +# 2: esp8266 station模式未连接 +# 3: esp8266 web配网模式 +# 4: esp8266 ap模式 +esp8266.status() +# 获取当前网卡状态 返回3表示web配网已启用,可以使用web配网模式 + +#使用手机等设备连接热点,使用浏览器进入网址192.168.4.1,进行配网 + +# esp8266.ipconfig() +# esp8266.stop() + +''' +UART.UART1 +''' +``` + +执行web.py之后,终端可以连接'Chic_web','123456999',通过192.168.4.1进入web配网界面。 +也可以通过http请求方式取代web界面, +使用get,http://192.168.4.1 +使用post,http://192.168.4.1/ap_set 具体参数设置参考以下截图 +使用post,http://192.168.4.1/station_set 具体参数设置参考以下截图 + +web配网之后ESP8266会自动重启连接,之后每次上电ESP8266就会自动连接。 + +![Web配网_GET](../../zh/media/hardware-advanced/ext-wifi/hardware-advanced.ext-wifi.GET.png) + + + + + +![Web配网_ap](../../zh/media/hardware-advanced/ext-wifi/hardware-advanced.ext-wifi.ap.png) + + + + + +![Web配网_sta](../../zh/media/hardware-advanced/ext-wifi/hardware-advanced.ext-wifi.sta.png) + + diff --git a/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.01.png b/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.01.png new file mode 100644 index 0000000000000000000000000000000000000000..116e135897e5d13c552cb5585082407fa21a3ba8 Binary files /dev/null and b/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.01.png differ diff --git a/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.02.png b/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.02.png new file mode 100644 index 0000000000000000000000000000000000000000..a3184158813ec1d9242e0f83ad4291d76850da2c Binary files /dev/null and b/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.02.png differ diff --git a/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.03.png b/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.03.png new file mode 100644 index 0000000000000000000000000000000000000000..593edb06dc739392e1287e27d3d562ecf611391f Binary files /dev/null and b/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.03.png differ diff --git a/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.04.png b/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.04.png new file mode 100644 index 0000000000000000000000000000000000000000..01a227cbe82cf134ab4f81bd92da838a8bb9c112 Binary files /dev/null and b/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.04.png differ diff --git a/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.05.png b/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.05.png new file mode 100644 index 0000000000000000000000000000000000000000..574ea533f50387429d5bf9527e5dfe65750f47ec Binary files /dev/null and b/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.05.png differ diff --git a/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.06.png b/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.06.png new file mode 100644 index 0000000000000000000000000000000000000000..fc2d09cab274976edc9787de1a67b2f09b603f01 Binary files /dev/null and b/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.06.png differ diff --git a/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.07.png b/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.07.png new file mode 100644 index 0000000000000000000000000000000000000000..3ce8dba29dc342d6a0b73ae9b117ebdc5ebaff2d Binary files /dev/null and b/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.07.png differ diff --git a/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.08.png b/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.08.png new file mode 100644 index 0000000000000000000000000000000000000000..fa2214a3a466023a5e1bf54f08943fd127954da3 Binary files /dev/null and b/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.08.png differ diff --git a/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.09.png b/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.09.png new file mode 100644 index 0000000000000000000000000000000000000000..df147d9da57578ffef1cfa85003d774bbede4fef Binary files /dev/null and b/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.09.png differ diff --git a/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.10.png b/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.10.png new file mode 100644 index 0000000000000000000000000000000000000000..f37e7170efb5b5c930f2e5c243ba4cb9da78d47e Binary files /dev/null and b/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.10.png differ diff --git a/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.11.png b/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.11.png new file mode 100644 index 0000000000000000000000000000000000000000..e1791a501541aaea933e6e95453ae062788c5b08 Binary files /dev/null and b/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.11.png differ diff --git a/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.12.png b/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.12.png new file mode 100644 index 0000000000000000000000000000000000000000..d8530ddb48142490b6b0fec199e2c9355f6745e8 Binary files /dev/null and b/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.12.png differ diff --git a/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.13.png b/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.13.png new file mode 100644 index 0000000000000000000000000000000000000000..73d636b418908539572692a738d02e7f07fb842d Binary files /dev/null and b/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.13.png differ diff --git a/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.14.png b/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.14.png new file mode 100644 index 0000000000000000000000000000000000000000..01a227cbe82cf134ab4f81bd92da838a8bb9c112 Binary files /dev/null and b/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.14.png differ diff --git a/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.15.png b/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.15.png new file mode 100644 index 0000000000000000000000000000000000000000..f3321f2c42bfedb25099e7e844fc8c291bc81cf4 Binary files /dev/null and b/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.15.png differ diff --git a/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.16.png b/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.16.png new file mode 100644 index 0000000000000000000000000000000000000000..7191c5a0eae88a817c5ca081e6ee876a92498058 Binary files /dev/null and b/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.16.png differ diff --git a/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.17.png b/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.17.png new file mode 100644 index 0000000000000000000000000000000000000000..d0dd7e798bb5132dd5dafd78aa014db808aed362 Binary files /dev/null and b/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.17.png differ diff --git a/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.18.png b/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.18.png new file mode 100644 index 0000000000000000000000000000000000000000..33aa567c84ae286f3e50a647d2604f013ea95311 Binary files /dev/null and b/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.18.png differ diff --git a/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.19.png b/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.19.png new file mode 100644 index 0000000000000000000000000000000000000000..9db5dc3e42cd55b4695113e5855b01d5fb7a0b3c Binary files /dev/null and b/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.19.png differ diff --git a/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.20.png b/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.20.png new file mode 100644 index 0000000000000000000000000000000000000000..7010a833dcc92b0f7c97536a123c9c0625677ad2 Binary files /dev/null and b/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.20.png differ diff --git a/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.21.png b/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.21.png new file mode 100644 index 0000000000000000000000000000000000000000..6951edbd76729b57d914f7f1fd977cfbe5dee741 Binary files /dev/null and b/docs/Getting_started/zh/media/clouds/clouds.HuaweiCloud.21.png differ diff --git a/docs/Getting_started/zh/media/clouds/clouds.aws.01.png b/docs/Getting_started/zh/media/clouds/clouds.aws.01.png new file mode 100644 index 0000000000000000000000000000000000000000..813d35c1b3a291132384fd2830f61d0e4ba4dd27 Binary files /dev/null and b/docs/Getting_started/zh/media/clouds/clouds.aws.01.png differ diff --git a/docs/Getting_started/zh/media/clouds/clouds.aws.02.png b/docs/Getting_started/zh/media/clouds/clouds.aws.02.png new file mode 100644 index 0000000000000000000000000000000000000000..ea2489091ae1474006eea8de5c49ab0d2609f264 Binary files /dev/null and b/docs/Getting_started/zh/media/clouds/clouds.aws.02.png differ diff --git a/docs/Getting_started/zh/media/clouds/clouds.aws.03.png b/docs/Getting_started/zh/media/clouds/clouds.aws.03.png new file mode 100644 index 0000000000000000000000000000000000000000..d14144b6b22f27473e52951c87ed859dde192c5c Binary files /dev/null and b/docs/Getting_started/zh/media/clouds/clouds.aws.03.png differ diff --git a/docs/Getting_started/zh/media/clouds/clouds.aws.04.png b/docs/Getting_started/zh/media/clouds/clouds.aws.04.png new file mode 100644 index 0000000000000000000000000000000000000000..8bb158e663f68649cdfbbb04e5a930044b37c730 Binary files /dev/null and b/docs/Getting_started/zh/media/clouds/clouds.aws.04.png differ diff --git a/docs/Getting_started/zh/media/clouds/clouds.aws.05.png b/docs/Getting_started/zh/media/clouds/clouds.aws.05.png new file mode 100644 index 0000000000000000000000000000000000000000..310681b5213a39746f719144a85630df9f7389c9 Binary files /dev/null and b/docs/Getting_started/zh/media/clouds/clouds.aws.05.png differ diff --git a/docs/Getting_started/zh/media/clouds/clouds.aws.06.png b/docs/Getting_started/zh/media/clouds/clouds.aws.06.png new file mode 100644 index 0000000000000000000000000000000000000000..a4c7bbc2dc7904a5cf6d101d923eafbfcef61d4c Binary files /dev/null and b/docs/Getting_started/zh/media/clouds/clouds.aws.06.png differ diff --git a/docs/Getting_started/zh/media/clouds/clouds.aws.07.png b/docs/Getting_started/zh/media/clouds/clouds.aws.07.png new file mode 100644 index 0000000000000000000000000000000000000000..d7b11a1ac6f3478d6a97dc6d1b3083c8fda4bfa5 Binary files /dev/null and b/docs/Getting_started/zh/media/clouds/clouds.aws.07.png differ diff --git a/docs/Getting_started/zh/media/clouds/clouds.aws.08.png b/docs/Getting_started/zh/media/clouds/clouds.aws.08.png new file mode 100644 index 0000000000000000000000000000000000000000..c7b5c51fbc627a0b5a397eb89dd3bc325768d0e4 Binary files /dev/null and b/docs/Getting_started/zh/media/clouds/clouds.aws.08.png differ diff --git a/docs/Getting_started/zh/media/clouds/clouds.aws.09.png b/docs/Getting_started/zh/media/clouds/clouds.aws.09.png new file mode 100644 index 0000000000000000000000000000000000000000..68eeecd8088498da7ce215e0df3605f48171d479 Binary files /dev/null and b/docs/Getting_started/zh/media/clouds/clouds.aws.09.png differ diff --git a/docs/Getting_started/zh/media/clouds/clouds.aws.10.png b/docs/Getting_started/zh/media/clouds/clouds.aws.10.png new file mode 100644 index 0000000000000000000000000000000000000000..395a9176f8e3f9e939616fd42e4604d81c6d4d84 Binary files /dev/null and b/docs/Getting_started/zh/media/clouds/clouds.aws.10.png differ diff --git a/docs/Getting_started/zh/media/clouds/clouds.aws.11.png b/docs/Getting_started/zh/media/clouds/clouds.aws.11.png new file mode 100644 index 0000000000000000000000000000000000000000..fedc518e47091a91fa4dddf768b40f24ddc50cdd Binary files /dev/null and b/docs/Getting_started/zh/media/clouds/clouds.aws.11.png differ diff --git a/docs/Getting_started/zh/media/clouds/clouds.aws.12.png b/docs/Getting_started/zh/media/clouds/clouds.aws.12.png new file mode 100644 index 0000000000000000000000000000000000000000..2615399d47b78a9f9cf0982410b552d45ab09cd5 Binary files /dev/null and b/docs/Getting_started/zh/media/clouds/clouds.aws.12.png differ diff --git a/docs/Getting_started/zh/media/clouds/clouds.aws.13.png b/docs/Getting_started/zh/media/clouds/clouds.aws.13.png new file mode 100644 index 0000000000000000000000000000000000000000..4c4017d127e1c356bb9f6331485b39d638e5c848 Binary files /dev/null and b/docs/Getting_started/zh/media/clouds/clouds.aws.13.png differ diff --git a/docs/Getting_started/zh/media/clouds/clouds.aws.14.png b/docs/Getting_started/zh/media/clouds/clouds.aws.14.png new file mode 100644 index 0000000000000000000000000000000000000000..9cdea6e45f0dd590284eb192340a44a3850ae743 Binary files /dev/null and b/docs/Getting_started/zh/media/clouds/clouds.aws.14.png differ diff --git a/docs/Getting_started/zh/media/clouds/clouds.aws.15.png b/docs/Getting_started/zh/media/clouds/clouds.aws.15.png new file mode 100644 index 0000000000000000000000000000000000000000..da0e93167b0be9269b18fdf709325db2822c80bd Binary files /dev/null and b/docs/Getting_started/zh/media/clouds/clouds.aws.15.png differ diff --git a/docs/Getting_started/zh/media/clouds/clouds.tencent.01.png b/docs/Getting_started/zh/media/clouds/clouds.tencent.01.png new file mode 100644 index 0000000000000000000000000000000000000000..bca31f7c3d9c355a025b55dcf44e9402320b7b4b Binary files /dev/null and b/docs/Getting_started/zh/media/clouds/clouds.tencent.01.png differ diff --git a/docs/Getting_started/zh/media/clouds/clouds.tencent.02.png b/docs/Getting_started/zh/media/clouds/clouds.tencent.02.png new file mode 100644 index 0000000000000000000000000000000000000000..d9a17a43beb7cbe5c93e6b2c23d9201efc02c186 Binary files /dev/null and b/docs/Getting_started/zh/media/clouds/clouds.tencent.02.png differ diff --git a/docs/Getting_started/zh/media/clouds/clouds.tencent.03.png b/docs/Getting_started/zh/media/clouds/clouds.tencent.03.png new file mode 100644 index 0000000000000000000000000000000000000000..18f747eb1f19a4d70f8a8209f03b8a8a527a3aa3 Binary files /dev/null and b/docs/Getting_started/zh/media/clouds/clouds.tencent.03.png differ diff --git a/docs/Getting_started/zh/media/clouds/clouds.tencent.04.png b/docs/Getting_started/zh/media/clouds/clouds.tencent.04.png new file mode 100644 index 0000000000000000000000000000000000000000..65165d065f21cc9208bd7502056e9aefb8681da3 Binary files /dev/null and b/docs/Getting_started/zh/media/clouds/clouds.tencent.04.png differ diff --git a/docs/Getting_started/zh/media/clouds/clouds.tencent.05.png b/docs/Getting_started/zh/media/clouds/clouds.tencent.05.png new file mode 100644 index 0000000000000000000000000000000000000000..976686be43d2e706a1f11b01ea196b0edeadba35 Binary files /dev/null and b/docs/Getting_started/zh/media/clouds/clouds.tencent.05.png differ diff --git a/docs/Getting_started/zh/media/clouds/clouds.tencent.06.png b/docs/Getting_started/zh/media/clouds/clouds.tencent.06.png new file mode 100644 index 0000000000000000000000000000000000000000..a585f37f051468351371bd5cdc4de67feacd1e85 Binary files /dev/null and b/docs/Getting_started/zh/media/clouds/clouds.tencent.06.png differ diff --git a/docs/Getting_started/zh/media/clouds/clouds.tencent.07.png b/docs/Getting_started/zh/media/clouds/clouds.tencent.07.png new file mode 100644 index 0000000000000000000000000000000000000000..3006aa251e810b4deb90dec7a8d1036a399b990b Binary files /dev/null and b/docs/Getting_started/zh/media/clouds/clouds.tencent.07.png differ diff --git a/docs/Getting_started/zh/media/clouds/clouds.tencent.08.png b/docs/Getting_started/zh/media/clouds/clouds.tencent.08.png new file mode 100644 index 0000000000000000000000000000000000000000..89f801b39feaffcc98551876e6cc698cb1bb1a57 Binary files /dev/null and b/docs/Getting_started/zh/media/clouds/clouds.tencent.08.png differ diff --git a/docs/Getting_started/zh/media/clouds/clouds.tencent.09.png b/docs/Getting_started/zh/media/clouds/clouds.tencent.09.png new file mode 100644 index 0000000000000000000000000000000000000000..d9793b34bcdb6bf42ec94edd3b0d83c40cb81e3b Binary files /dev/null and b/docs/Getting_started/zh/media/clouds/clouds.tencent.09.png differ diff --git a/docs/Getting_started/zh/media/clouds/clouds.tencent.10.png b/docs/Getting_started/zh/media/clouds/clouds.tencent.10.png new file mode 100644 index 0000000000000000000000000000000000000000..9184302934e851a613c116b14152f447f5e78267 Binary files /dev/null and b/docs/Getting_started/zh/media/clouds/clouds.tencent.10.png differ diff --git a/docs/Getting_started/zh/media/clouds/clouds.tencent.11.png b/docs/Getting_started/zh/media/clouds/clouds.tencent.11.png new file mode 100644 index 0000000000000000000000000000000000000000..f2c10af8807fc62afc6308dea0d32d2c8ac12854 Binary files /dev/null and b/docs/Getting_started/zh/media/clouds/clouds.tencent.11.png differ diff --git a/docs/Getting_started/zh/media/hardware-advanced/ext-wifi/hardware-advanced.ext-wifi.01.jpg b/docs/Getting_started/zh/media/hardware-advanced/ext-wifi/hardware-advanced.ext-wifi.01.jpg new file mode 100644 index 0000000000000000000000000000000000000000..1f92b6520f189ae0037cefa70c8008be439b55f5 Binary files /dev/null and b/docs/Getting_started/zh/media/hardware-advanced/ext-wifi/hardware-advanced.ext-wifi.01.jpg differ diff --git a/docs/Getting_started/zh/media/hardware-advanced/ext-wifi/hardware-advanced.ext-wifi.02.jpg b/docs/Getting_started/zh/media/hardware-advanced/ext-wifi/hardware-advanced.ext-wifi.02.jpg new file mode 100644 index 0000000000000000000000000000000000000000..d4196b06373d34d30d78a482e7654443b47c3f48 Binary files /dev/null and b/docs/Getting_started/zh/media/hardware-advanced/ext-wifi/hardware-advanced.ext-wifi.02.jpg differ diff --git a/docs/Getting_started/zh/media/hardware-advanced/ext-wifi/hardware-advanced.ext-wifi.03.jpg b/docs/Getting_started/zh/media/hardware-advanced/ext-wifi/hardware-advanced.ext-wifi.03.jpg new file mode 100644 index 0000000000000000000000000000000000000000..ad156e1078bcb54cea149e83bae049c40f173319 Binary files /dev/null and b/docs/Getting_started/zh/media/hardware-advanced/ext-wifi/hardware-advanced.ext-wifi.03.jpg differ diff --git a/docs/Getting_started/zh/media/hardware-advanced/ext-wifi/hardware-advanced.ext-wifi.04.jpg b/docs/Getting_started/zh/media/hardware-advanced/ext-wifi/hardware-advanced.ext-wifi.04.jpg new file mode 100644 index 0000000000000000000000000000000000000000..41c73c1ec599677fe93e0363e70e2df924063b0c Binary files /dev/null and b/docs/Getting_started/zh/media/hardware-advanced/ext-wifi/hardware-advanced.ext-wifi.04.jpg differ diff --git a/docs/Getting_started/zh/media/hardware-advanced/ext-wifi/hardware-advanced.ext-wifi.05.jpg b/docs/Getting_started/zh/media/hardware-advanced/ext-wifi/hardware-advanced.ext-wifi.05.jpg new file mode 100644 index 0000000000000000000000000000000000000000..c1d7801947daf5573b8cafa4945ac1c830e52f56 Binary files /dev/null and b/docs/Getting_started/zh/media/hardware-advanced/ext-wifi/hardware-advanced.ext-wifi.05.jpg differ diff --git a/docs/Getting_started/zh/media/hardware-advanced/ext-wifi/hardware-advanced.ext-wifi.GET.png b/docs/Getting_started/zh/media/hardware-advanced/ext-wifi/hardware-advanced.ext-wifi.GET.png new file mode 100644 index 0000000000000000000000000000000000000000..ef15e9959e9c4cb22dff990fcad6a64ba9cea98d Binary files /dev/null and b/docs/Getting_started/zh/media/hardware-advanced/ext-wifi/hardware-advanced.ext-wifi.GET.png differ diff --git a/docs/Getting_started/zh/media/hardware-advanced/ext-wifi/hardware-advanced.ext-wifi.ap.png b/docs/Getting_started/zh/media/hardware-advanced/ext-wifi/hardware-advanced.ext-wifi.ap.png new file mode 100644 index 0000000000000000000000000000000000000000..b8bd8587762c8efb21231fb9b6f7ac8068e55da3 Binary files /dev/null and b/docs/Getting_started/zh/media/hardware-advanced/ext-wifi/hardware-advanced.ext-wifi.ap.png differ diff --git a/docs/Getting_started/zh/media/hardware-advanced/ext-wifi/hardware-advanced.ext-wifi.sta.png b/docs/Getting_started/zh/media/hardware-advanced/ext-wifi/hardware-advanced.ext-wifi.sta.png new file mode 100644 index 0000000000000000000000000000000000000000..d03bdf1d54feb0bb691fa18f92b3af6d552c9a39 Binary files /dev/null and b/docs/Getting_started/zh/media/hardware-advanced/ext-wifi/hardware-advanced.ext-wifi.sta.png differ diff --git a/docs/Getting_started/zh/media/os/os.log.jpg b/docs/Getting_started/zh/media/os/os.log.jpg new file mode 100644 index 0000000000000000000000000000000000000000..ec8957a1c8b6c5427b3cc8bf80f76922ccc5e02b Binary files /dev/null and b/docs/Getting_started/zh/media/os/os.log.jpg differ diff --git a/docs/Getting_started/zh/media/os/os.ram.jpg b/docs/Getting_started/zh/media/os/os.ram.jpg new file mode 100644 index 0000000000000000000000000000000000000000..ed774bef991df583248f3a14fcacd3b33c76579d Binary files /dev/null and b/docs/Getting_started/zh/media/os/os.ram.jpg differ diff --git a/docs/Getting_started/zh/media/os/thread/os.thread.thread_c.png b/docs/Getting_started/zh/media/os/thread/os.thread.thread_c.png new file mode 100644 index 0000000000000000000000000000000000000000..e84107a49481f4e822eea1652a84180e6342b125 Binary files /dev/null and b/docs/Getting_started/zh/media/os/thread/os.thread.thread_c.png differ diff --git a/docs/Getting_started/zh/media/os/thread/os.thread.thread_mutu.png b/docs/Getting_started/zh/media/os/thread/os.thread.thread_mutu.png new file mode 100644 index 0000000000000000000000000000000000000000..05f76571f08c16fa8c36e966b0a7c849fb7a168d Binary files /dev/null and b/docs/Getting_started/zh/media/os/thread/os.thread.thread_mutu.png differ diff --git a/docs/Getting_started/zh/media/os/thread/os.thread.thread_queue.png b/docs/Getting_started/zh/media/os/thread/os.thread.thread_queue.png new file mode 100644 index 0000000000000000000000000000000000000000..9896a301f381c4843277fdf012debb71d5f451f5 Binary files /dev/null and b/docs/Getting_started/zh/media/os/thread/os.thread.thread_queue.png differ diff --git a/docs/Getting_started/zh/os/log.md b/docs/Getting_started/zh/os/log.md new file mode 100644 index 0000000000000000000000000000000000000000..d3451c26803d69e64491cd546ff6757c1e729208 --- /dev/null +++ b/docs/Getting_started/zh/os/log.md @@ -0,0 +1,36 @@ +# 日志功能 +## 什么是日志功能 + +本文介绍如何使用QuecPython的日志功能,使用日志功能可以让应用程序在执行过程中输出相关的内部信息,以供观察程序运行过程是否有异常。 + +## 怎么使用日志功能 + +### 软件应用 + +使用QuecPython开发的模组,调用log模块中的log.getLogger()可以获取logger对象,具体参数参考[log功能的API介绍文档](/../../API_reference/zh/QuecPython组件库/log.html)。 + +```python +import log +log.basicConfig(level=log.INFO) +Testlog = log.getLogger("TestLog") + +# 设置输出到debug口 +from machine import UART +uart = UART(UART.UART0, 115200, 8, 0, 1, 0) + +log.set_output(uart) +Testlog.info("this is a Test log") # 会输出带对应的uart口 + + +# 从uart口切换成交互口输出 +import usys +log.set_output(usys.stdout) +Testlog.info("this is a Test log") # 会输出到交互口 +``` + + +## 日志功能测试 + +使用QPYcom工具执行代码,可以看出QPYcom和串口调试助手都有打印信息。 + +![image-20230321153800938](../media/os/os.log.jpg) \ No newline at end of file diff --git a/docs/Getting_started/zh/os/ram.md b/docs/Getting_started/zh/os/ram.md new file mode 100644 index 0000000000000000000000000000000000000000..fb80c79cc8aed036458b425ec6aa25155c14de83 --- /dev/null +++ b/docs/Getting_started/zh/os/ram.md @@ -0,0 +1,38 @@ +# 内存管理 +## 什么是内存管理 + +本文介绍如何使用QuecPython的内存管理功能,内存管理可以让应用程序重复循环使用RAM。 + +## 怎么使用内存管理 + +### 软件应用 + +使用QuecPython开发的模组,调用gc模块中的gc.collect()可以手动回收一次内存,具体参数参考[gc功能的API介绍文档](/../../API_reference/zh/QuecPython标准库/gc.html),创建线程不会阻塞当前代码往下执行。 + +```python +import gc + +ret = gc.mem_free() +print('Current remaining memory',ret) + +a = bytes(100*1024) +ret = gc.mem_free() +print('After requesting 100K of memory',ret) + +del a +ret = gc.mem_free() +print('Variable not freed after deletion',ret) + +ret = gc.collect() +ret = gc.mem_free() +print('After manually reclaiming memory',ret) +``` + + + +## gc功能测试 + +使用QPYcom工具执行代码,从输出信息中可以看出gc.collect()后回收了内存。 + +![image-20230321173659592](../media/os/os.ram.jpg) + diff --git a/docs/Getting_started/zh/os/thread/thread_c.md b/docs/Getting_started/zh/os/thread/thread_c.md new file mode 100644 index 0000000000000000000000000000000000000000..19b981a94c83d9d0c197d8d2561e8e46d265ab21 --- /dev/null +++ b/docs/Getting_started/zh/os/thread/thread_c.md @@ -0,0 +1,39 @@ +# 多线程-创建线程 +## 什么是多线程 + +本文介绍如何使用QuecPython的多线程功能,多线程可以让应用程序的多个功能看起来在同时运行。 + +## 怎么使用多线程 + +### 软件应用 + +使用QuecPython开发的模组,调用\_thread模块中的_thread.start_new_thread()可以创建新线程,具体参数参考[_thread功能的API介绍文档](/../../API_reference/zh/QuecPython标准库/_thread-多线程.html),创建线程不会阻塞当前代码往下执行。 + +```python +import utime +import _thread + +def thread_1(): + while True: + for i in range(10): + print('thread_1', i) + utime.sleep_ms(1000) + +def thread_2(): + while True: + for i in range(10): + print('thread_2', i) + utime.sleep_ms(1000) + +_thread.start_new_thread(thread_1, ()) +_thread.start_new_thread(thread_2, ()) +``` +注意:线程里需要调用utime.sleep代码才能上下文切换。 + + +## _thread功能测试 + +使用QPYcom工具执行代码,可以看出两条线程在打印信息。 + +![](../../media/os/thread/os.thread.thread_c.png) + diff --git a/docs/Getting_started/zh/os/thread/thread_mutu.md b/docs/Getting_started/zh/os/thread/thread_mutu.md new file mode 100644 index 0000000000000000000000000000000000000000..58ca52c32a7f8fc9b7cc5ab83e3a94f5e91ed561 --- /dev/null +++ b/docs/Getting_started/zh/os/thread/thread_mutu.md @@ -0,0 +1,44 @@ +# 多线程-互斥锁应用 +## 什么是多线程-互斥锁 + +本文介绍如何使用QuecPython的多线程-互斥锁功能,互斥锁可以资源不会冲突,通常用于保护硬件接口通信的完整性,如SPI、I2C通信命令要严格的指令顺序才能正确通信。 + +## 怎么使用多线程-互斥锁 + +### 软件应用 + +使用QuecPython开发的模组,调用\_thread模块中的_thread.allocate_lock()可以创建互斥锁,具体参数参考[_thread功能的API介绍文档](/../../API_reference/zh/QuecPython标准库/_thread-多线程.html),互斥锁必须成对使用。 + +```python +import utime +import _thread + +def thread_1(): + while True: + for i in range(3): + lock.acquire() + print('thread_1', i) + utime.sleep_ms(2000) + lock.release() + +def thread_2(): + while True: + for i in range(3): + lock.acquire() + print('thread_2', i) + utime.sleep_ms(2000) + lock.release() + +lock = _thread.allocate_lock() +_thread.start_new_thread(thread_1, ()) +_thread.start_new_thread(thread_2, ()) +``` +注意:线程里调用lock.acquire后进入阻塞并切换上下文,直到系统获得锁立即往下执行,lock.release()释放锁,有等待锁的线程会立即执行。 + + +## _thread功能测试 + +使用QPYcom工具执行代码,可以看出两条线程在打印信息,值得注意的是执行到utime.sleep_ms(2000)的时候并没有切换线程,是因为锁还没释放。 + +![](../../media/os/thread/os.thread.thread_mutu.png) + diff --git a/docs/Getting_started/zh/os/thread/thread_queue.md b/docs/Getting_started/zh/os/thread/thread_queue.md new file mode 100644 index 0000000000000000000000000000000000000000..4a5554b74a75fd8ea115cc8fdc9023904ef023fb --- /dev/null +++ b/docs/Getting_started/zh/os/thread/thread_queue.md @@ -0,0 +1,44 @@ +# 多线程-消息队列 +## 什么是多线程-消息队列 + +本文介绍如何使用QuecPython的多线程-消息队列功能,消息队列用于线程间通信,如A是中断回调线程接收数据,B是普通线程处理数据,A线程把接收到的数据通过Queue发送到B线程后立即结束A线程,从而减少A线程占用CPU的时间。 + +## 怎么使用多线程-消息队列 + +### 软件应用 + +使用QuecPython开发的模组,调用queue模块中的queue.Queue()可以创建消息队列,具体参数参考[queue功能的API介绍文档](/../../API_reference/zh/QuecPython标准库/Queue - 普通队列.html),获取队列数据时,若队列有数据则立即返回,否则进入阻塞并切换上下文,直到队列有数据才继续往下执行。 + +```python +import _thread +from queue import Queue +import utime + +# 初始化队列 +q = Queue(maxsize=100) + +def thread_get(): + while True: + # q.get 会阻塞等待消息过来,每当有q.put()执行完后 q.get()会收到数据,解除阻塞往下执行 + item = q.get() + print("q.get:", item) + +# 开启线程在哪等待消息 +_thread.start_new_thread(thread_get, ()) +# put消息到队列 +q.put(1) +utime.sleep(1) +q.put() # 空数据默认 None +utime.sleep(1) +q.put(None) # 空数据默认 None +utime.sleep(1) +q.put(3) +``` + + +## queue功能测试 + +使用QPYcom工具执行代码,可以看出每当q.put()数据后,等待消息的线程立即执行打印数据。 + +![](../../media/os/thread/os.thread.thread_queue.png) + diff --git a/docs/Getting_started/zh/sidebar.yaml b/docs/Getting_started/zh/sidebar.yaml index 9b53f50148c369135ce54f3b1690d39564adaadc..26c9c89b532d4e35296d7c53e0e004a00e5781a0 100644 --- a/docs/Getting_started/zh/sidebar.yaml +++ b/docs/Getting_started/zh/sidebar.yaml @@ -59,8 +59,15 @@ items: - label: '4.7: 内存管理' file: os/ram.md - label: '4.8: 多线程' - file: os/threads.md - + file: os/thread/README.md + items: + - label: '4.8.1: 多线程' + file: os/thread/thread_c.md + - label: '4.8.2: 多线程' + file: os/thread/thread_mutu.md + - label: '4.8.3: 多线程' + file: os/thread/thread_queue.md + - label: '5: QuecPython 硬件基础功能' file: hardware-basic/README.md items: