WiFi controlled switch

Isaac Anderlik

Overview

My goal was to design a device that could switch the power from a wall socket on or off, depending on a user-defined pattern which is received via Wi-Fi. This would allow a user to, say, blink lights (or any device using an AC 110v power supply) using any custom pattern (in 1-second unit intervals).

General view

Hardware

The Wi-Fi module hosts an HTTP server which accepts a user input as an array of timing intervals. It then encodes those intervals and sends them to the EFM32ZG microcontroller. Those timings are used to control the output of the GPIO pins which gives a signal to either enable or disable the outlet, the timings are also used for an onboard LED which is used to display the output for testing purposes. The whole module can also be interfaced to modify the software using UART communication through a 115200Hz signal frequency.

The hardware is capable to control up to 4 independent channels, however currently only one of them is implemented in software.

Schematic Assembly

Software

The software for this project, developed using the Keil μVision IDE, includes an array loaded into memory which stores the timing values. The elements in the array are indexed and sent one after another to the timer's count register. They are pre-scaled by the timer so that they are counted down in 1-second intervals and, upon interrupt, the state of the LED/GPIO pins is changed and the timer count receives the new timer value which is in memory.

In order to load these timer values into memory, first the HTTP server must pack the user inputs (text from text boxes in this case) into hexadecimal values. This will allow the number of bytes to be sent to the server to be uniform and only requires 2 bytes per timing interval for a maximum of 2 * 256 + 2 = 513 bytes of data sent via POST request to the microcontroller. Those hexadecimal values are then decoded upon receival and loaded into the timings array.

Here is the user interface. Pressing the "Add text box" button creates a new editable text box and fills it with a random value not exceeding 127. Upon pressing the "Send" button, the data from the text boxed is collected, formatted, and forwarded to the unit's Wi-Fi module. The module itself operates as an access point and provides its own private network.

Final Thoughts

Designing the software for the HTTP server, while strenuous at times, was made very simple after I began using the Wireshark software. I was able to view the bytes of the HTTP requests that the server made so that I knew exactly how JavaScript was encoding the request (This was otherwise tricky with JavaScript's type casting). I would recommend and use Wireshark in the future for this as Web development can be tricky at times when it is performed at such a high level above the circuitry of the system. Overall, while I faced many unforeseen difficulties and challenges along the way, I learned a lot about the way these embedded systems are implemented from the ground up and I have gained a newfound confidence in my ability to take on similar projects in the future.

Downloads


Last modified:Mon, Jan 23, 2023.

00092