This is simple infrared sender/receiver controlled over MQTT. It uses the Homie MQTT convention and is based on Homie implementation for ESP8266 by Marvin Roger.
The wirring bellow is the one I used and worked for me. You will likely need to adjust the resistor sizes based on the voltage drop and max current for your IR diodes. The transistor is general purpose NPN transistor (I used BSY34)
I recommend to use platformio which will resolve all the dependencies for you, but to compile this sketch in Arduino IDE you have to manually install follwing libraries:
- Homie for ESP8266 and all it's dependencies
- IRremoteESP8266
- ArduinoJson
as well I recommend to install the Homie UI Bundle to data/homie folder. To upload the UI bundle you have to follow SPIFFS upload process if using PlatformIO or if you use Arduino IDE you may use arduino-sep8266fs-plugin.
Once you upload the sketch, you have to configure the node as described in Homie Getting Started Tutorial (this is where you device gets device id assigned)
- To listen for received IR codes, subscribe to MQTT topic
homie/<deviceid>/infrared/code
:
$ mosquitto_sub -h 192.168.1.50 -v -t 'homie/5ccf7fd38d01/infrared/code'
homie/5ccf7fd38d01/infrared/code {"name":"UNKNOWN: 0x42D74094","value":1121403028,"frequency":38,"type":{"id":-1,"name":"UNKNOWN"},"raw":[9100,4600,600,650,600,1750,600,1750,600,1750,600,650,600,1750,600,1750,600,1750,600,1750,600,1750,600,1750,600,650,600,650,600,650,600,650,600,1800,600,650,600,650,600,1750,600,650,600,650,600,650,600,650,600,650,600,1750,600,1750,600,650,600,650,600,1750,600,1750,600,650,600,650,600]}
- To send IR codes, publish to MQTT topic
homie/<deviceid>/infrared/code/set
:
mosquitto_pub -h 192.168.1.50 -t 'homie/5ccf7fd38d01/infrared/code/set' -m "{"frequency":38,"raw":[900,900,1800,900,900,900,900,900,900,900,900,900,900,900,900,900,900,900,900,900,900,900,900,1800,900]}";