Using GMail as a relay with Postfix

I fiddled a bit with this, so I thought I'd do a no-nonsense guide to doing this. There are other guides, but a lot of them are incomplete and will leave you with queueing issues or annoyances.

The science bit:

Edit /etc/postfix/main.cf:

smtp_use_tls = yes

# Send all mail through smtp.gmail.com
relayhost = smtp.gmail.com

# Stop getting a catpcha, hopefully.
smtp_destination_rate_delay = 60
relay_destination_rate_delay = 60

Now, edit /etc/postfix/sasl_passwd:

smtp.gmail.com myemail@gmail.com:MyPaSsWoRd

It doesn't have to be an @gmail account, it can be a GAFYD account, once you've logged into it once to activate it.

Then just generate the map file for the sasl_passwd file and reload. As root:

postmap sasl_passwd
postix reload

And you're done. Monitor your queue a few times over the first few days to make sure stupid stuff hasn't happened (the delay between mails might get tweaked), but in general this has worked for me.

Have fun.


Alive and Thinkin'

I am alive. Apologies to folks who were following the electronics stuff -- the short version is that it worked, although I didn't get to use it 'in anger' as such. The other thing I learned is that when traveling through UK customs on the week of a royal wedding, having a small plastic box with wires coming out of it and a 9v battery strapped to it with tape is not a clever thing to have in your car (thankfully the customs official had a sense of humour).

Since then I've been doing a bunch of for-money work, and only took time out this week to relax. I occasionally take a week off to hang around at home and get 'life administrivia' done. Think of it as a concrete block on the see-saw of work-life balance.

I've been playing around a bit with generalised messaging for domotics updates. I'm thinking of a centralised controller that can accept events from various signals, such as the Current Cost meter, a wifi device coming in range, or a small IC hanging off the doorbell circuit, for example. A lot of these devices don't have particularly fully-functional network stacks, so I'll have to bite the bullet and get the handful of ZigBee radios I got recently working. Doorbell will be the fun one, I think. My house already has a (private) twitter account, and DMs me for various stuff (unknown hosts grabbing a DHCP lease on the network, etc.). Adding more stuff to this is the idea.

I'm also interested in the idea of cloud applications with local storage or local encryption keys -- so all your data is stored encrypted on the server side, and only you have the keys, so the content is decrypted at render-time. Stuff like 1password does this with secure stuff like password databases, but I think web browsing machines are zippy enough to do this for userdata. I have to see if it's been done already (it probably has), but I want to do some fiddling with it.

So yes, same old. Too much science to do, never enough time.


My Eyes!

I've not had a lot of time to go at electronics in the past while (mainly a combination of work things and family things kicking my ass), but I got to some of it tonight -- The clever parts of the design and build are basically done, so what's left is producing the final piece.

Aside from the motion sensor parts, there's also the bright light, to mess with people's night vision. For this, I got 4 super-bright LEDs, and did monstrous things with solder to produce a 5x2 header, that was fully connected along the long side. This gave me the 4 LEDs connected in parallell. This is pretty bright with the 5v applied from the analog output of the Arduino:


