|
@@ -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
|
|
|
+
|
|
|
+拉取完成如下图:
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+## 三,到阿里云生活物联网平台创建项目
|
|
|
+
|
|
|
+1,官方平台链接:[项目管理 - 生活物联网平台 (aliyun.com)](https://living.aliyun.com/) 创建可参考[创建项目 (aliyun.com)](https://help.aliyun.com/document_detail/126404.html) 一步一步进行配置。
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+输入名称,选择品牌
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+项目创建成功选择创建产品
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+创建成功后进行功能配置,可以自行添加其他功能,我这里不做修改直接用默认功能测试
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+输入产品信息,选择App,我这里选择公版App测试
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+然后设置设备面板,先在手机上安装好云智能App,然后就可以通过扫描预览二维码进行查看了
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+选择一个面板,也可以自定义面板,我这里直接选一个官方模板的测试
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+设置配网信息。
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+配置完成如下图
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+然后新建一个测试设备,记录下这里的参数信息。
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+## 四,配置SDK,编译烧录。
|
|
|
+
|
|
|
+### 1,编译 ali-smartliving-device-sdk-c 库
|
|
|
+
|
|
|
+ 找到esp-ali-smartliving 目录下执行:
|
|
|
+
|
|
|
+cd ali-smartliving-device-sdk-c
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+再执行 make reconfig (选择SDK平台)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+make menuconfig (选择相关功能配置,默认不需要修改,该步骤可以省略)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+最后执行make (生成相关头文件和库文件) 等待编译完成
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+### 2 编译 demo 例程
|
|
|
+
|
|
|
+在目录esp-ali-smartliving/config/mass_mfg下找到`single_mfg_config.csv`文件,复制重命名为`my_single_mfg_config.csv` 文件
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+`修改my_single_mfg_config.csv` 文件内容,到阿里云平台找到四元组信息填好
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+然后按照官方步骤执行以下命令生成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
|
|
|
+```
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+生成bin文件后先烧录到ESP32执行以下命令:
|
|
|
+
|
|
|
+```
|
|
|
+$IDF_PATH/components/esptool_py/esptool/esptool.py write_flash 0x210000 my_single_mfg.bin
|
|
|
+```
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+然后打开esp-ali-smartliving 目录下执行:
|
|
|
+
|
|
|
+```
|
|
|
+cd examples/solutions/smart_light
|
|
|
+```
|
|
|
+
|
|
|
+```
|
|
|
+make defconfig
|
|
|
+```
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+执行make menuconfig命令配置烧录参数,可省略
|
|
|
+
|
|
|
+执行idf.py build命令执行编译工程,编译完成idf.py flash进行烧录
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+执行命令查看串口打印信息,正常运行打印如下数据
|
|
|
+
|
|
|
+```
|
|
|
+idf.py monitor
|
|
|
+```
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+首次运行上电,默认就是配网状态下,可以看到如下信息:
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+然后打开云智能App进行配网,也可以直接使用天猫精灵进行语音配网,我这里用app进行配置。找到之前的阿里云平台配置界面,点击配网+APP二维码这里。然后用手机先连接WiFi 再打开App进行扫描配置。
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+扫描后弹出这个界面。扫描到后会提示进度。
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+我们再查看设备端串口打印的调试数据,可以看到配网流程信息如下
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+然后点击手机上的开关指令可以看到设备端接收信息
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+但是硬件上的灯并没有变化,这时我们需要打开源码查看是什么问题。查看源码发现开关指令的标识符不对与我们实际接收的不一致。需要在此处修改一下才行,是因为平台端的开关标识符默认是powerstate。同时下面的RGB标识符也需要修改一下,我这里采用HSV调光。
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+修改后编译下载成功运行;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+相关IO口定义在lightbulb.c文件
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+### 注意事项:
|
|
|
+
|
|
|
+1,四元组信息一定要设置好,并且成功烧录到对应NVS分区
|
|
|
+
|
|
|
+2,配网的WiFi一定要是2.4G频段的
|
|
|
+
|
|
|
+3,控制IO以及相关标识符要对应。
|