6 Star 72 Fork 27

一个杀手/smart_control

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

智能遥控器(在线版)

本项目实现了红外遥控、红外学习的功能,实现对空调等支持红外遥控电器的控制。除此之外,还支持通过语音、手机BLE小程序与遥控器交互。另外还支持天气播报、闹钟提醒、温度检测功能,并支持通过MQTT客户端将本地温度数据上传到华为云。

仓库目录

doc:说明文档

main:用户代码

audio:音频代码

app:应用代码

ir_decoder:红外码库代码

network:网络、蓝牙相关代码

periph:外设驱动代码

picture:图片

tools:使用到的工具

mp3:MP3离线音频

spiffs:文件系统,存放二进制码库 etymology_anallyze:百度词法分析定制文件

partitions.csv:分区表

一、程序框架

cc34e0b2ccef417fb412c0f3445c81e7

二、硬件设计

PCB原理图下载: 链接:https://pan.baidu.com/s/1wzTGKnRF7WUzTYZ5U4v9kQ 提取码:6tds

三、软件模块

1、语音识别模块

相对于离线版,在线版除了具有本地的语音识别之外,还加入了百度的语音识别API,当本地的语音识别未能匹配到命令时,将音频数据发送到百度语音识别接口,并对返回的文本结果进行解析,逻辑如图(百度智能云语音识别返回结果是utf-8编码的字符串,所以代码编辑器中最好设置utf-8编码.)

image-20210903144247457

  • WakeNet是语音唤醒模型
  • MultiNet是语音识别模型。
  • Baidu ASR是在线识别的任务

语音模块的工作流程如下:

麦克风输入的音频经过音频解码芯片,通过IIS进入到ESP32内存,经过降噪处理输入WakeNet检测是否存在唤醒词,若有唤醒词则进入语音识别,将音频输入MultiNet匹配命令词,同时缓存音频数据。若匹配成功则会执行命令内容,若经过设置的时间(eg 4s)匹配失败,则将缓存的音频数据通过Baidu ASR发送到百度智能云并读取返回的文本结果,对结果解析出命令内容执行。

2、ble

ESP32支持蓝牙双模,目前仅使用蓝牙进行配网(即给esp32发送wifi名称和密码,使esp32连接到wifi)。所以使用ble更合适。

BLE(低功耗蓝牙),适合数据量较小的场合,ESP32支持完整的BLE协议栈,以ESP32作为BLE从机,发送广播、建立GATT Server并等待客户端连接。客户端以微信小程序BLE为例。小程序与ESP32蓝牙通信过程如下图:

ESP32建立一张profile、并创建一个wifi service、用于配置ESP32的wifi。小程序可向wii service 的相应属性中写入数据,来配置ESP32的wifi。

如图,向SSID、PSWD、CONFIG分别写入下值,ESP32会自动连接到路由器esp

image-20210903150941609

3、mqtt模块

该模块使用mqtt_client库实现mqtt客户端进程的登陆,订阅,发布等功能。MQTT broker则使用华为云的设备接入IOT平台。

华为云平台为每个设备定义了多个主题,用于最基本的mqtt消息应用,本模块参考了设备接入Iota->API参考->设备侧mqtt接口参考实现了以下功能:

目前实现的软件框架如图所示:

ec02f9b0affc47ae88edbe62e6b827a5

4、音频播放模块

本项目板子上装备了两个喇叭,可以用于播放音频,可播放 本地音频 和 网络音频流 。如图所示,由于嵌入式设备内存有限,故本地音频主要是一些简单的提示语音,其优点是播放速度快,响应及时;而HTTP音频流能灵活播放音频,但其受限于网络环境,故将二者结合互补。

dadd9504768e4ec4b2890331e80c3bab

5、红外模块

目前的家具,电器中,仍有很多电器使用红外遥控,特别是空调。同类型的设备使用的红外协议大同小异,并且都可以查看其协议内容。

红外模块可发送不同类型,品牌的产品的红外控制信号,同时具备学习功能,能通过遥控器,学习设备的红外协议。

