Sunday 30 October 2011

Blinking lights on the LAN

The sorry state of my garden lights has taken one pathetic step to the brighter. I can now blink my garden lights over the local network, using a serverized version of the Lua script i wrote earlier to do the same over the command line. Okay, so it's one step better than ssh'ing into the box and entering relay commands over Bash :)

I first thought of learning some more Lua to make the script socket-aware. But then it hit me: Linux has all this built in, into a "super server" called inetd, which i've never actually used before but kinda know of due to its history of security issues. Still, i feel like such a late bloomer for never having used inetd before.

Here's how, if you're one of the inetd virgins. Edit /etc/services and add the name, port and protocol of my service. In my case, i called it relay 11647/tcp. Call update-inetd --add ...and a bunch of arguments separated by the t character, as one wonky string. Yeah, it's hairy.

I needed to make just one change to the Lua script. Since the script won't read command line arguments anymore -- and i don't know if it's by design or my deficiency -- i had to add if rel == Nil then rel, act = "*number", "*number" ) end into the code.

Still, now i can say echo 4 1 | nc gardengnome 11647 which is a sure sign about a turn for the better :)

Did this make any sense at all to you?

Thursday 27 October 2011

Ping watchdog with Powershell

We have one unreliable virtual server which sometimes just loses its network connection. Until we have a permanent solution, the temporary fix is to have the computer reboot if it loses network connection.

Note: There is nothing as permanent as a temporary solution. With that warning, let's get to it.

Step 1 - Produce the following Powershell script into c:binpingdog.ps1

$netup = new-object Test-Connection -quiet ""
if( $netup -eq $False ) {

Step 2 - Fix your security settings

Start Powershell. Enter Set-ExecutionPolicy RemoteSigned or whatever level you're comfortable with that'll still run your script.

Step 3 - Schedule it

If you're using Windows Server 2003 (like we, ungh) schedule a daily task to run %SystemRoot%system32WindowsPowerShellv1.0powershell.exe c:binpingdog.ps1

From the task's Properties, the Schedule tab, press the Advanced button. Tick Repeat Task, every 12 minutes (or whatever you fancy), and repeat for 24 hours.

If you're using Windows Server 2008 or later, you should be able to set the task to run evey x minutes right from the interface.

Step 4 - Check your logs

Keep an eye on the failing computer's system log to see if it's restarted when you looked away.

Monday 24 October 2011

Happy UN day

Greetings to everybody working in the UN, everybody who have worked in the UN and all who are to work for the UN. Especially this goes to my chums who i had the joy and privilege to work with in Timor-Leste some six short years ago. It was a great gig, wasn't it? :)


Thursday 6 October 2011

It blinks!

A while ago, i bought an Ethernet module from Sure electronics. I wasn't sure what to use it for or if i indeed would be able to use it for anything, but it was cheap and hey, you could connect it to the Ethernet. Can't be all bad :)

Having less than a raving success with controlling my garden lights with a Nanode, i decided i needed a break. And so i googled "Arduino Sure-electronics ethernet", and lo && behold(), up comes a blog post with just what i needed, but just didn't understand to expect: that it's really easy to interface an Arduino with the Ethernet, and that the magic is built on the EtherShield library which i was already using on Nanode.

So i soldered the seven pins needed to have the two devices talk with each other. Wired them together with neat and correctly coloured jumper wires. Copied the code into my editor. Changed the MAC and IP addresses. Verified the code ("It compiles! Ship it!"). Uploaded it to the Arduino board. And it - just - worked!

You can't imagine how excited i was when i was able to open up a web page, served from the Arduino, and was able to toggle a LED on and off over my LAN. I't just so neat! (or if you do know me, you can probably imagine just how excited i was :) I should have taken a picture, or a video!

So my thanks go out to Henrik Denhart who wrote the blog post and to Andrew Lindsay, coder and maintainer of the EtherShield library, and indeed the whole Arduino maker movement who with their enthusiasm and drive for openness make the platform such a wonderful thing it is!