The final result will be built on an Arduno Fio board, which only has a 3.3v signal (It's powered off a 3.7v LiPo battery), so I'll need to amplify that somehow. I'm thinking I might try to power the board and LEDs off a regular 9V instead, or have the LiPo powering the board and the 9V powering the buzzer and leds, gated on the signal line of the board with some transistors. I may be of course talking out my ass. I'm going to pick up some various transistors over the weekend and experimenting. My guess is the gate and emitter of a transistor need a common ground, which won't work with using separate power sources. We'll see.

Of course, deadlines, help. I'm supposed to be using this thing next saturday. So, full steam ahead.


Finding Day

One year ago today, a very small ball of fur decided to mew outside our front door in particular. We let her in and looked after her for a bit, and eventually decided she could stay.

We're not sure exactly how old she is, we're guessing se was about 6-7 months when she came to us, but I guess her finding day is as good a day as any to be happy she's around.

Happy finding day, Ping.


I Seeeeee Youuuuu

So, first steps. I picked up a few PIR Motion sensors. These are a specific kind, there are a few other kinds, but they should have datasheets. You might recognise the bulbous white shape of them from those motion-sensing light switches. They're about a fiver each and fun to play with.

The comments section on Sparkfun had a very good tutorial on basic use, but also explains the basic principles of its operation. It has 3 pins -- DC, Ground and Alarm.

Science Bit

The alarm pin is what's called an Open Collector, which means it's either connected to ground, or to 'nothing'. To better understand this, let's assume you don't know what a transistor is (I know I sure didn't a few weeks ago).

Speaking simplistically, a transistor is a component where you can vary one voltage based on a much smaller voltage. In this way you can amplify a voltage pretty easily.

Here's a diagram!

Usually transistors are tiny and embedded or are tiny and on a breadboard, but let's assume for a moment that it's a box with 3 wires coming out of it. They're called collector, emitter and base. Emitter is always connected to ground, and provides the reference voltage, or definition of 'zero'. Base is a small voltage in relation to ground, and the voltage applied to the base controls how much voltage is allowed flow between the emitter and the collector. The difference between the voltage on the base, and the voltage allowed through the collector is called the 'gain'.

However! The voltage on the collector doesn't come from nowhere. It has to be supplied, and the voltage 'allowed' to flow is defined by the voltage on the base. So, if you apply 3.3v to the base, and 9v to the collector (the voltage marked 'Vcc' on the diagram there), you get a certain voltage that's actually 'allowed' through the transistor, and can be used in other applications by connecting them before the resistor (At 'Vout' on the diagram).

The zig-zaggy thing there on the diagram is a resistor. We put it across the larger Vcc voltage to lower it a bit, since transistors are usually only rated to take a certain voltage. The function of Vcc and the resistor is to 'pull up' the voltage across the emitter and collector. This is why the resistor there is often called a 'pull-up resistor'.

Transistors are handy for switches when you want to control a large voltage using a small voltage. They're also useful if you want to take a tiny voltage you get from a signal somewhere and amplify it.

Anyway, why this is relevant is that an 'Open Collector' is the collector from a transistor that's available as a signal. However, instead of usual 'binary' signals that might produce a 'True' voltage or a 'False' lack of voltage, it's either connected to ground, or not. Whether or not it is connected to ground depends on the base voltage. My guess is that the PIR sensor circuitry provides the 'base' voltage and lets us use any Vcc voltage we want, in order to 'pull up' the output.

So, if you go look at the circuit diagram and build instructions in the tutorial mentioned above, it works just so. The one modification I made here is that as well as pulling up the voltage, instead of connecting back to the LED on the Arduino board, I connected up to a big old Piezo Buzzer I got in Maplin.

The finished build looked like this:

So, the end result is that when you wave your hand in front of the PIR, the buzzer makes an annoying noise. Success!

Next up would be making things a bit smaller -- There are smaller, cheaper Arduino boards you can get, and I'll do a build soon that's a little easier to get into a project box and lug around with you.



I've been back from the states for a week or so now, and really have been meaning to get back to the electronics stuff. However, jetlag jetlagged me, and oncall oncalled me. I have played a bit with the PIR motion sensors I got, and with XBee, which I have to summon the mental wherewithal to write up and document.

Hoping to get back to it this week, in between the million other things happening, both work and non-work. The slowly spreading damp patch coming from the cieling of one of the rooms of my house would be #1 right now :-)


Step 2: The Plan

Okay, I was talking last about my idea(s) for an electronics project, and I think I have enough of it thought about to sketch it out. I'll also point out where I got some of the specific parts for the project itself, in case you want to follow along at home (please don't, I don't know what I'm doing).

Those who are familiar with my escapades will know I'm into Airsoft, which is kind of like a bunch of grown men playing army with pellet guns. I've got a reasonable amount of kit, and have travelled quite a bit to various events and venues both Irish and abroad.

One of the venues I've been to a good few times is Sennybridge FIBUA Village in Wales. It's a Ministry of Defence training village that the British army uses to take pasty-faced youths and turn them into wet pasty-faced youths who want to go home. On a few weekends in the year, though, they open it up to pasty-faced middle-aged escapists to play 24-hour overnight Airsoft games. I've been to five of these so far, and I've another one coming up in April.

So, to the idea. One of the features of the game, of course, is being a sneaky git. It's the sort of game where World War I tactics of running line abreast at the enemy is unlikely to work. Sennybridge is comprised mainly of 2-3 storey buildings, which usually have between 1 and 3 entries. Usually you and a squad of 8 guys will take and hold the building until told otherwise. Sometimes this'll be at night, and you have to keep an eye open for people trying to take the building from you.

What would be nice is to be able to find out if someone's being a sneaky git and is sneaking up on you. So, something like a motion detection alert you can drop or conceal that'll let you know if it's time to watch those stairs.

Motion detection sensors are pretty easily obtainable, for less than a tenner. Sparkfun have one, and I'm sure there are other, possibly cheaper suppliers. After that it's about deciding what you do when you detect motion. So, I've ordered what I plan to do, in order of complexity (i.e. in order of likelihood to actually get done).

  1. Audible/Visible Motion Detector

  2. Pretty simple, really. If it detects motion, it makes an audible sound. You could also possibly switch it to 'night mode' where it makes a sound (so the person who set it off looks in that direction), and then it flashes a blinding white light, to screw up their night vision. I've picked up a X5 White LED PCB in Fry's that might do the job, if I can get enough power to it. Maplin also had a decent-sized buzzer, which you could make buzz with a couple of 555 timers. I like this idea because it could end up potentially costing less than 20 quid in parts, and I could make a few of them. It may not even require an Arduino (I know it doesn't strictly require an Arduino, but it may not require an Arduino even for an electronics leper like me).

    Incidentally, a great primer on 555 timers is in the Make: Electronics book, which I just read through on the train. They're tiny, cheap as chips (ho ho) and can be very powerful if applied correctly.

  3. Remote Motion Sensor

  4. A lot more complex, but potentially more effective. The sensor itself doesn't need to make a sound (although I could leave the flash in, since it has an effect). The sensor could alert me wirelessly and silently to it being tripped. I looked into a few options for this, including good old 802.11, but XBee seems to be interesting, and I've picked up a few XBee RF modems. Sparkfun and SK Pang have them, as well as Radionics.

    The sensor part could be quite similar to in Idea 1, except with a small antenna. I've also picked up some wearable LilyPad Arduino kit for the part attached to me. This can be powered from a couple of AAs or a small 3.7v LiPo (although probably AAs. I'm trying to limit my exposure to having lithium fires break out in my pockets). The alert could be audible, or could be via the LilyPad buzzer in a glove. So, someone sneaks into the building downstairs, and the back of my hand buzzes.

There are a few more ideas that came out of these, but this is the basic idea. Idea 1 is looking more likely, since I'm actually more likely to make it, the components are a lot cheaper (I'm entirely prepared for one or two of these to get stepped on, nicked or lost) and it's more likely to actually work reliably.

I've already done some exploratory work on XBee and motion detection, which I'll cover next. I've picked up a few PIR Motion Sensors and will document the fiddling next.