6、传感器模块

目前我们的板子上添加了ds18b20温度传感器,用于准确的读取室内的温度。

7、定时器模块

定时模块主要用于记录当前的年份,月份,日期,时间,提供精确到秒的定时提醒服务,支持大时间尺度上的定时,如一天,两天甚至更长时间的定时提醒。其定时的时钟源是freertos的系统时钟。

8、无线检测模块

四、使用

1、编译

先安卓ESP-ADF,使用idf-v4.0.2,将仓库下载到examples目录下,首先设置环境变量,在idf目录下执行:

./export.sh
export ADF_PATH=/esp/esp-adf

在项目目录下执行:

idf.py build

等待编译完成

2、烧录

根据partitions.cv的地址安排,烧录二进制文件。

3、上电初始化

上电后会自动连接上次连接的路由器 若无法连接,则会一直请求连接

4、蓝牙配网

打开微信,搜索小程序BLETool,打开蓝牙,连接到ESP32A1S,然后在characteristics分别写入:

  • 6601 :写入你的路由名称
  • 6602:路由密码
  • 6603:发送666确认连接

完成以上操作后。设备会自动连接到路由器,复位后会尝试连接上次连接的路由器。配网完成后可关闭BLE以节省内存资源。

开发者也可通过串口发送如下串口数据实现配网:

#yourssid
@yourpassword
$

5、语音唤醒及识别

嗨乐鑫,唤醒,蓝灯亮起,说出命令词

命令词及控制代码在 'static esp_err_t asr_multinet_control(int commit_id)'

6、红外遥控/学习

开启ir_study();后,使用本地红外遥控器发送指定命令(如,空调遥控器发送打开 制冷模式 26° 自动扫风 一级风速,目前仅支持格力美的海尔)即可匹配本地码库。

目前支持空调红外遥控,如设置开关,温度,扫风,风速,工作模式。

7、日历系统

主要在clock.c中,以一个任务的形式存在。日历系统在初始化阶段会获取网络gmt时间,并设置一个定时器,每隔24小时获取gmt时间。

日历系统支持定时器功能,定时时间精度为1s,定时最大时长可1年(不建议)

8、http请求

该部分代码位于myhttp.c中,主要负责网络时间,天气数据,百度token的获取。

9、MQTT客户端

使用华为云iot接入

参考文档 https://support.huaweicloud.com/api-iothub/iot_06_v5_3010.html

主题列表

下发设备命令: $oc/devices/60b9c9383744a602a5cb9bf3_smart_control_01/sys/commands/request_id={request_id}

设备响应: $oc/devices/60b9c9383744a602a5cb9bf3_smart_control_01/sys/commands/response/request_id={request_id}

查询设备属性: $oc/devices/{device_id}/sys/properties/get/request_id={request_id}

设备响应 $oc/devices/{device_id}/sys/properties/get/response/request_id={request_id}

命令控制

可汇报数据:室内温度,空调状态,温度,定时任务?

  • temp:(int)36
  • ir_status:(int)open,temperature,windspeed,
  • timer: (string)timer_name,(string)time

可控制的动作:空调的控制,读取温度,设置定时任务,红外学习

  • ir_status:(int)open,temperature,windspeed,
  • timer: (string)timer_name,(string)time
  • ir_study:(int) open

10、传感器

目前搭载了ds18b20温度传感器,在每次上电时先读一次温度。

11、无线检测

12、命令词

本地识别

CONFIG_CN_SPEECH_COMMAND_ID0="da kai kong tiao"

CONFIG_CN_SPEECH_COMMAND_ID1="guan bi kong tiao"

CONFIG_CN_SPEECH_COMMAND_ID2="zeng jia feng su"

CONFIG_CN_SPEECH_COMMAND_ID3="jian xiao feng su"

CONFIG_CN_SPEECH_COMMAND_ID4="sheng gao yi du"

CONFIG_CN_SPEECH_COMMAND_ID5="jiang di yi du"

CONFIG_CN_SPEECH_COMMAND_ID6="xian zai ji dian"

