Story

If you have a Wi-Fi connection, you may encounter some problems with your Wi-Fi router, such as disconnecting from the internet. Most of the time, you can fix this issue by power cycling your router.

To make this process easier, I've created a wireless switch that lets you turn the router off and on without needing to be near it. Press a button at your desk, and the router will be turned off for two seconds, and then it will turn back on automatically.

Both the sender and receiver are made using the Seed Studio Xiao ESP32C3. Right now, we use the ESP-Now protocol to communicate with the sender and receiver. One of the main advantages of using ESP-Now is that no extra wireless communication circuit is needed; the ESP32 devices talk directly to each other, which makes the project less complicated overall.

Supplies

TX Parts

RX Parts

Tools Used

Step 1: Designing in Fusion 360

Design is broken down into several levels for easy 3d printing

Step 2: 3D Printing

Due to its complex nature, I designed the object in parts, so we will need to assemble it after 3D printing. I used orange PLA and grey PLA. 3D printed all models in my cubic printer. In 0.2mm layer height and 30% infill

Step 3: Finding the MAC Address of Your XIAO ESP32C3

We are using the ESP-NOW protocol for communication between the transmitter (TX) and receiver (RX). For this, the transmitter (TX) needs to know the unique MAC address of the RX ESP32. You will need to run the following code on your ESP32C3 receiver (XIAO) to find its MAC address. After running this program, the MAC address will be displayed on the serial monitor.

My MAC address is 64:E8:33:8A:22:54

Code for finding the MAC address

#include<WiFi.h>#include<esp_wifi.h>voidreadMacAddress(){uint8_t baseMac[6];esp_err_t ret = esp_wifi_get_mac(WIFI_IF_STA, baseMac);if (ret == ESP_OK) {    Serial.printf("%02x:%02x:%02x:%02x:%02x:%02x\n",                  baseMac[0], baseMac[1], baseMac[2],                  baseMac[3], baseMac[4], baseMac[5]);  } else {    Serial.println("Failed to read MAC address");  }}voidsetup(){  Serial.begin(115200);  WiFi.mode(WIFI_STA);  WiFi.STA.begin();  Serial.print("[DEFAULT] ESP32 Board MAC Address: ");readMacAddress();}voidloop(){}

Step 4: TX Code

Before uploading the code we need to enter the MAC address of the our receiver which is 64:E8:33:8A:22:54 for me we need to add a 0x before it,

Then it will be 0x64, 0xE8, 0x33, 0x8A, 0x22, 0x54

Put that in this line of the code

// MAC address of the receiver

uint8_t receiverAddress[] = {0x64, 0xE8, 0x33, 0x8A, 0x22, 0x54};

TX code

#include<WiFi.h>#include<esp_now.h>// MAC address of the receiver (RX) ESP32uint8_t rx_mac[] = {0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX};  // Replace with actual MAC addressvoidsetup(){  Serial.begin(115200);// Initialize WiFi in STA mode  WiFi.mode(WIFI_STA);// Initialize ESP-NOWif (esp_now_init() != ESP_OK) {    Serial.println("ESP-NOW initialization failed");while (true);  }// Register peeresp_now_peer_info_t peerInfo;memcpy(peerInfo.peer_addr, rx_mac, 6);  peerInfo.channel = 0;  // use the current channel  peerInfo.encrypt = false;if (esp_now_add_peer(&peerInfo) != ESP_OK) {    Serial.println("Failed to add peer");while (true);  }// Register callback functionesp_now_register_send_cb(onDataSent);// Setup button pinpinMode(D0, INPUT_PULLUP);}voidloop(){if (digitalRead(D0) == LOW) {  // Button pressed// Send signal to power cycleuint8_t data[] = {0x01};  // Signal to RXesp_now_send(rx_mac, data, sizeof(data));delay(1000);  // Debounce delay  }}voidonDataSent(constuint8_t *mac_addr, esp_now_send_status_t status){if (status == ESP_NOW_SEND_SUCCESS) {    Serial.println("Data sent successfully");  } else {    Serial.println("Data send failed");  }}

Step 5: Rx Code

There is change need for the RX code

#include<WiFi.h>#include<esp_now.h>#define RELAY_PIN D0voidsetup(){  Serial.begin(115200);// Initialize WiFi in STA mode  WiFi.mode(WIFI_STA);// Initialize ESP-NOWif (esp_now_init() != ESP_OK) {    Serial.println("ESP-NOW initialization failed");while (true);  }// Register callback function (new format)esp_now_register_recv_cb(onDataReceived);// Setup relay pinpinMode(RELAY_PIN, OUTPUT);digitalWrite(RELAY_PIN, HIGH);  // Ensure relay is HIGH (closed) initially}voidloop(){// Nothing to do here}// Updated callback function with esp_now_recv_infovoidonDataReceived(const esp_now_recv_info *recvInfo, constuint8_t *data, int len){  Serial.print("Message from: ");for (int i = 0; i < 6; i++) {    Serial.printf("%02X", recvInfo->src_addr[i]);if (i < 5) Serial.print(":");  }  Serial.println();if (len == 1 && data[0] == 0x01) {    Serial.println("Power cycle signal received");powerCycle();  }}voidpowerCycle(){digitalWrite(RELAY_PIN, LOW);   // Open relay to cut powerdelay(2000);                    // Wait 2 secondsdigitalWrite(RELAY_PIN, HIGH);  // Close relay to restore power}

Step 6: Wiring Diagram of TX and RX

Wiring diagram of TX

Wiring diagram of RX

Step 7: Voltage Setting on Step-down Converter

Before assembling we need to preset the voltage on the step-down converter Connect your 12v source into IN+ and IN- and set the voltage to 5v. measure it from the OUT+ and OUT-- using a multimeter. it is used to provide the necessary 5v to XIAO ESP32C3

Step 8: RX Assembly

8.1

We can start the assembly by soldering a 10k resistor between G and S of the MOSFET

8.2

Now place the MOSFET into the 3D printed slot and melt the tab using a soldering iron to fix the MOSFET in place.

8.3

Glue both the step-down converter and XIAO ESP32C3 into the 3d print

8.4

Connect the antenna to Xiao and attack it on the side wall

8.5

Install both of the DC jack

8.6

Now complete all of the wiring according to the wiring diagram

8.7

Glue the front cap and close it

So we just finished the RX build

Step 9: TX Assembly

9.1

Put the push button in the button holder and bend the 4 terminals into the 3d print using a nose player

9.2

stick the antenna into the body of the 3d print and connect the antenna port to XIAO

9.3

Glue the button holder into the main body using superglue

9.4

Now push in the switch cap on top of the push button

So we're done with the build of both devices. Now, let's look at how to set them up.

Step 10: How to Set Them Up

It is so simple to set them up with your router just connect the 12v power from the adapter to the input DC jack of the receiver, then using a DC to DC male cable, connect the output of the receiver to the power input of the wifi router also power the TX push button using a USB power.