Network controlled Arduino retic system

Yes that’s a mouth full but over the last few weeks I have been playing with an Arduino based retic controller. After looking at some off the shelf solutions from the local Bunnings I wasn’t happy with the number of channels provided nor the control or expandability. So off I went to buy an Arduino and a bunch of relays and a rough plan. The idea is to wire all my solenoids to a set of relays managed by the Arduino which is programmed to trigger them for a certain period of time on the correct watering days. Additionally the long term plan was to add in fertilizer injection and rain/moisture sensors to be able better manage my gardens.

First step, all the kit you need.

So with all this kit you can effectively build a 16 channel system, with the capacity to expand to around 50 channels or so depending on what shields you have connected.

After getting all the gear there were a few issues to sort out. First is how do you track time on Arduino, unfortunately by default the 2560 does not have a RTC. Initially I had looked at some NTP based libraries but settled on the RTC module from Freetronics. With this wired up I started up a basic sketch and had my relays triggering at certain times without too many problems. Everything seemed ok so time to add in the Ethernet and LCD shields.

You end up with a rather tall stack like this.


Not too bad, not exactly pretty but then it’s going to be housed in a box anyway.

Getting the LCD and Ethernet working was pretty straight forward. There are plenty of libraries to deal with getting these working however where things become complicated is the fact that Arduino is really single threaded at heart so how do you still accept input whilst triggering something for a period of time? E.g. if you use a simple sleep the entire process halts till complete thus blocking any other code from running such as your LCD management or Ethernet code. The easiest way is to track the number of seconds and use that to create start and stop times, however the RTC library recommended by Freetronics doesn’t support a simple unix time stamp, and only reports in literal days, hours, seconds.

The solution after a great deal of messing around was to use the timer library which makes creating triggers and simple timers relatively easy. Once in place it was straight forward to trigger something. However yet again a new problem was found. Triggering multiple timers and mixing them in with the rest of the system made programming multiple “programs” for the retic zones complicated. Not impossible but lots of looping to figure out things resulting in it being rather slow in performance. Throw in this with the complexity of building a web interface this was fast becoming a right pain.

So the simplest way out was to drop most of the complexity from the Arduino and treat it as a simple controller accepting commands over Ethernet from a big PHP powered system with cron jobs on the back end. This makes things easy to program. So after dropping all the existing code I can now trigger an Arduino channel with a simple packet consisting of <channel>|<action>|<time>|<security code>. E.g. 1|1|10|***** would trigger channel one to turn on for 10 seconds and without the security code the trigger will be ignored. Simple and effective and means I can more easily build a web interface in PHP and spend more time designing that than messing with the Arduino side of things.

The only remaining functionality problem was how do I add things in like rain sensors or other inputs. A slight adjustment to the code now allows a return if a channel is an input which can then be acted upon. E.g. 1|2|***** would tell the controller to read an input from channel 1, and the standard 0,1 options for the action just simply switch on and off.

With the code in place I purchased a large weatherproof box and mounted the parts. The next item on the list is connectivity. I wasn’t keen on running a network cable the box, or at least I will eventually but want this working sooner rather than later. So a TP-Link WR702N was the quick fix, it’s a small credit card sized (although obviously not as thin) wireless access point that can also act as a client and bridge a device. This is the blue device in the image below. It runs off USB to you can easily hack the cable to run off the 5v supply from the Arduino making it a cheap solution compared to a WiFi shield.


So with connectivity sorted, power was the next obstacle. I needed a combination of 24v AC for the solenoids, 12v DC to drive the relay and ideally 5-12V DC for the Arduino. During testing I had been using a standard ATX power supply with the correct pins bridged to power it up. I then dug out my old M1-ATX power supply for my CarPC which wasn’t in use. This would give me a nice easy 5v and 12v regulated supply.

However I still needed to get 24v AC which was solved with a standard wall wart power pack. However I still needed to supply 12v to the DC-DC car PSU. I picked up a cheap $20 24VAC –> 12VDC adapter for security camera’s which worked well but the wiring looked messy and I had to mod the ATX plug to get it to power on.


In the end the solution was actually quite simple. It turns out the relay board has a 5v regulator on board to drop 12v down to 5v for some of the components on the board. I was able to tap into this and directly power both the Arduino and the TP-Link. This means doing away with the car PSU and it being a rather simple layout. 240VAC –> 24VAC –> 12VDC –> 5VDC with each voltage branched out to where it needs to go.


The image above shows the resulting relay board layout. To reduce any bleed or earthing the first relay needs to be switched on before power flows to any others. This also works as a master trigger for the master solenoid valve which you should always have in a retic system to prevent leaks causing large water bills.

