This shows you the differences between two versions of the page.
— |
walltimer [2007/04/27 00:23] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Wall Timer ====== | ||
+ | After reaching my limit with my unreliable D-Link 604+ ADSL router, I decided that manually power-cycling the thing was becoming a chore, and more importantly when I am asleep or my room is otherwise off limits to my housemates a crash means no connectivity for them, and no way to overcome it! | ||
+ | I'd been thinking of modding some junk I had to help me for a while, but it was only when I was prompted by an irate housemate that I took up the challenge. | ||
+ | |||
+ | ===== Junk transformed ===== | ||
+ | |||
+ | {{walltimer.jpg }} | ||
+ | I have an unused digital wall timer among my junk, it hasn't worked for some time now --- I suspect the inbuilt rechargable battery has died or similar because the LCD never displays anything and the '' | ||
+ | |||
+ | You can see from this picture ( which is the end product of my efforts ) that the LCD is still not working, but seems healthier than before. Who knows, perhaps it will magically start working? | ||
+ | |||
+ | I opened it up, and would you believe it was very nice and neat inside? Lots of ordinary components that any determined geek could understand. After turning the thing over in my hands a few times and giving it a thorough examining it was clear that all I needed to do was solder my own wires onto the 3 existing wires inside, which connected the relay system to the LCD/Control panel. | ||
+ | |||
+ | At first I soldered my wires to Vdd and CTL (the nice people of '' | ||
+ | |||
+ | I used a pair of wide pliers and firmly gripped the end of the plastic chasis, and tore off a neat rectangular section which I fed my wired through. Took a little rocking back an forth to make sure I got a nice clean slice. :-) | ||
+ | |||
+ | ===== Getting it hooked up ===== | ||
+ | |||
+ | Once I had a method of turning the mains on and off, I needed to interface this with my PC with a view to code a program which checks for internet connectivity and then power-cycles the router as needed. | ||
+ | |||
+ | First first thought was to use one of my PC's serial (RS232) ports to do this, as I have got some experience using them from my [[project|final year project]]. I did some [[http:// | ||
+ | |||
+ | {{ parallelport.jpg}} | ||
+ | |||
+ | In fact it was at this point that I realised there was something fundamentally wrong with my approach - I was trying to use the PC as a switch, which is not really in keeping with the TTL way of doing things. But being lazy I didn't want to resolder the wall timer, instead I tried using the parallel port. | ||
+ | |||
+ | I uncovered a sturdy source of info on [[google> | ||
+ | |||
+ | I had some trouble finding which pin was 'pin 1' on my parallel port (as none of the pages seem to feel this is an important detail). I found that for my own setup it was the bottom pin on the longer of the two columns((this is looking directly at the rear-end of my PC, with the motherboard mounted on the left of the case)). | ||
+ | |||
+ | I had some limited success with this approach, connecting my wired to data pin 1 (which is physical pin 2) and one of the grounds (pins 18-25) did indeed get the relay to turn on and off, but it made an awful buzzing noise when it was on, and a not-so-awful-but-still-audible buzzing when in the off state. Not that the noise was what bothered me, it's the fact that I have created something which is doing seriously dangerous things with mains power! | ||
+ | |||
+ | I summoned some effort, overcame my laziness and re-soldered my bastard of science. This time I got it right: I soldered to Vss and CTL. I then connected it up to my parallel port in the same manner, but had no success, so I reversed the wires and //then// it worked. I labeled my wires; the yellow tagged one is the drive, the other is the ground. | ||
+ | |||
+ | :!: I rebooted my machine to see what happens to the pins, and they remain on until the BIOS POST screen where they turn off, then when the WinXP logo fades in they pop on again, and after some delay they flicker a bit and stay on (I'm now fully booted and they' | ||
+ | |||
+ | ===== Writing and compiling my own control code ===== | ||
+ | It took a while to find a library I was happy with, and eventually I settled on [[http:// | ||
+ | |||
+ | After much a-do trying to get MS Visual Studio .NET to install properly, | ||
+ | |||
+ | **Note:** This is actually the second version of the code. | ||
+ | |||
+ | <code cpp> | ||
+ | // PowerCycler.cpp : Defines the entry point for the console application. | ||
+ | // | ||
+ | // Makes use of WinIO library to gain access to the parallel port, ensure | ||
+ | // that WinIo.dll, WinIo.sys and WINIO.VXD are in the same directory as | ||
+ | // the final executable, or in the environment path | ||
+ | |||
+ | #include " | ||
+ | #include " | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | #define MAX_ERRORS 3 | ||
+ | |||
+ | // Function prototypes | ||
+ | int ConnectivityController(); | ||
+ | int ManualOverride(char*); | ||
+ | |||
+ | int _tmain(int argc, _TCHAR* argv[]) | ||
+ | { | ||
+ | switch(argc) | ||
+ | { | ||
+ | case 1: | ||
+ | ConnectivityController(); | ||
+ | break; | ||
+ | case 2: | ||
+ | ManualOverride(argv[1]); | ||
+ | break; | ||
+ | default: | ||
+ | printf(" | ||
+ | printf(" | ||
+ | printf(" | ||
+ | printf(" | ||
+ | printf(" | ||
+ | } | ||
+ | } | ||
+ | |||
+ | int ManualOverride(char* command) | ||
+ | { | ||
+ | if(InitializeWinIo()) // | ||
+ | { | ||
+ | int bits; | ||
+ | if(strcmp(command, | ||
+ | { | ||
+ | printf(" | ||
+ | bits = 1; | ||
+ | } | ||
+ | else if(strcmp(command, | ||
+ | { | ||
+ | printf(" | ||
+ | bits = 0; | ||
+ | } | ||
+ | else if(strcmp(command, | ||
+ | { | ||
+ | printf(" | ||
+ | bits = (_inp(0x378) + 1) % 2; | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | printf(" | ||
+ | } | ||
+ | |||
+ | _outp(0x378, | ||
+ | ShutdownWinIo(); | ||
+ | return 0; | ||
+ | }else{ | ||
+ | printf(" | ||
+ | OutputDebugString(" | ||
+ | return 1; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | |||
+ | int ConnectivityController() | ||
+ | { | ||
+ | OutputDebugString(" | ||
+ | |||
+ | int errors = 0; | ||
+ | while(1) | ||
+ | { | ||
+ | CAtlHttpClient client; | ||
+ | |||
+ | printf(" | ||
+ | if (client.Navigate( " | ||
+ | { | ||
+ | errors = 0; | ||
+ | |||
+ | printf(" | ||
+ | |||
+ | printf(" | ||
+ | Sleep(5000); | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | errors++; | ||
+ | |||
+ | OutputDebugString(" | ||
+ | printf(" | ||
+ | |||
+ | if(errors >= MAX_ERRORS) | ||
+ | { | ||
+ | printf(" | ||
+ | OutputDebugString(" | ||
+ | if(InitializeWinIo()) // | ||
+ | { | ||
+ | _outp(0x378, | ||
+ | Sleep(5000); | ||
+ | _outp(0x378, | ||
+ | |||
+ | ShutdownWinIo(); | ||
+ | |||
+ | printf(" | ||
+ | OutputDebugString(" | ||
+ | Sleep(30000); | ||
+ | }else{ | ||
+ | printf(" | ||
+ | OutputDebugString(" | ||
+ | return 1; | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | This produces an 80k executable file. The important output is also sent to a debugger, so if you don't have a debugger or tool such as [[http:// | ||
+ | |||
+ | ===== Running it as a Service ===== | ||
+ | |||
+ | Now I've got it all working, the thing is powered off when it loses connectivity and is given 30 seconds to come back up before checking. So what's left to be done? Well, I do //not// want to have the console open all the time, ideally I'd want to run this thing as a windows service! Guess what? It is possible. I probably should have modified my source code and made a special build for this, but I have no idea how and by this point I was already fed up with wrestling MS Studio .NET :-( | ||
+ | |||
+ | Luckily I came across a set of windows NT 4 utilities from one of the resource packs ---'' | ||
+ | |||
+ | So all that remains now is to leave it running and see how well it copes. I'm a little concerned what it will do when I intentionally reboot the router (like when I change it's configuration). I'll do some testing on it soon enough. | ||
+ | |||
+ | ===== Epilogue ===== | ||
+ | It works very nicely, and have power cycled the router 3 times since I put it in place. All three times it did this before I had noticed I'd lost connectivity, | ||
+ | |||
+ | :!: Annoyingly, I've come across the root of my router problems((The "Proxy DNS" feature, which caches DNS entries to save bandwidth, was causing the problem, [[http:// | ||
+ | |||
+ | Still, it was fun to make. ;-) | ||
+ | |||
+ | **Follow-up: |