CONFIG_CN_SPEECH_COMMAND_ID7="shi nei wen du"

CONFIG_CN_SPEECH_COMMAND_ID8="da kai lan ya"

CONFIG_CN_SPEECH_COMMAND_ID9="guan bi lan ya"

空调

  • 打开/关闭空调 close open aircon
  • 设置空调26度 open aircon 26

蓝牙

  • 打开/关闭蓝牙 close open ble

其他

  • 今天/明天/后天 天气怎么样 day weather
  • 现在几点 now
  • 明天早上12点叫我起床;明天早上12点半叫我起床

词法解析:词典

  • clock:一小时后、两小时后、三小时后;一分钟后、两分钟后、三分钟后

目前的问题

  • wifi检测不准确
  • 需要一个网络管理任务,处理wifi、蓝牙连接状态改变时,对其他任务的影响
  • 词法解析定时任务

日志

  • 2021.9.3

完成在线离线语音识别混合使用

  • 2021.3.3

修正tools/mk_audio_bin.py

唤醒时会出现蓝灯,表示正在倾听,蓝灯熄灭表示倾听结束

修复定时器,定时器每24小时更新

  • 2021.3.2

使用离线的语音识别

  • 2021.2.28

添加更多注释

  • 2020.12.27

完成和风天气预报,语音红外,时间系统。解析来需要解决定时任务

  • 2020.11.24

百度语言识别与百度自然语言理解结合,百度语音识别将语音转成文字,用词法分析,提取文字中的关键字,根据关键字触发指定动作。定制词法用于规定关键字。 实现了空调的控制,天气数据的获取。

  • 2020.11.21

讲本地语音识别换成百度语音在线识别 修改获取天气代码,统一myhttp.c的http_event_handle

  • 2020.11.5

修改了天气接口,更换了一个更稳定的API,将所有任务的创建集合在main函数,创建任务内存管理来监控任务的运行状态。

  • 2020.11.2

烧录了新的红外码库文件,包含格力美的海尔奥克斯的全常用的码库。可正常显示灯光

  • 2020.10.26

增加了irext库的解码。使用了spiffs文件系统,烧录文件时,命令行操作:python spiffsgen.py 0x19000 binfile spiffs.bin ,其中的0x19000是分区表设置的文件系统的大小,为100k。然后使用esp32烧录工具烧录到分区表所示的位置。

待解决:解析出来的数据转换成红外波能否有效?

  • 2020.10.24

增加了对ds18b20的温度读取

  • 2020.10.23

简化了ir_task的代码,用信号量限制对全局变量的访问

  • 2020.10.22

完成红外学习,最多存储1600个字节的命令。可调节nvs来增加内存。由于红外接收是低电平所以需要一个item_reversal()来反转电平

解决了按键的问题,如果改动按键,需要到board.c中修改button的宏;

完成了dht11温湿度的读取 在BUTTON.C中触发读取

  • 2020.10.14

天气数据播放完成,http_get_weather()函数会使用大量内存 需要为任务分配足够的堆栈,测试堆栈:3k

  • 2020.10.13

添加了audio文件夹来放语音相关的文件 添加player.c文件 实现播放flash和http的mp3

  • 2020 .10.12

完成http发送get请求到http://api.jirengu.com/getWeather.php请求天气数据并用CJSON解析出数据。

开放天气接口来自:http://api.jirengu.com/

服务器返回json编码是utf-8,需要使用支持utf-8的串口助手才能正常打印中文字符,例如星瞳串口助手

  • 2020.10.11

结合了蓝牙配网模块 注意clean后再build 的重要性

wifi自动重连 ble中只需要添加wifi_update()就可以更新wifi配置并重连

  • 2020.9.23

修改了button的按键为io19 等。需要测试正确性

添加了mn_count的打印

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

esp32智能遥控器 展开 收起
C 等 4 种语言
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/killerp/smart_control.git
git@gitee.com:killerp/smart_control.git
killerp
smart_control
smart_control
master

搜索帮助