|
@@ -0,0 +1,198 @@
|
|
|
+## 一,搭建Linux ESP-IDF开发环境,本博客不在叙述具体搭建过程,请参考网上教程。
|
|
|
+
|
|
|
+> ESP-IDF: 请切换到 release v4.2 tag 版本: `git checkout v4.2`
|
|
|
+
|
|
|
+> ESP8266_RTOS_SDK: 请切换到 v3.3 tag 版本: `git checkout v3.3`
|
|
|
+
|
|
|
+## 二,拉取官方阿里云生活物联网平台 & 天猫精灵 IoT 开放平台SDK开发版本
|
|
|
+
|
|
|
+拉取官方链接:git clone https://github.com/espressif/esp-ali-smartliving.git
|
|
|
+
|
|
|
+我个人码云链接: git clone https://gitee.com/http1520/esp-ali-smartliving.git
|
|
|
+
|
|
|
+拉取完成如下图:
|
|
|
+
|
|
|
+![image-20210826085500079](C:\Users\liuhao\AppData\Roaming\Typora\typora-user-images\image-20210826085500079.png)
|
|
|
+
|
|
|
+## 三,到阿里云生活物联网平台创建项目
|
|
|
+
|
|
|
+1,官方平台链接:[项目管理 - 生活物联网平台 (aliyun.com)](https://living.aliyun.com/) 创建可参考[创建项目 (aliyun.com)](https://help.aliyun.com/document_detail/126404.html) 一步一步进行配置。
|
|
|
+
|
|
|
+![image-20210826085958916](C:\Users\liuhao\AppData\Roaming\Typora\typora-user-images\image-20210826085958916.png)
|
|
|
+
|
|
|
+输入名称,选择品牌
|
|
|
+
|
|
|
+![image-20210826090057330](C:\Users\liuhao\AppData\Roaming\Typora\typora-user-images\image-20210826090057330.png)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+项目创建成功选择创建产品
|
|
|
+
|
|
|
+![image-20210826090253271](C:\Users\liuhao\AppData\Roaming\Typora\typora-user-images\image-20210826090253271.png)
|
|
|
+
|
|
|
+创建成功后进行功能配置,可以自行添加其他功能,我这里不做修改直接用默认功能测试
|
|
|
+
|
|
|
+![image-20210826090618093](C:\Users\liuhao\AppData\Roaming\Typora\typora-user-images\image-20210826090618093.png)
|
|
|
+
|
|
|
+输入产品信息,选择App,我这里选择公版App测试
|
|
|
+
|
|
|
+![image-20210826090854109](C:\Users\liuhao\AppData\Roaming\Typora\typora-user-images\image-20210826090854109.png)
|
|
|
+
|
|
|
+然后设置设备面板,先在手机上安装好云智能App,然后就可以通过扫描预览二维码进行查看了
|
|
|
+
|
|
|
+![image-20210826091015525](C:\Users\liuhao\AppData\Roaming\Typora\typora-user-images\image-20210826091015525.png)
|
|
|
+
|
|
|
+选择一个面板,也可以自定义面板,我这里直接选一个官方模板的测试
|
|
|
+
|
|
|
+![image-20210826091217962](C:\Users\liuhao\AppData\Roaming\Typora\typora-user-images\image-20210826091217962.png)
|
|
|
+
|
|
|
+设置配网信息。
|
|
|
+
|
|
|
+![image-20210826091348232](C:\Users\liuhao\AppData\Roaming\Typora\typora-user-images\image-20210826091348232.png)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+配置完成如下图
|
|
|
+
|
|
|
+![image-20210826091534859](C:\Users\liuhao\AppData\Roaming\Typora\typora-user-images\image-20210826091534859.png)
|
|
|
+
|
|
|
+然后新建一个测试设备,记录下这里的参数信息。
|
|
|
+
|
|
|
+![image-20210826091722421](C:\Users\liuhao\AppData\Roaming\Typora\typora-user-images\image-20210826091722421.png)
|
|
|
+
|
|
|
+## 四,配置SDK,编译烧录。
|
|
|
+
|
|
|
+### 1,编译 ali-smartliving-device-sdk-c 库
|
|
|
+
|
|
|
+ 找到esp-ali-smartliving 目录下执行:
|
|
|
+
|
|
|
+cd ali-smartliving-device-sdk-c
|
|
|
+
|
|
|
+![image-20210826093223834](C:\Users\liuhao\AppData\Roaming\Typora\typora-user-images\image-20210826093223834.png)
|
|
|
+
|
|
|
+再执行 make reconfig (选择SDK平台)
|
|
|
+
|
|
|
+![image-20210826093347711](C:\Users\liuhao\AppData\Roaming\Typora\typora-user-images\image-20210826093347711.png)
|
|
|
+
|
|
|
+make menuconfig (选择相关功能配置,默认不需要修改,该步骤可以省略)
|
|
|
+
|
|
|
+![image-20210826093502614](C:\Users\liuhao\AppData\Roaming\Typora\typora-user-images\image-20210826093502614.png)
|
|
|
+
|
|
|
+最后执行make (生成相关头文件和库文件) 等待编译完成
|
|
|
+
|
|
|
+![image-20210826093645812](C:\Users\liuhao\AppData\Roaming\Typora\typora-user-images\image-20210826093645812.png)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+### 2 编译 demo 例程
|
|
|
+
|
|
|
+在目录esp-ali-smartliving/config/mass_mfg下找到`single_mfg_config.csv`文件,复制重命名为`my_single_mfg_config.csv` 文件
|
|
|
+
|
|
|
+![image-20210826094011303](C:\Users\liuhao\AppData\Roaming\Typora\typora-user-images\image-20210826094011303.png)
|
|
|
+
|
|
|
+`修改my_single_mfg_config.csv` 文件内容,到阿里云平台找到四元组信息填好
|
|
|
+
|
|
|
+![image-20210826094433137](C:\Users\liuhao\AppData\Roaming\Typora\typora-user-images\image-20210826094433137.png)
|
|
|
+
|
|
|
+然后按照官方步骤执行以下命令生成nvs配置bin文件,
|
|
|
+
|
|
|
+```
|
|
|
+$IDF_PATH/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py --input my_single_mfg_config.csv --output my_single_mfg.bin --size 0x4000
|
|
|
+```
|
|
|
+
|
|
|
+我这里会一直出现错误,错误如下
|
|
|
+usage: nvs_partition_gen.py [-h] {generate,generate-key,encrypt,decrypt} …
|
|
|
+nvs_partition_gen.py: error: argument command: invalid choice: ‘my_single_mfg_config.csv’ (choose from ‘generate’, ‘generate-key’, ‘encrypt’, ‘decrypt’)
|
|
|
+实际原因是idf v4.0以上python的命令格式发生了改变
|
|
|
+**正确格式应该是:**
|
|
|
+
|
|
|
+```
|
|
|
+$IDF_PATH/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py generate my_single_mfg_config.csv my_single_mfg.bin 0x4000
|
|
|
+```
|
|
|
+
|
|
|
+
|
|
|
+![image-20210826095337698](C:\Users\liuhao\AppData\Roaming\Typora\typora-user-images\image-20210826095337698.png)
|
|
|
+
|
|
|
+生成bin文件后先烧录到ESP32执行以下命令:
|
|
|
+
|
|
|
+```
|
|
|
+$IDF_PATH/components/esptool_py/esptool/esptool.py write_flash 0x210000 my_single_mfg.bin
|
|
|
+```
|
|
|
+
|
|
|
+![image-20210826100707720](C:\Users\liuhao\AppData\Roaming\Typora\typora-user-images\image-20210826100707720.png)
|
|
|
+
|
|
|
+然后打开esp-ali-smartliving 目录下执行:
|
|
|
+
|
|
|
+```
|
|
|
+cd examples/solutions/smart_light
|
|
|
+```
|
|
|
+
|
|
|
+```
|
|
|
+make defconfig
|
|
|
+```
|
|
|
+
|
|
|
+![image-20210826095614119](C:\Users\liuhao\AppData\Roaming\Typora\typora-user-images\image-20210826095614119.png)
|
|
|
+
|
|
|
+执行make menuconfig命令配置烧录参数,可省略
|
|
|
+
|
|
|
+执行idf.py build命令执行编译工程,编译完成idf.py flash进行烧录
|
|
|
+
|
|
|
+![image-20210826100057852](C:\Users\liuhao\AppData\Roaming\Typora\typora-user-images\image-20210826100057852.png)
|
|
|
+
|
|
|
+执行命令查看串口打印信息,正常运行打印如下数据
|
|
|
+
|
|
|
+```
|
|
|
+idf.py monitor
|
|
|
+```
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+![image-20210826101512723](C:\Users\liuhao\AppData\Roaming\Typora\typora-user-images\image-20210826101512723.png)
|
|
|
+
|
|
|
+首次运行上电,默认就是配网状态下,可以看到如下信息:
|
|
|
+
|
|
|
+![image-20210826101714557](C:\Users\liuhao\AppData\Roaming\Typora\typora-user-images\image-20210826101714557.png)
|
|
|
+
|
|
|
+然后打开云智能App进行配网,也可以直接使用天猫精灵进行语音配网,我这里用app进行配置。找到之前的阿里云平台配置界面,点击配网+APP二维码这里。然后用手机先连接WiFi 再打开App进行扫描配置。
|
|
|
+
|
|
|
+![image-20210826101902854](C:\Users\liuhao\AppData\Roaming\Typora\typora-user-images\image-20210826101902854.png)
|
|
|
+
|
|
|
+扫描后弹出这个界面。扫描到后会提示进度。
|
|
|
+
|
|
|
+![image-20210826102351237](C:\Users\liuhao\AppData\Roaming\Typora\typora-user-images\image-20210826102351237.png)
|
|
|
+
|
|
|
+![image-20210826102457885](C:\Users\liuhao\AppData\Roaming\Typora\typora-user-images\image-20210826102457885.png)
|
|
|
+
|
|
|
+我们再查看设备端串口打印的调试数据,可以看到配网流程信息如下
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+![image-20210826102143454](C:\Users\liuhao\AppData\Roaming\Typora\typora-user-images\image-20210826102143454.png)
|
|
|
+
|
|
|
+然后点击手机上的开关指令可以看到设备端接收信息
|
|
|
+
|
|
|
+![image-20210826102722163](C:\Users\liuhao\AppData\Roaming\Typora\typora-user-images\image-20210826102722163.png)
|
|
|
+
|
|
|
+但是硬件上的灯并没有变化,这时我们需要打开源码查看是什么问题。查看源码发现开关指令的标识符不对与我们实际接收的不一致。需要在此处修改一下才行,是因为平台端的开关标识符默认是powerstate。同时下面的RGB标识符也需要修改一下,我这里采用HSV调光。
|
|
|
+
|
|
|
+![image-20210826103107781](C:\Users\liuhao\AppData\Roaming\Typora\typora-user-images\image-20210826103107781.png)
|
|
|
+
|
|
|
+![image-20210826105450577](C:\Users\liuhao\AppData\Roaming\Typora\typora-user-images\image-20210826105450577.png)
|
|
|
+
|
|
|
+修改后编译下载成功运行;
|
|
|
+
|
|
|
+![image-20210826110503020](C:\Users\liuhao\AppData\Roaming\Typora\typora-user-images\image-20210826110503020.png)
|
|
|
+
|
|
|
+![image-20210826110537323](C:\Users\liuhao\AppData\Roaming\Typora\typora-user-images\image-20210826110537323.png)
|
|
|
+
|
|
|
+相关IO口定义在lightbulb.c文件
|
|
|
+
|
|
|
+![image-20210826105937770](C:\Users\liuhao\AppData\Roaming\Typora\typora-user-images\image-20210826105937770.png)
|
|
|
+
|
|
|
+### 注意事项:
|
|
|
+
|
|
|
+1,四元组信息一定要设置好,并且成功烧录到对应NVS分区
|
|
|
+
|
|
|
+2,配网的WiFi一定要是2.4G频段的
|
|
|
+
|
|
|
+3,控制IO以及相关标识符要对应。
|