Merge pull request #326 from HonestQiao/master
规范EVB_AIoT快速入门指南的目录层级,升级mqtt_config_gen.py工具脚本
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
# TencentOS tiny定制开发板EVB_AIoT快速入门指南
|
||||
# TencentOS tiny定制开发板EVB_AIoT快速入门指南
|
||||
|
||||
| Revision | Date | Description |
|
||||
| -------- | --------- | ----------- |
|
||||
@@ -117,9 +117,10 @@ https://www.nxp.com/design/software/development-software/mcuxpresso-software-and
|
||||
|
||||
|
||||
|
||||
## 三. 在EVB_AIoT开发板上移植TencentOS tiny内核
|
||||
## 三. 在EVB_AIoT开发板上移植TencentOS tiny内核
|
||||
|
||||
### 3.1 准备裸机工程
|
||||
|
||||
移植TencentOS Tiny内核前,我们先准备一个简单的点灯工程,这里跟前面的步骤一样,我们先使用MCUXpresso IDE 基于RT1060 SDK生成基础工程;
|
||||
|
||||

|
||||
@@ -181,9 +182,9 @@ https://www.nxp.com/design/software/development-software/mcuxpresso-software-and
|
||||
|
||||
接下来,我们在gpio_led_output.c添加TencentOS Tiny内核初始化和相关任务代码
|
||||
|
||||
#### 1. 包含内核头文件 #include "tos_k.h"
|
||||
#### 3.2.1 包含内核头文件 #include "tos_k.h"
|
||||
|
||||
#### 2. 添加Tick处理函数 SysTick_Handler ,代码如下:
|
||||
#### 3.2.2 添加Tick处理函数 SysTick_Handler ,代码如下:
|
||||
|
||||
```
|
||||
void SysTick_Handler(void)
|
||||
@@ -197,7 +198,7 @@ void SysTick_Handler(void)
|
||||
}
|
||||
```
|
||||
|
||||
#### 3.新建两个测试任务
|
||||
#### 3.2.3 新建两个测试任务
|
||||
|
||||
```
|
||||
#define TASK1_STK_SIZE 1024
|
||||
@@ -227,8 +228,7 @@ void task2_entry(void *arg)
|
||||
|
||||
```
|
||||
|
||||
|
||||
#### 4.在main函数后面增加操作系统初始化函数
|
||||
#### 3.2.4 在main函数后面增加操作系统初始化函数
|
||||
|
||||
```
|
||||
int main(void)
|
||||
@@ -258,13 +258,13 @@ int main(void)
|
||||
|
||||
```
|
||||
|
||||
#### 5.在工程里面配置TencentOS Tiny 头文件编译目录
|
||||
#### 3.2.5 在工程里面配置TencentOS Tiny 头文件编译目录
|
||||
|
||||
如图,需要在IDE里面配置TencentOS Tiny的编译头文件目录,按如图所示配置即可:
|
||||
|
||||

