『瀚思彼岸』» 智能家居技术论坛

 找回密码
 立即注册
查看: 109197|回复: 502

[进阶教程] OpenMQTTGateway HA&HB 锁定。作者更新太久。本贴无效了。

  [复制链接]

8

主题

270

帖子

1337

积分

金牌会员

Rank: 6Rank: 6

积分
1337
金钱
1067
HASS币
0
发表于 2017-9-10 10:05:09 | 显示全部楼层 |阅读模式
本帖最后由 671792320 于 2020-4-11 17:43 编辑

提示提示提示:由于本方案的github上的代码更新的已经很多,但是楼主没有更新。所以本教材只能作为参考
提示提示提示:由于本方案的github上的代码更新的已经很多,但是楼主没有更新。所以本教材只能作为参考
提示提示提示:由于本方案的github上的代码更新的已经很多,但是楼主没有更新。所以本教材只能作为参考
提示提示提示:由于本方案的github上的代码更新的已经很多,但是楼主没有更新。所以本教材只能作为参考

ESP8266替代遥控器并接入到ha里面之红外线方案
只是更新了标题,暂时没有打算更新到最新的项目。等中断在进行更新。

进过努力已经可以控制空调了。

项目还是这个项目地址:https : //github.com/1technophile/OpenMQTTGateway
谷歌翻译如下:
  • ESP8266,NodeMCU V1(测试),NodeMCU V3(测试)或Wemos D1 mini(测试)
  • RF网关:433Mhz接收器XD RF 5V和FS1000A或超外差STX882&SRX882
  • IR网关:用于发射的红外二极管
  • IR网关:晶体管2N2222
  • IR网关:一个330欧姆的电阻
  • 红外网关:红外接收器
  • BT网关:HM 10键盘蓝牙模块
如果只是用红外的话,需要红外接收头,发射头,一个2N222三极管,一个330欧姆电阻。
接收头我是用的是1838。


如何编译可以参考我这个帖子去编译:https : //bbs.hassbian.com/thread-894-1-1.html


下面来简单说明下如何控制空调的,和需要修改那些地方。
[隐藏]

pubsubclient \ src \ PubSubClient.h

修改26行为10240



<font style="vertical-align: inherit;"><font style="vertical-align: inherit;">// MQTT_MAX_PACKET_SIZE:最大数据包大小</font></font>
<font style="vertical-align: inherit;"><font style="vertical-align: inherit;">#ifndef MQTT_MAX_PACKET_SIZE#定义</font></font>
<font style="vertical-align: inherit;"><font style="vertical-align: inherit;">MQTT_MAX_PACKET_SIZE 10240 </font></font>
<font style="vertical-align: inherit;"><font style="vertical-align: inherit;">#endif </font></font>

<font style="vertical-align: inherit;"><font style="vertical-align: inherit;">// MQTT_KEEPALIVE:keepAlive时间间隔以秒为单位</font></font>
<font style="vertical-align: inherit;"><font style="vertical-align: inherit;">#ifndef MQTT_KEEPALIVE#定义</font></font>
<font style="vertical-align: inherit;"><font style="vertical-align: inherit;">MQTT_KEEPALIVE 15 </font></font>
<font style="vertical-align: inherit;"><font style="vertical-align: inherit;">#endif</font></font>





修改42行取消注释



<font style="vertical-align: inherit;"><font style="vertical-align: inherit;">// MQTT_MAX_TRANSFER_SIZE:限制</font></font>
<font style="vertical-align: inherit;"><font style="vertical-align: inherit;">每个写调用中// </font><font style="vertical-align: inherit;">将多少数据传递给网络客户端</font><font style="vertical-align: inherit;">。</font><font style="vertical-align: inherit;">Arduino Wifi Shield需要。</font><font style="vertical-align: inherit;">保留undefined即可</font></font>
<font style="vertical-align: inherit;"><font style="vertical-align: inherit;">//在每个写调用中传递整个MQTT数据包。</font></font>
<font style="vertical-align: inherit;"><font style="vertical-align: inherit;">#define MQTT_MAX_TRANSFER_SIZE 80 </font></font>

<font style="vertical-align: inherit;"><font style="vertical-align: inherit;">// </font><font style="vertical-align: inherit;">client.state </font><font style="vertical-align: inherit;">()的可能值</font></font>


修改项目内的ZgatewayIR.ino文件
30-42行替换如下内容



<font style="vertical-align: inherit;"><font style="vertical-align: inherit;">#ifdef ESP8266 </font></font>

<font style="vertical-align: inherit;"><font style="vertical-align: inherit;">  #include <IRremoteESP8266.h> </font></font>

<font style="vertical-align: inherit;"><font style="vertical-align: inherit;">  #include <IRsend.h> //如果要发送IR命令,则需要 </font></font>