So the end result of all of this is the following. Soon to be mounted in the cabinet outside and wired up.


An early version of the trigger code is listed below but doesn’t have the security option. I’m trying some other options at the moment to simply send a hash with a salt loaded into the Arduino to stop sniffing (just in case).


Microsoft KMS licensing quick tips

From the cmd line run the following.

View Current Counts
cscript C:\windows\system32\slmgr.vbs /dlv all

Uninstall KMS
slmgr /upk

Convert client from MAK to KMS
slmgr /upk
slmgr /ipk <KMS Client Key>

Set KMS Server
slmgr /skms

Recreate the NTFS change journal

Recently I have found a few machines having issues with their backup software. From the logs the NTFS  journal was missing.

Quick fix is to run this command substituting in your own drive letter.

fsutil usn createjournal m=2147483648 a=536870912 F:

Dynamic lists and mail migration in Exchange 2007

Just a couple of quick tips which have helped me recently. Unlike Exchange 2003, creating dynamic lists based on AD attributes has become a little more complicated. Granted there is a built in wizard which works for some basic queries but doesn’t have the fine grained control that I needed.

For example to create a dynamic mailing list which will contain all users who have been marked as being in say the Perth office. This refers to the office field which you can set through AD users and computers or via the Exchange console. To create this load your Exchange shell as admin and run the following.

New-DynamicDistributionGroup -Name ‘Perth Staff’ -OrganizationalUnit’ -Alias ‘PerthStaff’ -RecipientFilter { (Office -eq ‘Perth’) }

To break it down you are limiting your search scope with the –OrganizationalUnit which improves performance by not having to search the entire tree when you don’t need to. The -Alias is self explanitory and the –RecipientFilter is simply what you are filtering on and in this case its the Office field and the fact it equals Perth.

This is just a simple dynamic list, check out the Microsoft page here for more advanced examples and options.


Mail migration between mailboxes has always been a bit of a pain. In the past Exmerge was the tool of choice however this is no longer needed come Exchange 2007. This could be useful for archiving mail out from one mailbox to another on different storage (Exchange 2010 has archiving built in which is much better) or you can even go to PST for maybe permanent archival to tape or optical media.

Make sure you have the latest service and you can simply run the export-mailbox tool via the Exchange shell.

export-mailbox –identity source.mailbox -includefolders "\Inbox" -MaxThreads 4 –TargetMailbox destination.mailbox -TargetFolder Archive

You can filter this further if needed but it’s relatively straight forward and will pull all the mail you specify out and put directly into the target mailbox without having to go to PST in between or use Outlook.

Good luck and have fun.

Howto generate Exchange 2007 certificates

By default Exchange uses a self signed certificate. If you are allowing external access its best practice to use a CA signed certificate either by your own internal CA or an external 3rd party trusted CA.

So to generate yourself a signing request open an Exchange shell as admin and run the following.

New-ExchangeCertificate -GenerateRequest -SubjectName “” -IncludeAcceptedDomains -DomainName, -IncludeAutoDiscover -Path c:\mycert.req

To break this command down, –GenerateRequest and –SubjectName are pretty straight forward and define the primary subject for the certificate. –IncludeAcceptedDomains tells it to add any other accepted domains to the certificate, useful if you accept mail for multiple domains. –DomainName is for additional domains you wish to specify, sometimes you may have a split internal and external domain so this would be used in that instance. And –IncludeAutoDiscover is one that gets forgotten but adds the autodiscover domain name to the certificate. If you do not include your autodiscover domain or the domain of the server it is on then you may get certificate errors when launching Outlook.

So now you have your certificate request, either plug it into your internal CA to get signed or pass this on to a 3rd party to get it signed by them. You should get a certificate file back and once you do simply run the following from your admin Exchange shell.

Import-ExchangeCertificate -Path C:\certnew.cer

Next step is to tell Exchange to use the certificate. Upon importing you should get the thumbprint of the certificate. With this you can enable the certificate by running the following and substituting the thumbprint.

Enable-ExchangeCertificate -Thumbprint THUMBPRINT -Services SMTP,POP,IMAP,IIS

One gotcha that I have seen a couple of times now is that the IIS/SMTP certs don’t stick. This presents itself after a reboot when suddenly its reverted back to the original certificate. In these cases I have found it necessary to re-run the command with just IIS and SMTP like below.

Enable-ExchangeCertificate -Thumbprint THUMBPRINT -Services SMTP,IIS

And that should be it, your certificate will take affect immediately and you should be good to go.

One last note, its worth keeping in mind that your paths may vary in terms of the OWA, OAB and Autodiscover paths and you should check to ensure that these are all correct. Domain name mismatch is pretty common which can create error messages which have the potential confuse users.