Back
Featured image of post 230V WiFi relay with D1 mini and ESP Easy

230V WiFi relay with D1 mini and ESP Easy

ESP Easy is a firmware designed to create devices easily with ESP modules. Here we’ll use a Wemos D1 Mini with a 230V relay shield.

ESP Easy is a firmware designed to create devices easily with ESP modules. Here we’ll use a Wemos D1 Mini with a 230V relay shield.

Loading firmware

First let’s clone Esptool from Github. Esptool is a A python-based, open source, platform independent, utility to communicate with the ROM bootloader in Espressif ESP8266 & ESP32 chips.

Clone it :

git clone https://github.com/espressif/esptool
And move to the cloned folder :
cd esptool

Download the last ESP Easy stable firmware from https://www.letscontrolit.com/wiki/index.php/ESPEasy#Loading_firmware and unzip it.

Then plug the D1 Mini and check the dmesg output :

dmesg

Output should be something like :

[ 3011.463165] usbcore: registered new interface driver usbserial_generic
[ 3011.463180] usbserial: USB Serial support registered for generic
[ 3011.481026] usbcore: registered new interface driver ch341
[ 3011.481044] usbserial: USB Serial support registered for ch341-uart
[ 3011.481066] ch341 3-3:1.0: ch341-uart converter detected
[ 3011.482045] usb 3-3: ch341-uart converter now attached to ttyUSB0

Then you are ready to load the firmware to the board :

./esptool.py --port /dev/ttyUSB0 write_flash -fm dio -fs 32m 0x00000 ../ESPEasy_R120/ESPEasy_R120_4096.bin

If everything is going well, output should be something like :

WARNING: Flash size arguments in megabits like '32m' are deprecated.
Please use the equivalent size '4MB'.
Megabit arguments may be removed in a future release.
esptool.py v2.6-beta1
Serial port /dev/ttyUSB0
Connecting....
Detecting chip type... ESP8266
Chip is ESP8266EX
Features: WiFi
MAC: 5c:cf:7f:d7:21:ea
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Compressed 411264 bytes to 278754...
Wrote 411264 bytes (278754 compressed) at 0x00000000 in 24.6 seconds (effective 133.6 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...

Configuration

You sould see a new encrypted network ESP_0. The password is espconfig. Once connected, all the configuration is web based. Let’s connect our module to our WiFi network.

ESPeasy setup
ESPeasy setup

One connected, you can proceed to main configuration.

ESPeasy configuration
ESPeasy configuration

From now, we can already use HTTP requests to change states of I/Os :

ESPeasy configuration
ESPeasy configuration

You can easily write a simple webpage with an ajax request :

<html>
<head>
<title>Test</title>
</head>
<script type="text/javascript">
function lightOn() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
console.log(xhttp.responseText);
if (this.readyState == 4 && this.status == 200) {
feedback = JSON.parse(xhttp.responseText);
document.getElementById('text').innerHTML=feedback;
}
};
xhttp.open("GET", "http://192.168.1.10/control?cmd=GPIO,5,0", true);
xhttp.send();
}
</script>
<button onclick="lightOn()">Light ON</button>
</html>

comments powered by Disqus
Built with Hugo
Theme Stack designed by Jimmy