This project is focused around two devices, one based on an ESP32 and the other on the ESP8266.
Full details are covered in articles on Machina Speculatrix (Medium subscription required).
There are two main operations:
- SENDER: Responds to an MQTT message sent across the network and emits a corresponding IR signal.
- RECEIVER: Responds to an IR signal (eg, from a remote) and generates a corresponding MQTT message.
This project consists of four variations on a theme:
- IR_IoT_hub_basic: Sender and receiver for pretty much any Arduino IDE-compatible microcontroller. This is a 'scratchpad' app for playing around with IR signals. It has no IoT/network component. WORKING.
- IR_IoT_hub_receiver: Receiver-only version. Based on an ESP8266 board. WORKING.
- IR_IoT_hub_sender: Sender-only version. Also based on an ESP8266. WORKING.
- IR_IoT_hub_ESP32: Combines both sender and receiver functions. Based on an ESP32 board. You can choose at compilation time whether to use multitasking. The non-multitasking version works. The multitasking version not so much.
When the hub receives an IR signal from a remote, it sends it out over the network as an MQTT message using the topic home/irrem
.
The format of the message is:
<device_type>_<device_id>_<protocol>_<address>_<command>_<flags>
Here's an example:
IRHUB_10_8_0_68_0
The format is strict.
- device_type - 5 printable ASCII chars
- Five integer values (16-bit).
When the hub picks up an MQTT message on the topic home/ircmd
- using the same format as above - it generates a corresponding IR signal. Malformed messages will have unpredictable and not very entertaining consequences.
Combines both the above functions.
I eventually created two PCBs.
One uses the ESP8266 and is intended to be used as either a sender or a receiver. If you want it to be a receiver, you simply omit the IR LED and its resistor. If you want it to be a sender, you leave off the IR sensor and its supporting passives. Alternatively, you can populate all the components and decide later if it's going to be a sender or receiver by flashing the appropriate firmware.
The other PCB is for an ESP32 and is for the hub application.
The software expects two 'libraries' in your main Arduino libraries
folder. They are:
- MQTTconfig
- WifiConfig
Each of these just contains a header file with some defines. I've provided examples of these here. Just edit the header files and then move the folders into your libraries
folder.
In my case, I have two access points at home with different names (SSIDs) but the same password, which is why I've configured 'main' and 'alt' SSIDs. You can just set both SSIDs to be the same if you're using only one access point.
- GitHub repo for this project: https://github.com/mspeculatrix/IR_IoT_hub
- IRremote library: https://github.com/Arduino-IRremote/Arduino-IRremote
- Adafruit MQTT library: https://github.com/adafruit/Adafruit_MQTT_Library
I based these projects on the microcontroller dev boards I happened to have lying around. From an electronics point of view, they are so simple that they could be converted easily to work with your preferred choice of microcontroller. For example, the Raspberry Pi Pico W would be a good candidate. Just select the right pins for your needs.
That said, the code for the ESP32 multitasking version is somewhat specific to that microcontroller.
The boards I actually use are:
- Basic: Arduino Nano
- Sender & Receiver: NodeMCU 1.0 (ESP8266)
- ESP32: DoIT generic ESP32 Dev Module.
It's up to you which signals you want to respond to and which MQTT messages are treated as valid (and which signals you send as a result). This code just has some examples. Adapt for your own purposes.