编译OpenMQTTGateway

仓库地址 https://github.com/1technophile/OpenMQTTGateway

上一篇OpenMQTTGateway文章尝试编译了ESP8266的RF功能,这次在支持RF的基础上添加IR功能.

参考文档:
https://docs.openmqttgateway.com/upload/builds.html#configure-upload-with-platformio

这篇官方文档写了自定义配置的方法,并且有同时支持RF和IR的示例,但是示例代码中的只添加了build_flags,没有添加lib_deps(依赖库)
这导致了在User_cofnig.h中即使选了IR功能,编译的时候导致缺少依赖库而报错
报错如下:

1
2
3
4
5
6
7
8
9
10
11
12
****************************************************************

33 | # include <IRrecv.h> // Needed if you want to receive IR commands.
| ^~~~~~~~~~
compilation terminated.
*** [.pio/build/nodemcuv2-rf-ir/src/main.ino.cpp.o] Error 1
====================================================================================== [FAILED] Took 8.77 seconds ======================================================================================

Environment Status Duration
--------------- -------- ------------
nodemcuv2-rf-ir FAILED 00:00:08.769
================================================================================= 1 failed, 0 succeeded in 00:00:08.769 =================================================================================

解决办法

在RF的环境中,添加IR的依赖库即可

具体自定义配置

编辑environments.ini

OpenMQTTGateway/enviroments.ini

  1. 找到nodemcuv2-rf的环境配置复制一份并命名为nodemcuv2-rf-ir
    修改环境名和网关名称

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    [env:nodemcuv2-rf-ir]
    platform = ${com.esp8266_platform}
    board = nodemcuv2
    lib_deps =
    ${com-esp.lib_deps}
    ${libraries.wifimanager8266}
    ${libraries.rc-switch}
    ${libraries.esp8266_mdns}
    build_flags =
    ${com-esp.build_flags}
    '-DZgatewayRF="RF"'
    '-DGateway_Name="OpenMQTTGateway_ESP32_RF_IR'
    board_build.flash_mode = dout
    custom_description = The historic RF gateway using RCSwitch library
  2. 找到nodemcuv2-ir的环境配置进行比对
    对比IR 的示例添加 build_flags 下面是添加的 env 定义:

    1
    '-DZgatewayIR="IR"'
  3. 官方文档中没有添加IR的依赖导致编译缺少库
    所以这里还需要添加IR的依赖

对比 IR 的示例添加 lib_deps 下面是 添加的 dep 定义:

1
${libraries.irremoteesp}

custom_description自定义描述修不修改无所谓

  1. RF&IR的完整配置环境代码如下
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    [env:nodemcuv2-rf-ir]
    platform = ${com.esp8266_platform}
    board = nodemcuv2
    lib_deps =
    ${com-esp.lib_deps}
    ${libraries.wifimanager8266}
    ${libraries.rc-switch}
    ${libraries.irremoteesp}
    ${libraries.esp8266_mdns}
    build_flags =
    ${com-esp.build_flags}
    '-DZgatewayRF="RF"'
    '-DZgatewayIR="IR"'
    '-DGateway_Name="OpenMQTTGateway_ESP8266_RF_IR"'
    board_build.flash_mode = dout
    custom_description = The historic RF&IR gateway using RCSwitch&IRRemoteesp library
1
'-DGateway_Name="OpenMQTTGateway_ESP8266_RF_IR"'

Gateway_Name是网关名称,发出的SSID名称也会相同

编译

在codeserver底栏选择 √ (PlatformIO:Build) 进行编译

如果依然有问题可能是环境没有清理
点击codeserver底栏的垃圾桶即可清理环境

实际上垃圾桶替代的命令

1
pio run --target clean

编译完成

固件在OpenMQTTGateway/.pio/build/nodemcuv2-rf-ir/firmware.bin

1
2
3
4
5
6
7
Creating BIN file ".pio/build/nodemcuv2-rf-ir/firmware.bin" using "/home/coder/.platformio/packages/framework-arduinoespressif8266/bootloaders/eboot/eboot.elf" and ".pio/build/nodemcuv2-rf-ir/firmware.elf"
===================================================================================== [SUCCESS] Took 151.48 seconds =====================================================================================

Environment Status Duration
--------------- -------- ------------
nodemcuv2-rf-ir SUCCESS 00:02:31.479
====================================================================================== 1 succeeded in 00:02:31.479 ======================================================================================

启动日志

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
[15:37:03]*wm:[2] Added Parameter: server
[15:37:03]*wm:[2] Added Parameter: port
[15:37:03]*wm:[2] Added Parameter: user
[15:37:03]*wm:[2] Added Parameter: pass
[15:37:03]*wm:[2] Added Parameter: secure
[15:37:03]*wm:[2] Added Parameter: cert
[15:37:03]*wm:[2] Added Parameter: name
[15:37:03]*wm:[2] Added Parameter: topic
[15:37:03]*wm:[2] Added Parameter: ota
[15:37:03]N: Attempting Wifi connection with saved AP: 0
[15:37:06]N: IR_EMITTER_GPIO: 16
[15:37:06]N: IR_RECEIVER_GPIO: 2
[15:37:06]N: RF_EMITTER_GPIO: 3
[15:37:06]N: RF_RECEIVER_GPIO: 0
[15:37:06]N: Switching to RF Receiver
[15:37:06]N: OpenMQTTGateway modules: ["IR","RF"]
[15:37:06]N: ************** Setup OpenMQTTGateway end **************
[15:37:06]W: MQTT connection...
[15:37:06]N: Connected to broker
[15:37:06]N: Send on /SYStoMQTT msg {"uptime":3,"version":"version_tag","discovery":true,"ohdiscovery":false,"env":"nodemcuv2-rf-ir","freemem":31456,"mqttport":"1883","mqttsecure":false,"rssi":-29,"SSID":"xx","BSSID":"xxxxxxxxxx","ip":"10.20.111.1","mac":"xxxxxx","actRec":2,"modules":["IR","RF"]}

经测试工作正常

更新: OpenMQTTGateway获取到一堆raw不会用,然后换了ESPHome,库用的都是rc-switch,看了一些大佬们的操作,粗略操作了一下。能正常获取和发射信号,但是没有反应。看大佬们都用上了逻辑分析仪,433无线水很深我把握不住,博联那种成品我用过没啥问题,是我太菜了。T_T

针脚定义

RF gateway

Board Receiver Pin Emitter Pin
Arduino UNO D3 D4
ESP8266 D2/D3/D1/D8 RX/D2
ESP32 27/26 12
RF BRIDGE - -
RF BRIDGE 4 5
SONOFF RFR3 4 -
RF WIFI GATEWAY 5 -

IR gateway

Board Receiver Pin Emitter Pin
Arduino UNO D2 D9
ESP8266 D4 D0
ESP32 27/26 14