<font style="vertical-align: inherit;"><font style="vertical-align: inherit;">  #include <IRrecv.h> //如果要接收IR命令,则需要。</font></font>

<font style="vertical-align: inherit;"><font style="vertical-align: inherit;">  uint16_t CAPTURE_BUFFER_SIZE = 4096; </font></font>

<font style="vertical-align: inherit;"><font style="vertical-align: inherit;">  #define TIMEOUT 90U </font></font>

<font style="vertical-align: inherit;"><font style="vertical-align: inherit;">  IRrecv irrecv(IR_RECEIVER_PIN,CAPTURE_BUFFER_SIZE,TIMEOUT,true); </font></font>

<font style="vertical-align: inherit;"><font style="vertical-align: inherit;">  IRsend irsend(IR_EMITTER_PIN); </font></font>

<font style="vertical-align: inherit;"><font style="vertical-align: inherit;">#else </font></font>

<font style="vertical-align: inherit;"><font style="vertical-align: inherit;">  #include <IRremote.h> </font></font>

<font style="vertical-align: inherit;"><font style="vertical-align: inherit;">  IRrecv irrecv(IR_RECEIVER_PIN); </font></font>

<font style="vertical-align: inherit;"><font style="vertical-align: inherit;">  IRsend irsend; </font><font style="vertical-align: inherit;">//将IR发射器引脚连接到arduino上的D9,您需要在库IRremote.h上注释#define IR_USE_TIMER2并取消注释#define IR_USE_TIMER1,以便将D3引脚释放为RF RECEIVER PIN </font></font>

<font style="vertical-align: inherit;"><font style="vertical-align: inherit;">#endif</font></font>
然后注意启用接收未知协议然后79-80行之间又一个错误修改为true即可
<font style="vertical-align: inherit;"><font style="vertical-align: inherit;">[/ align] </font></font>

