本帖最后由 zhuangzi105 于 2019-4-23 16:32 编辑
首先感谢feversky,huex ,zhkufish分享的代码.和教程,教程链接https://bbs.hassbian.com/thread-5417-1-1.html
下面介绍操作过程中的各种坑,希望后面的同学引以为戒。。
首先是ssl 部分,
之前用的5元永久花生壳壳域名(因为贫穷),不带ssl。所以需要申请一个。
坑1:然而北京联通封了80和443端口,没办法验证,正好手头有个做酸酸乳的vultr的VPS,参考了这篇帖子
http://koolshare.cn/thread-111350-1-11.html
1.在vps上运行花生壳,软件请务必到官网上下,我就是点了个教程,下了个低版本的结果运行不了。。坑2
2.建服务器,把阿里云验证文件fileauth放到对应位置。
3.回到阿里云验证
4.审核完毕之后把公钥和私钥放到树莓派上去。。
坑3:home assistant 中配置ssl,因为home assistant是在docker里装的。configuration.yaml中ssl_certificate,ssl_key的地址需要是docker的地址。也就是说需要把公钥和私钥放到比如/config挂载的位置上去,我这边是/usr/share/homeassistant 。然后在configuration.yaml对应位置填上docker的地址,如下
http:
base_url: https://********:8123
ssl_certificate: /config/server.pem
ssl_key: /config/server.key
use_x_forwarded_for: true
trusted_proxies:
- 127.0.0.1
- ::1
ip_ban_enabled: true
login_attempts_threshold: 5
然后nginx配置编辑,放置dueros.py什么的按照教程来就好。docker安装的home assistant,dueros.py要放在挂载的地方
然后顺利授权成功,但是模拟测试的时候坑来了。。
坑4:模拟测试时,home assistant可以收到信息。不过会报错。检查了下。DuerOS发过来的json文件和python代码里对不上啊。苦苦思索哪里不对,始终找不到。然后去查DuerOS的手册,发现智能家居发的就应该有header和payload,为啥我的没有呢。回去检查技能设置的时候看到了技能类型:自定义。。感觉怪怪的。回想起来当时创建技能的时候好像有别的选项啊 。。。。应该选智能家居啊。选自定义是什么鬼。
2019-04-23 10:14:10 DEBUG (MainThread) [homeassistant.components.http.view] Serving /dueros_gate to 10.202.112.18 (auth: False)
2019-04-23 10:14:12 ERROR (MainThread) [custom_components.dueros] Traceback (most recent call last):
File "/config/custom_components/dueros.py", line 97, in post
response = await handleRequest(data)
File "/config/custom_components/dueros.py", line 120, in handleRequest
header = data['header']
KeyError: 'header'
在对应位置输出data的内容。发现data中没有header关键字。
data内容:
[custom_components.dueros]{"version": "v2.0","session": {"new":true, "sessionId":"2bf27c64-3d48-4ad2-8980-dddec189cf0a"},"context": {"System":{"user": {"userId":"9009298", "accessToken":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiI5NGVhNzhlNjMzNzA8YjZiM2ZkNTM3NjQxYWQ5ZCIsImlhdCI6MTU1NTk4NjI3MiwiZXhwIjoxNTU2NjM0MjcyfQ.Nc2_eb2cKP5PFSNbf7uHcaGAs4PNJUisoY37DOa6EY","userInfo": {"account":{}}}, "application": {"applicationId":"917baa19-c612-9a17-9f39-d48df768df061"},"device": {"deviceId":"77be6f9f9aa83634f7e08bef40a124","supportedInterfaces": {"VoiceInput":{}, "VoiceOutput": {}, "AudioPlayer":{}, "VideoPlayer": {"preferedBitrate":"", "preferedWidth":0, "preferedHeight":0}}, "TVControl":{"controlType": "DCSControl","controlStatus": 0},"originalDeviceSerialNumber": "91206/1B3F160053140"},"apiAccessToken": "+OKmo/6o7dAPXT/5IGAzhEOS/apTcnZzY+C5rVuWJNAQt+gVH+giijfT8q0MWcpXI/CSLCJnWY3D1/Cz7OWcWD1R9hFMF0hnyge8cFRqwnX6lrKixur3uYzUYr029vvnFt/bRYdXvPbf+cTAFh6gzKDlF/ZgYGXIOPWMlCQ/sxyskERNSpq9pSD2iWhBSEMYT9YgnpiEGYcoGinrFUV5YEXhT3w+eeJqcLvaXqBoZ2o74yLFKiGys+037gdyx1UGFUX1siwY0tErNl/fQSrEnQV+p+ac+2QFfONfRAzAlybPAF9l6g8/mINQywPFL6n27R0Q+HJIzlSp5Z5k6V+zGwVjmKUoS2+Fcjk+Jzag5CT1gwdX97rvoyH4/x+XQhZawGpUnWhGEVKMfkPOQ==","apiEndPoint": "https://xiaodu.baidu.com","avaliableApplicationIds": ["aries_general","audio_music", "audio_unicast","audio_live", "audio_news","speaker_hardware", "duer_weather","sysprofile_service", "ai.dueros.bot.vocal_joke","ai.dueros.bot.alarm", "ai.dueros.bot.timer","ai.dueros.bot.smarthome", "doudi_server","ai.dueros.bot.audio_museum", "ai.dueros.bot.puzzle","ai.dueros.bot.faq_didp", "audio_music_children","483c3ee4-0e37-e05a-0d95-efe1dc96dc44","audio_classic", "d4106ab2-4374-816e-322a-341fcc625e4b","fed5e9a3-32e0-a87c-9571-9c7d296b919d","ai.dueros.bot.oss", "0b082db2-fc64-6396-5744-1ffd84e83a32","409e98fd-e144-c39a-6c35-75d261683834","ai.dueros.ext.rus", "6402fc3a-7825-3147-b52e-c25911b6d03c","ca4585e2-3cc2-8605-4062-08f9931304db","ext_timer"]}, "AudioPlayer":{"token": "1","offsetInMilliSeconds": 1520773,"playActivity": "STOPPED","applicationId": "audio_live"},"SettingsState": {"childFriendlyMode":false}}, "request":{"type": "LaunchRequest","requestId": "c4349bc0-6574-18e9-b28b-d9f75472d902_DCSxukbcd8871_3#1_0","timestamp": "155508782","dialogRequestId": "45c90f3f-f9be-4937-9d20-6a6c9cbd2dc2"}}
重新创建技能之后,模拟测试顺利通过,完满收工。。
这东西,来来回回折腾了两三天。差点精神崩溃。不过最终还是结局完美。希望后续官方能出接口吧。这样就不用这么折腾了。。
题外话:
小度音箱终于可以控制家电了。不然感觉这东西就是个废物。。问个问题听不懂,一言不合就要给你播放音乐。。
比如我对他说:快来救我。他就给我播放名字是快来救我的音乐。。一点幽默细胞都没有。简直是人工智障
|