EspRelay project is a very simple IOT project to control a relay by MQTT messages.
Dual Relay capability added
- control a relay with MQTT messages
- OTA (On-The-Air) firmware update
Because of the OTA update you need ESP01 with 1MB flash (ESP01S)! In this example I used a 5V usb light. This is my way, you can choose yours. If you don't know how does it work, please don't use it.
For the first upload you will need an ESP01 programmer, i use this:
More info: https://www.diyhobi.com/flash-program-esp-01-using-usb-serial-adapter/
https://github.com/VorosEgyes/espRelay-ESP01S
Edit your platformio.ini file and make your first upload.
Copy and paste the content of the src\main.cpp into a new Arduino IDE sketch and copy the config.h file in your saved ardunio file. In the Library Manager you have to install:
- ArduinoOta : for OTA firmware update
- ESP8266WiFi : for Wifi
- DNSServer.h : for Wifi
- ESP8266WebServer : for WifiManager
- WiFiManager : WifiManager
- PubSubClient : MQTT
Please edit your config.h according to your parameters.
After your first upload search for EspRelayAP wifi network, and in the browser choose your LAN. Further help: https://github.com/tzapu/WiFiManager#how-it-works
Commands:
- mosquitto_pub -t "espRelay2/cmd" -m "RST" // Reseting the ESP01
- mosquitto_pub -t "espRelay2/relay1" -m "ON" // Switch Relay1 ON
- mosquitto_pub -t "espRelay2/relay1" -m "OFF" // Switch Relay1 OFF