Smart Relay Control for ESP32/ESP8266
- Web/Mobile Application (PWA)
- Integration with any Smart Home Assistant (such as Alise) via MQTT broker
- Web Hooks
- MQTT Protocol
- Open the ESP Launchpad.
- Select esp-relay and your desired platform.
- Install PlatformIO.
- (Optional) Modify the
credentials.h
file and, if necessary, customizeconstants.h
. You can change these parameters later through the Web UI. - Upload the filesystem and firmware.
Note: This repository contains a submodule. Please use the --recursive
option when cloning.
git clone --recursive https://github.com/DrA1ex/esp_relay.git
cd esp_relay
# Make script executable
chmod x ./upload_fs.sh
# Specify the platform: esp32-c3 or esp8266
PLATFORM=esp32-c3
# Set the environment: debug, release, or ota
ENV=release
# For OTA: set your ESP's address
ADDRESS=esp_relay.local
# Additional envs if OTA enabled
if [ "$ENV" = "ota" ]; then OTA=1 else OTA=0 ADDRESS= fi
pio run -t upload -e $PLATFORM-$ENV --upload-port "$ADDRESS"
./upload_fs.sh --upload-port "$ADDRESS"
Topic In * | Topic Out * | Type | Values | Comments |
---|---|---|---|---|
MQTT_TOPIC_POWER |
MQTT_OUT_TOPIC_POWER |
uint8_t |
0..1 | Power state: ON (1) / OFF (0) |
MQTT_TOPIC_NIGHT_MODE |
MQTT_OUT_TOPIC_NIGHT_MODE |
uint8_t |
0..1 | Night mode state: ON (1) / OFF (0) |
* Actual topic values decalred in constants.h
If you're hosting a Web UI that uses SSL, you'll need to set up a Secure WebSocket (wss://...
) server instead of the non-secure ws://
provided by your ESP. Browsers require secure socket connections for WebSocket functionality, so this configuration is essential.
To achieve this, you can use Nginx as a proxy to create an SSL-enabled WebSocket connection.
apt install nginx
Create a file at /etc/nginx/conf.d/ws.locations
and add the following content:
location /w_esp_relay/ws {
proxy_pass http://<YOUR-ESP-IP-HERE_1>/ws; # Replace with your actual service address
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
}
# You can create proxy for multiple hosts
location /w_esp_relay_2/ws {
proxy_pass http://<YOUR-ESP-IP-HERE_2>/ws; # Replace with your actual service address
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
}
After saving the configuration file, reload Nginx to apply the changes:
nginx -s reload
Note
Make sure to replace <YOUR-ESP-IP-HERE_1>
and <YOUR-ESP-IP-HERE_2>
with the actual IP addresses of your ESP devices.
Open WebUi in browser https://dra1ex.github.io/esp_relay/?host=ADDRESS/w_esp_relay