|
||||
|
||||
#### 6.修改tos_config.h文件
|
||||
#### 3.2.6 修改tos_config.h文件
|
||||
|
||||
```
|
||||
#ifndef _TOS_CONFIG_H_
|
||||
@@ -324,7 +324,7 @@ int main(void)
|
||||
|
||||
```
|
||||
|
||||
#### 7.编译下载测试
|
||||
#### 3.2.7 编译下载测试
|
||||
|
||||
编译完成下载到开发板,通过串口助手我们可以看到两个任务交替运行,打印task信息,说明内核移植成功,如下图所示:
|
||||
|
||||
@@ -342,14 +342,15 @@ int main(void)
|
||||
|
||||
二是:基于TencentOS Tiny完成终端应用开发,向腾讯云上报业务数据。
|
||||
|
||||
# 1. 云端操作步骤
|
||||
## 1.1. 新建项目
|
||||
### 4.1 云端操作步骤
|
||||
|
||||
#### 4.1.1 新建项目
|
||||
|
||||
登录[腾讯云物联网开发平台](https://cloud.tencent.com/product/iotexplorer),点击新建项目,填写项目名称和简介:
|
||||
|
||||

|
||||
|
||||
|
||||
## 1.2. 新建产品
|
||||
#### 4.1.2 新建产品
|
||||
|
||||
点击项目名称进入到该项目中,点击新建产品:
|
||||
|
||||
@@ -360,7 +361,8 @@ int main(void)
|
||||
|
||||

|
||||
|
||||
## 1.3. 数据模板
|
||||
#### 4.1.3 数据模板
|
||||
|
||||
进入产品,点击【物模型】,点击【导入物模型】,导入下面的JSON代码:
|
||||
```json
|
||||
{
|
||||
@@ -394,7 +396,8 @@ int main(void)
|
||||
|
||||

|
||||
|
||||
## 1.4. 创建设备
|
||||
#### 4.1.4 创建设备
|
||||
|
||||
点击【设备调试】,进入后点击【新建设备】,创建真实设备:
|
||||
|
||||

|
||||
@@ -403,8 +406,7 @@ int main(void)
|
||||
|
||||

|
||||
|
||||
|
||||
## 2. 基于TencentOS Tiny AIoT 开发板完成设备侧应用开发
|
||||
### 4.2 基于TencentOS Tiny AIoT 开发板完成设备侧应用开发
|
||||
|
||||
对接腾讯云物联网平台需要使用网络模块,我们开发板上有WAN Interface 可以扩展wifi 4G LoRa等等,这里我们扩展一个esp8266 wifi模块,如下图所示
|
||||
|
||||
@@ -425,14 +427,13 @@ int main(void)
|
||||
|
||||
打开工程后进入 < NXP_RT1062_TencentOS_Tiny_AIoT\source\mqttclient_iot_explorer.c> 源文件,根据您的网络环境和云端创建的产品设备信息修改终端参数。
|
||||
|
||||
### 2.1. 修改WIFI接入信息
|
||||
#### 4.2.1 修改WIFI接入信息
|
||||
|
||||
找到mqttclient_task函数,修改要接入WIFI的名称和密码(建议使用手机热点,不要有特殊字符):
|
||||
|
||||

|
||||
|
||||
|
||||
### 2.2. 修改云端对接信息
|
||||
#### 4.2.2 修改云端对接信息
|
||||
|
||||
终端的MQTT客户端需要对应的产品ID、设备ID,密码,我们从云端获取到对应的信息备用,如下图所示:
|
||||
|
||||
@@ -482,7 +483,7 @@ username = username.encode("utf-8")
|
||||
passwd = passwd.encode("utf-8")
|
||||
sign = hmacsha1(username, passwd)
|
||||
|
||||
template = ('#ifndef TOS_MQTT_CONFIG_H\n'
|
||||
template_header = ('#ifndef TOS_MQTT_CONFIG_H\n'
|
||||
'#define TOS_MQTT_CONFIG_H\n'
|
||||
'\n'
|
||||
'#define MQTT_SERVER_IP "111.230.189.156"\n'
|
||||
@@ -495,26 +496,55 @@ template = ('#ifndef TOS_MQTT_CONFIG_H\n'
|
||||
'#define MQTT_SUBSCRIBE_TOPIC "$product/$dev/$sub"\n'
|
||||
'#define MQTT_PUBLISH_TOPIC "$product/$dev/$pub"\n'
|
||||
'\n'
|
||||
'#define MQTT_SERVER_DOMAIN "$product.iotcloud.tencentdevices.com"\n'
|
||||
'#define MQTT_TOPIC "$product/$dev"\n'
|
||||
'#define MQTT_SUBSCRIBE_TOPIC_DOWN "$thing/down/property/$product/$dev"\n'
|
||||
'#define MQTT_PUBLISH_TOPIC_UP "$thing/up/property/$product/$dev"\n'
|
||||
'\n'
|
||||
'#endif\n'
|
||||
'\n')
|
||||
|
||||
src = Template(template)
|
||||
template_c = ('#ifndef TOS_MQTT_CONFIG_H\n'
|
||||
'tos_sal_module_parse_domain(MQTT_SERVER_DOMAIN,host_ip,sizeof(host_ip));\n'
|
||||
'\n'
|
||||
'mqtt_set_port(client, MQTT_SERVER_PORT);\n'
|
||||
'mqtt_set_host(client, host_ip);\n'
|
||||
'mqtt_set_client_id(client, MQTT_CLIENT_ID);\n'
|
||||
'mqtt_set_user_name(client, MQTT_USR_NAME);\n'
|
||||
'mqtt_set_password(client, MQTT_PASSWORD);\n'
|
||||
'mqtt_set_clean_session(client, 1);\n'
|
||||
'\n'
|
||||
'error = mqtt_subscribe(client, MQTT_SUBSCRIBE_TOPIC_DOWN, QOS0, tos_topic_handler);\n'
|
||||
'\n'
|
||||
'error = mqtt_publish(client, MQTT_PUBLISH_TOPIC_UP, &msg);\n'
|
||||
'\n'
|
||||
'#endif\n'
|
||||
'\n')
|
||||
|
||||
src_header = Template(template_header)
|
||||
src_c = Template(template_c)
|
||||
|
||||
d = {
|
||||
'product':product_id,
|
||||
'dev':dev_name,
|
||||
'sign':sign,
|
||||
'sub':sub,
|
||||
'pub':pub
|
||||
'pub':pub,
|
||||
'thing':'$thing'
|
||||
}
|
||||
|
||||
#do the substitution
|
||||
dst = src.substitute(d)
|
||||
dst_header = src_header.substitute(d)
|
||||
dst_c = src_c.substitute(d)
|
||||
print("===============Generate mqtt_config.h==================")
|
||||
print(dst)
|
||||
print(dst_header)
|
||||
with open('mqtt_config.h', 'w') as f:
|
||||
f.write(dst)
|
||||
f.write(dst_header)
|
||||
|
||||
print("===============Generate mqtt_connect_demo.c==================")
|
||||
print(dst_c)
|
||||
with open('mqtt_connect_demo.c', 'w') as f:
|
||||
f.write(dst_c)
|
||||
|
||||
```
|
||||
|
||||
@@ -527,19 +557,21 @@ with open('mqtt_config.h', 'w') as f:
|
||||
|
||||

|
||||
|
||||
最新版本的mqtt_config_gen.py将同时生成mqtt_config.h、mqtt_connect_demo.c文件,引入mqtt_config.h后,可直接复制mqtt_connect_demo.c中的示例代码,到mqttclient_task函数之中对应的部分。
|
||||
|
||||
#### 4.2.3 编译工程
|
||||
|
||||
### 2.3. 编译工程
|
||||
工程上右键,选择构建项目,编译整个工程:
|
||||
|
||||

|
||||
|
||||
### 2.4. 下载程序
|
||||
#### 4.2.4 下载程序
|
||||
|
||||
工程右键,选择调试方式,进入MCUXpresso IDE LinkServer CMSIS DAP ,下载程序到开发板并进行调试:
|
||||
|
||||

|
||||
|
||||
### 2.5. 使用串口助手查看日志
|
||||
#### 4.2.5 使用串口助手查看日志
|
||||
|
||||
运行sscom软件,打开电脑上开发板对应的串口,比如我选择COM6,点击【打开串口】:
|
||||
按下开发板上的复位键,程序开始运行,即可在串口助手中看到系统运行打印的日志:
|
||||
@@ -553,7 +585,8 @@ with open('mqtt_config.h', 'w') as f:
|
||||
|
||||

|
||||
|
||||
## 3. 云端平台查看设备数据
|
||||
### 4.3 云端平台查看设备数据
|
||||
|
||||
回到腾讯云物联网开发平台,可以看到设备状态变为【在线】:
|
||||
|
||||

|
||||
@@ -567,11 +600,14 @@ with open('mqtt_config.h', 'w') as f:
|
||||
|
||||

|
||||
|
||||
# 五、腾讯连连小程序操作步骤
|
||||
## 1. 添加家庭
|
||||
## 五、腾讯连连小程序操作步骤
|
||||
|
||||
### 5.1 添加家庭
|
||||
|
||||
手机端在【微信】搜索【腾讯连连】小程序,首次使用需要进入后点击【我的】->【家庭管理】,添加一个你喜欢的名称即可。
|
||||
|
||||
## 2. 添加调试设备
|
||||
### 5.2 添加调试设备
|
||||
|
||||
返回【首页】,点击右上角“加号”图标:
|
||||
|
||||

|
||||
|
@@ -37,7 +37,7 @@ username = username.encode("utf-8")
|
||||
passwd = passwd.encode("utf-8")
|
||||
sign = hmacsha1(username, passwd)
|
||||
|
||||
template = ('#ifndef TOS_MQTT_CONFIG_H\n'
|
||||
template_header = ('#ifndef TOS_MQTT_CONFIG_H\n'
|
||||
'#define TOS_MQTT_CONFIG_H\n'
|
||||
'\n'
|
||||
'#define MQTT_SERVER_IP "111.230.189.156"\n'
|
||||
@@ -50,22 +50,52 @@ template = ('#ifndef TOS_MQTT_CONFIG_H\n'
|
||||
'#define MQTT_SUBSCRIBE_TOPIC "$product/$dev/$sub"\n'
|
||||
'#define MQTT_PUBLISH_TOPIC "$product/$dev/$pub"\n'
|
||||
'\n'
|
||||
'#define MQTT_SERVER_DOMAIN "$product.iotcloud.tencentdevices.com"\n'
|
||||
'#define MQTT_TOPIC "$product/$dev"\n'
|
||||
'#define MQTT_SUBSCRIBE_TOPIC_DOWN "$thing/down/property/$product/$dev"\n'
|
||||
'#define MQTT_PUBLISH_TOPIC_UP "$thing/up/property/$product/$dev"\n'
|
||||
'\n'
|
||||
'#endif\n'
|
||||
'\n')
|
||||
|
||||
src = Template(template)
|
||||
template_c = ('#ifndef TOS_MQTT_CONFIG_H\n'
|
||||
'tos_sal_module_parse_domain(MQTT_SERVER_DOMAIN,host_ip,sizeof(host_ip));\n'
|
||||
'\n'
|
||||
'mqtt_set_port(client, MQTT_SERVER_PORT);\n'
|
||||
'mqtt_set_host(client, host_ip);\n'
|
||||
'mqtt_set_client_id(client, MQTT_CLIENT_ID);\n'
|
||||
'mqtt_set_user_name(client, MQTT_USR_NAME);\n'
|
||||
'mqtt_set_password(client, MQTT_PASSWORD);\n'
|
||||
'mqtt_set_clean_session(client, 1);\n'
|
||||
'\n'
|
||||
'error = mqtt_subscribe(client, MQTT_SUBSCRIBE_TOPIC_DOWN, QOS0, tos_topic_handler);\n'
|
||||
'\n'
|
||||
'error = mqtt_publish(client, MQTT_PUBLISH_TOPIC_UP, &msg);\n'
|
||||
'\n'
|
||||
'#endif\n'
|
||||
'\n')
|
||||
|
||||
src_header = Template(template_header)
|
||||
src_c = Template(template_c)
|
||||
|
||||
d = {
|
||||
'product':product_id,
|
||||
'dev':dev_name,
|
||||
'sign':sign,
|
||||
'sub':sub,
|
||||
'pub':pub
|
||||
'pub':pub,
|
||||
'thing':'$thing'
|
||||
}
|
||||
|
||||
#do the substitution
|
||||
dst = src.substitute(d)
|
||||
dst_header = src_header.substitute(d)
|
||||
dst_c = src_c.substitute(d)
|
||||
print("===============Generate mqtt_config.h==================")
|
||||
print(dst)
|
||||
print(dst_header)
|
||||
with open('mqtt_config.h', 'w') as f:
|
||||
f.write(dst)
|
||||
f.write(dst_header)
|
||||
|
||||
print("===============Generate mqtt_connect_demo.c==================")
|
||||
print(dst_c)
|
||||
with open('mqtt_connect_demo.c', 'w') as f:
|
||||
f.write(dst_c)
|
||||
|
Reference in New Issue
Block a user