<font style="vertical-align: inherit;"><font style="vertical-align: inherit;">[align = left] irrecv.resume(); </font><font style="vertical-align: inherit;">// </font></font>
<font style="vertical-align: inherit;"><font style="vertical-align: inherit;">    如果(pubIRunknownPrtcl == true && MQTTprotocol ==“ -1”){//不发布未知的IR协议</font></font>
<font style="vertical-align: inherit;"><font style="vertical-align: inherit;">      trc(F(“-没有发布的未知协议-”)),</font><font style="vertical-align: inherit;">则</font><font style="vertical-align: inherit;">接收下一个值</font><font style="vertical-align: inherit;">;</font></font>
<font style="vertical-align: inherit;"><font style="vertical-align: inherit;">[/ align] </font></font>


<font style="vertical-align: inherit;"><font style="vertical-align: inherit;">[align = left]</font></font>




[/隐藏]


然后编译上传即可。
目前最多支持1500位为数据。空调应该完全足够的了!!!
目前最多支持1500位为数据。空调应该完全足够的了!!!
目前最多支持1500位为数据。空调应该完全足够的了!!!
有坑不负责折腾了~~大家自行测试吧~~我家的格力空调完美识别控制,
已知BUG如果发送数据太快的会会导致ESP8266重新启动!!!
已知BUG如果发送数据太快的会会导致ESP8266重新启动!!!
已知BUG如果发送数据太快的会会导致ESP8266重新启动!!!


服下我的空调代码~~~

<font style="vertical-align: inherit;"><font style="vertical-align: inherit;">-平台:mqtt </font></font>

<font style="vertical-align: inherit;"><font style="vertical-align: inherit;">名称:“ ktktzl_23_f1_raw” </font></font>

<font style="vertical-align: inherit;"><font style="vertical-align: inherit;">#state_topic:“ home / IRtoMQTT”#由User_config.h中的subjectGTWRFtoMQTT定义。command_topic </font></font>

<font style="vertical-align: inherit;"><font style="vertical-align: inherit;">:“ home / commands / MQTTtoIR_Raw”</font></font>

<font style="vertical-align: inherit;"><font style="vertical-align: inherit;">payload_on:“8986,4490,648,1658,648,558,648,558,646,1658,648,1660,648,558,646,558,646,560,646,1660,646,1660,648,1658,648,558,646,558,648,560,646,558,648,558,648,558,646,558,648,558,646,560,646,558,648,1658,648,558,646,558,646,558,646,558,646,558,648,558,646,1660,648,558,646,1660,648,558,646,558,648,1658,648,558,646,19992 ,648,558,646,558,646,558,646,558,646,560,646,558,646,558,648,560,646,558,648,558,646,558,646,560,646,558,646,558,648,558,646,558,646,558,646,558,648,558,646,560,646,558,646,558,646,558,646,560,646,558,646,558,646,560,646,558,646,558,646,1660,648,560,646,1660,648,40004,8984,4494,646,1660,648,558,648,558,646,1660,648,1660,648,558,646,558,646,558,648,1660,646,1662,646,1660,648,558,646,558,646,558,646,558,646,558,646,558,648,558,646,558,646,558,646,558,646,1660,646,558,646,558,646,558,648,558,646,560,646,558,648,1658,650 ,1658,648,1662,646,558,646,558,648,1658,648,558,646,19994,646,558,646,560,646,558,646,558,646,558,648,558,646,560,646,558,648,558,646,560,646,558,646,560,646,560,648,558,646,558,646,560,646,558,646,558,646,558,648,560,646,1662,646,560,646,558,646,560,646,558,646,560,646,560,646,558,648,1660,646,1662,646,558,646,1662,644"</font></font>

<font style="vertical-align: inherit;"><font style="vertical-align: inherit;">payload_off:“8986,4490,648,1658,648,558,648,558,646,1658,648,1660,648,558,646,558,646,560,646,1660,646,1660,648,1658,648,558,646,558,648,560,646,558,648,558,648,558,646,558,648,558,646,560,646,558,648,1658,648,558,646,558,646,558,646,558,646,558,648,558,646,1660,648,558,646,1660,648,558,646,558,648,1658,648,558,646,19992 ,648,558,646,558,646,558,646,558,646,560,646,558,646,558,648,560,646,558,648,558,646,558,646,560,646,558,646,558,648,558,646,558,646,558,646,558,648,558,646,560,646,558,646,558,646,558,646,560,646,558,646,558,646,560,646,558,646,558,646,1660,648,560,646,1660,648,40004,8984,4494,646,1660,648,558,648,558,646,1660,648,1660,648,558,646,558,646,558,648,1660,646,1662,646,1660,648,558,646,558,646,558,646,558,646,558,646,558,648,558,646,558,646,558,646,558,646,1660,646,558,646,558,646,558,648,558,646,560,646,558,648,1658,650 ,1658,648,1662,646,558,646,558,648,1658,648,558,646,19994,646,558,646,560,646,558,646,558,646,558,648,558,646,560,646,558,648,558,646,560,646,558,646,560,646,560,648,558,646,558,646,560,646,558,646,558,646,558,648,560,646,1662,646,560,646,558,646,560,646,558,646,560,646,560,646,558,648,1660,646,1662,646,558,646,1662,644"</font></font>

<font style="vertical-align: inherit;"><font style="vertical-align: inherit;">乐观:错误</font></font>

<font style="vertical-align: inherit;"><font style="vertical-align: inherit;">保留:错误</font></font>

<font style="vertical-align: inherit;"><font style="vertical-align: inherit;">-平台:mqtt </font></font>

<font style="vertical-align: inherit;"><font style="vertical-align: inherit;">名称:“ ktktgj_raw” </font></font>

<font style="vertical-align: inherit;"><font style="vertical-align: inherit;">#state_topic:“ home / IRtoMQTT”#由subjectGTWRFtoMQTT在User_config.h中定义。command_topic </font></font>

<font style="vertical-align: inherit;"><font style="vertical-align: inherit;">:“ home / commands / MQTTtoIR_Raw”</font></font>

<font style="vertical-align: inherit;"><font style="vertical-align: inherit;">payload_on:“8988,4492,648,1658,648,558,646,558,646,560,646,560,646,558,646,558,646,560,646,558,646,1660,648,1662,646,1660,646,558,648,558,646,560,646,560,646,560,646,558,648,558,646,558,646,560,648,1660,648,558,646,558,646,558,646,558,648,558,646,558,648,1660,646,558,648,1660,646,558,646,558,648,1660,648,558,648,19992,648,558,648,558,646,558,646,558,648,558,648,558,646,558,648,558,646,558,646,558,648,558,646,558,648,558,646,558,646,558,648,558,648,558,646,558,648,558,646,558,648,558,648,558,648,558,648,558,648,558,646,558,646,558,648,558,646,1660,648,558,646,558,648,1660 ,646,40002,8986,4492,648,1660,648,558,646,558,646,558,648,558,646,558,646,558,648,558,646,558,646,1660,648,1658,648,1660,646,558,646,560,646,558,648,558,646,558,648,648,648,646,558,646,558,646,558,646,558,646,558,646,558,646,558,646,558,646,558,646,558,646,558,646,558,646,558,646,558,558648,558,648,558,646,1660,646,558,648,19994,646,558,646,558,648,558,648,558,646,558,648,558,646,558,646,558,648,558,648,558,646,560,648,558,648,558,646,560,648,558,646,558,646,558,648,558,646,558,648,558,648,558,646,558,648,558,646,560,646,558,646,558,646,558,648,558,648,1658,648,558,648,558,646,1660,648"</font></font>

<font style="vertical-align: inherit;"><font style="vertical-align: inherit;">payload_off:“8988,4492,648,1658,648,558,646,558,646,560,646,560,646,558,646,558,646,560,646,558,646,1660,648,1662,646,1660,646,558,648,558,646,560,646,560,646,560,646,558,648,558,646,558,646,560,648,1660,648,558,646,558,646,558,646,558,648,558,646,558,648,1660,646,558,648,1660,646,558,646,558,648,1660,648,558,648,19992,648,558,648,558,646,558,646,558,648,558,648,558,646,558,648,558,646,558,646,558,648,558,646,558,648,558,646,558,646,558,648,558,648,558,646,558,648,558,646,558,648,558,648,558,648,558,648,558,648,558,646,558,646,558,648,558,646,1660,648,558,646,558,648,1660 ,646,40002,8986,4492,648,1660,648,558,646,558,646,558,648,558,646,558,646,558,648,558,646,558,646,1660,648,1658,648,1660,646,558,646,560,646,558,648,558,646,558,648,648,648,646,558,646,558,646,558,646,558,646,558,646,558,646,558,646,558,646,558,646,558,646,558,646,558,648,558,5581660,648,558,648,558,646,1660,646,558,648,19994,646,558,646,558,648,558,648,558,646,558,648,558,646,558,646,558,648,558,648,558,646,560,648,558,648,558,646,560,648,558,646,558,646,558,648,558,646,558,648,558,648,558,646,558,648,558,646,560,646,558,646,558,646,558,648,558,648,1658,648,558,648,558,646,1660,648"</font></font>

<font style="vertical-align: inherit;"><font style="vertical-align: inherit;">乐观:错误</font></font>

<font style="vertical-align: inherit;"><font style="vertical-align: inherit;">保留:错误</font></font>



嗯,完工。








示例.png
ha显示效果.png

项目和库文件.7z

3.86 MB, 下载次数: 213

评分

参与人数 2金钱 +30 收起 理由
Roger + 20 技术贴!必须加分!
+ 10 谢谢分享!

查看全部评分

回复

使用道具 举报

3

主题

286

帖子

2664

积分

版主

懵懂的小白

Rank: 7Rank: 7Rank: 7

积分
2664
金钱
2378
HASS币
0
发表于 2017-9-10 10:07:59 来自手机 | 显示全部楼层
多配点图就好了
回复

使用道具 举报

19

主题

457

帖子

8161

积分

元老级技术达人

云淡风轻近午天

积分
8161
金钱
7704
HASS币
0

教程狂人

发表于 2017-9-10 10:08:14 | 显示全部楼层
辛苦娘子磨豆腐
回复

使用道具 举报

8

主题

270

帖子

1337

积分

金牌会员

Rank: 6Rank: 6

积分
1337
金钱
1067
HASS币
0
 楼主| 发表于 2017-9-10 10:08:27 | 显示全部楼层
jlxwkj 发表于 2017-9-10 10:07
多配点图就好了

懒的截图了。。
回复

使用道具 举报

8

主题

270

帖子

1337

积分

金牌会员

Rank: 6Rank: 6

积分
1337
金钱
1067
HASS币
0
 楼主| 发表于 2017-9-10 10:10:22 | 显示全部楼层
luzai 发表于 2017-9-10 10:08
辛苦娘子磨豆腐

回复

使用道具 举报

2

主题

136

帖子

502

积分

高级会员

Rank: 4

积分
502
金钱
366
HASS币
0
发表于 2017-9-10 10:11:55 | 显示全部楼层
群里刚入坑的 新手前来学习啦
回复

使用道具 举报

123

主题

4661

帖子

1万

积分

管理员

囧死

Rank: 9Rank: 9Rank: 9

积分
16410
金钱
11664
HASS币
45
发表于 2017-9-10 10:14:20 | 显示全部楼层
失语妹子?
回复

使用道具 举报

8

主题

270

帖子

1337

积分

金牌会员

Rank: 6Rank: 6

积分
1337
金钱
1067
HASS币
0
 楼主| 发表于 2017-9-10 10:22:18 | 显示全部楼层

...........................................
回复

使用道具 举报

2

主题

136

帖子

1024

积分

金牌会员

Rank: 6Rank: 6

积分
1024
金钱
888
HASS币
0
发表于 2017-9-10 10:43:40 | 显示全部楼层
失语妹纸么么哒
回复

使用道具 举报

3

主题

219

帖子

932

积分

高级会员

Rank: 4

积分
932
金钱
713
HASS币
0
发表于 2017-9-10 11:23:12 | 显示全部楼层
好像很厉害的样子
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-11-25 07:01 , Processed in 0.102699 second(s), 36 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表