I have added a web-based power control unit (PCU) to my private game
server. The PCU is based on the Atmel ATmega168 microcontroller
and the Microchip ENC28J60 Ethernet interface chips. This project
has proved great fun and adds a whole new level of convenience for the
guys who use my server.
The PCU allows me to visit a small web page, served by the 'mega168,
and turn on the server. I intentionally did not add any ability
to turn off the server from the web page, but could add that feature if
I change my mind later.
The foundation
This project is based on the Tuxgraphics Ethernet project, hosted by
Guido Socher and presented on his excellent web page at
http://tuxgraphics.org/electronics/200606/article06061.shtml
I adapted Guido's circuit slightly but my code is based very heavily on
his efforts. The resulting code is quite small; the entire
project fits in less than 10K of flash.
Here are the obligatory photos...
This photo shows the circuit board containing the ENC28J60 Ethernet
chip (top) and the 'mega168 MCU (center). The white, four-pin
connector on the left is the control port; it connects to the POWER
switch and a hard-drive power cable in the server PC case. The
clear cube on the right edge of the board is the 5 VDC relay that
closes momentarily to short across the PC's POWER switch.
This photo shows a close-up of the wiring on the Ethernet jack.
This jack has built-in magnetics and normally is soldered onto a
PCB. Since the pinout isn't friendly to a project board, I
mounted the jack upside-down, held in place with double-sided foam
tape, and used wirewrap to hook the jack into the circuit. Note
that the schematic shows wiring connections for a Magjack connector,
which I did not use. If you don't have a Magjack, you can use
this photo and the schematic to adjust your connections accordingly.
This photo shows a closeup view of the 5 VDC relay used to activate the
server PC. Since the 'mega168 MCU cannot drive the relay's coil
directly, I added 2N2222 transistor to the MCU's output line; the
transistor provides plenty of drive. Note that this relay, like
almost all currently available, has a built-in snubbing diode to
eliminate back-EMF damage to the transistor when the relay
switches. Therefore, you must ensure that you wire the relay's
coil correctly, paying attention to how pins 1 and 16 are connected.
The schematic
Here is the schematic as a PDF:
Web PCU
schematic
Note that the schematic shows the MCU as an ATmega328; either the '168
or '328 will work fine and have plenty of code space for Guido's
origninal firmware.
Wiring to the server PC
The control port has four pins for connecting to the server PC.
Pins 1 and 2 connect to a standard 4-pin Molex hard-drive power
connecter; wire pin 1 to GND (black) and pin 2 to 5 VDC (red).
The PCU tests pin 2 for the presence of 5 VDC in the server PC; if the
voltage is present, the PCU assumes the server PC is powered.
Pins 3 and 4 of the control port are wired to a pair of normally-open
contacts on the PCU's relay. When the PCU needs to power up the
server PC, it closes the relay for one second, shorting out pins 3 and
4 on the control port. These pins, in turn, are wired across the
POWER SWITCH connector on the server PC's motherboard. You can
usually find the connector on your PC's motherboard as a pair of pins
in a small cluster of similar pins along one edge. Check your
motherboard manual or inspect the silkscreen on your PC's motherboard
surface for location. Because the relay's contacts are just a
switch, there is no concern about polarity when connecting to the PC's
motherboard.
Using the PCU
I wired the
control port into the server's PC, then ran an Ethernet cable between
the PCU and a nearby hub. The PCU is powered from a small, 5 VDC
wall-wart. When I applied power, the green LED (next to the
Ethernet connector) lights to show that the PCU has a good Ethernet
connection.
The PCU firmware contains a hard-coded IP address; in my case, it's
192.168.1.238. I went to another PC in my house network, pulled
up a command line prompt, and tried pinging the PCU's IP address; it
responded to the pings properly.
I then opened up a web browser and went to the PCU's web page at
192.168.1.238/server; the PCU responded with the expected web
page. You can see what the web page looks like if the server is
not powered up.
All that remained was to open port 80 in my firewall to route HTML
requests to the PCU board. Now my server, which address exists on
the Internet as a dynamically served location, can be reached by my
gaming buddies. If one of them needs to power up the server so
they can do some gaming, they just aim a browser at the server's page,
check the box and click the button; done! Since I have disabled
the ability to turn off the server from the web, I don't need to worry
about anyone accidently turning off the server while I'm in the middle
of a non-gaming task.
This has been a lot of fun to work on and has already proved popular
with the guys in my gaming group. This project uses the ENC28J60,
which has been around for quite a while and has a few drawbacks.
When combined with the small memory footprint of the 'mega168, you end
up with a board that can serve only a single TCP/IP buffer; a fact
built into Guido's code. Next time I build something like this, I
will probably switch to the newer Microchip
ENC424J600,
which has some excellent features, including an on-chip RAM buffer
large enough to hold 16 full TCP/IP pages.
Home