Selective Routing Using DD-WRT & OpenVPN

 

This is a quick guide on how I managed to configure OpenVPN on DD-WRT such that only traffic from some LAN clients and some ports is routed over the VPN tunnel.

Recently I signed up for a nice little VPN service Tiger VPN which so far seems quite nice – FYI, they have not asked me to recommend them or paid me in any way to say nice things about them. I just genuinely like the service 🙂

They supply OpenVPN configuration files so that you can easily roll your VPN client of choice if you don’t want to use their own client and they even have a script to automagically install on your DD-WRT enabled router.

The problem is that by default the setup will route all of your network’s outbound connections over the VPN.

I have managed to create a configuration which does the following:

  • Routes all traffic from a single LAN IP over the VPN.
  • Blocks traffic from the same LAN IP from reaching the internet when the VPN is down
    • This is often referred to as a kill switch.
  • Routes all traffic destined for a specific port over the VPN
  • Prevents requests to the same port when the VPN is down

Under Administration > Commands in the DD-WRT GUI, save the following as a custom script:

#!/bin/sh
# Some MASQUERADE line that I don't really understand.
iptables -I POSTROUTING -t nat -o tun1 -j MASQUERADE

# Set the default route for table 200 as over the VPN
ip route add default dev tun1 table 200

# Assign all outgoing connections from 192.168.11 to table 200 (so they go over the VPN)
ip rule add from 192.168.1.11 table 200

# Assign all packets marked with 11 to table 200 (so they go over the VPN)
ip rule add fwmark 11 table 200

# Flush the cache
ip route flush cache

# Mark all tcp packets whos destination port is 563 with 11 (so that it will be routed over the VPN)
iptables -t mangle -I PREROUTING --dport 563 -j MARK --set-mark 11

Under Administration > Commands, save the following to the firewall script:

# Prevent 192.168.1.11 from reaching the internet directly (so no connection if VPN down)
iptables -I FORWARD -s 192.168.1.11 -o vlan2 -j DROP

# Prevent 192.168.1.11 from connecting to port 563 directly (so no connection if VPN down)
iptables -I FORWARD -s 192.168.1.11 --dport 563 -o vlan2 -j DROP

The next step is a little bit trickier. Basically you have to use the DD-WRT GUI to configure as many of the OpenVPN settings as you can (based on what your provider specifies) and then do the rest in the ‘additional config’ box.

Use the DD-WRT OpenVPN documentation to help you identify which GUI settings correspond to which OpenVPN properties. Each time you click ‘Apply Settings’ you can check the raw generated config vis ssh by looking at /tmp/openvpncl/openvpn.conf

My settings for TigerVPN look like this (username and password removed obviously):

DD-WRT OpenVPN Settings

Under additional config for OpenVPN client I have the following:

# Write to a log file for easy viewing
log /tmp/tigervpn.log

# Mute messages that repeat a bunch of times
mute 50

# Do not accept the routes provided by the VPN server
# (will manage those myself)
route-nopull

# Keep the connection alive and attempt to reestablish it if it dies
keepalive 10 60

# Additional settings specified by VPN provider
tls-client
remote-cert-tls server

# Dont use auth-nocache as it prevents reconnection due to a bug
# auth-nocache

# Script to run when the link is established
# This sets up my custom routes and iptables rules
up /tmp/custom.sh

The really important setting there was the route-nopull. What this does is prevent the OpenVPN client from automatically installing routes provided by the VPN server. We do this because we want to use the routes set up in our scripts.

The final generated OpenVPN config (viewable under ‘/tmp/openvpncl/openvpn.conf’ on the router) looks like this:

ca /tmp/openvpncl/ca.crt
management 127.0.0.1 16
management-log-cache 100
verb 3
mute 3
syslog
writepid /var/run/openvpncl.pid
client
resolv-retry infinite
nobind
persist-key
persist-tun
script-security 2
dev tun1
proto udp
cipher aes-256-cbc
auth sha1
auth-user-pass /tmp/openvpncl/credentials
remote zur.tigervpn.com 1194
comp-lzo adaptive
tun-mtu 1500
mtu-disc yes
fast-io
tun-ipv6
# Write to a log file for easy viewing
log /tmp/tigervpn.log

# Mute messages that repeat a bunch of times
mute 50

# Do not accept the routes provided by the VPN server
# (will manage those myself)
route-nopull

# Keep the connection alive and attempt to reestablish it if it dies
keepalive 10 60

# Additional settings specified by VPN provider
tls-client
remote-cert-tls server

# Script to run when the link is established
# This sets up my custom routes and iptables rules
up /tmp/custom.sh

 

Advertisements

Simple Solenoid Driver

Intro

Recently I have been experimenting with CO2 injection for my planted aquarium and was interested in using a solenoid valve to control the CO2 flow, turning it off at night when the plants don’t need it. Since I have just upgraded my lighting to a DIY LED setup it would seem sensible to use an Arduino with a Real Time Clock to control both the lighting (allowing for gradual sunrise/sunset emulation) and the CO2.

In doing some research I found a very interesting article about the proper way to drive a solenoid which drastically reduces power consumption. The original article can be found here:

http://m.electronicdesign.com/analog/what-s-all-solenoid-driver-stuff-anyhow

I encourage you to read it as it goes into a lot more detail and has some further revisions of the design that add features over and above the basic design I have implemented.

Video

I have actually created two videos about this circuit. The first is the full version – it’s quite long (around 50 minutes) because it contains all the mistakes, debugging and thought processes that go along with building a circuit like this. Choose this video if you have some time and want to take the journey along with me and laugh at my bumbling approach.

The other video is a more condensed look at the circuit, with all the mistakes and most of the bumbling edited out. Its about 20 minutes. Choose this one if you just want to quickly learn how the circuit works, see it working on a breadboard and aren’t interested in following my stream of consciousness as I build it.

Circuit Diagram

Below is the circuit diagram. Please note that capacitor C2 is the smoothing capacitor I had to add on to the circuit at the end of the video. It may not be absolutely required depending on your power supply, but it is probably a good idea to include it for good measure.

Also note that you should choose the value for resistor R1 depending on the resistance of your solenoid and the voltage required to hold it open reliably. I explain how to do this in my video.

Circuit Diagram

ISTA Max Mix CO2 Reactor Review

Intro

I’ve recently been getting a lot more into my aquarium hobby and as a part of that journey I have been experimenting with CO2 injection. The general consensus on aquarium CO2 is that CO2 reactors are probably the best way to get CO2 into the aquarium and frankly that makes sense.

One of the other very popular methods is by using a ceramic diffuser in the aquarium that basically just produces bubbles like an air stone, but really really tiny bubbles. These work great, but you can be pretty sure that some of those bubbles (most in my experience) will make it to the surface of the water and escape into the atmosphere where they are essentially wasted.

Reactors on the other hand are plumbed into your filtration system and are designed to create a container from which no CO2 bubbles can escape, thus forcing them to stick around until they are fully dissolved. This means no wasted CO2 – Great right?

The question is, how do you implement one on the cheap? I was looking into building my own DIY one and stumbled across the ISTA Max Mix CO2 reactor on Amazon. It cost 20 quid so I decided to give it a go.

The Review

Conclusions

I see a lot of reviews of the ISTA Max Mix CO2 reactor that totally dismiss it as crap and frankly I can imagine how that happens – anything that leaks and dumps water all over your floor is going to quickly draw your ire. However I think that most of these reviewers don’t take this thing for what it is – a cheap mass produced product – and as such don’t give it the initial preparation and care that it needs so badly.

So in summary, yes this thing is worth 20 quid, but only if you are prepared to invest a little time and effort into taking the steps I outlined in my review video.

Sky Fibre Broadband with DD-WRT

I recently moved house and switched to Sky Fibre (FTTC) broadband.

Overall it seems like a pretty good service – customer service seems excellent and they don’t do traffic management. So great right?

The Problem:

In order to use their service, Sky force you to use their noddy ‘Sky Hub’ by using MER authentication. They actually install a hidden username and password specific to you onto the router they send you – only that router will be able to connect! They will also not give you this password if you ask for it. This means that even if you have your own VDSL modem, it won’t be able to connect. Rubbish.

The Solution:

  1. Use WireShark to sniff the DHCP requests emanating from the Sky Hub to find the credentials.
  2. Hook your DD-WRT router up to the line via a dedicated VDSL modem
  3. Configure DD-WRT to send the credentials you sniffed earlier when requesting a WAN IP address.
  4. Profit?

Prerequisites:

  • This guide assumes you have an S101 or S102 Sky hub.
  • You have successfully connected your noddy Sky Hub to the internet and it is working happily.
  • You will need a separate dedicated VDSL modem.
    • N.B. You need a modem, not a router.
    • See below for list of appropriate modems.
  • A router with DD-WRT flashed on it already.
    • I am using an Asus RT-N66U which is super awesome btw.
  • Have installed WireShark – UPDATE: Not required any more (see below)
    • N.B. On OSX WireShark takes ages to start the first time (like up to 5 minutes!) – give it a while.

Why DO I need a VDSL Modem?

The vast majority of DD-WRT compatible routers have an ethernet WAN port. They require a separate cable / ADSL / VDSL modem.

For Sky’s FTTC service the last stretch from the cabinet to your house uses VDSL over a copper twisted pair telephone line. This line is installed by OpenReach and as such, you can use one of Openreach’s VDSL modems which can easily be sourced on Ebay. Just search for one of the following:

The Huawei model is the better option since is is much more hackable than the second option. See: http://huaweihg612hacking.wordpress.com

Steps:

Obtain Your Username & Password

UPDATE: Thanks to the commenters who have reported that you can use the following site to generate your username & password: http://www.ph-mb.com/products/sky-calc

Below are the instructions of how to extract these the hard way:

  1. Connect your Sky Hub to the power and to your computer using an ethernet cable.
    1. Have nothing else connected to the Sky Hub. Especially not the telephone cable or separate modem.
    2. Make sure you connect with and ethernet cable, not WiFi.
  2. Follow the video below to obtain your credentials using WireShark:
  3. Record the username and password you obtained. It should look something like this:
    a0a0a0a0a0a0@skydsl|abcd1234

    From now on we will refer to this as your ‘client identifier’ since that is the technical term for it.
    N.B. You should notice that the first part of your client identifier is your MAC address. The part after the ‘|’ is your password.

Set Up Your Modem & DD-WRT Router

  1. First connect your Modem, router and PC together as per the diagram below:
    Sky FTTC DD-WRTN.B. The diagram above shows a face-plate with a built-in microfilter. If you don’t have one of these then you will need to also use a separate microfilter.
  2. Verify that the power and DSL lights on your modem are solid, indicating a good DSL connection. The Lan1 light on your modem should also be lit, but may be flickering occasionally.
  3. SSH onto your DD-WRT router.
    1. If you don’t know how to do this then read this and do some Googling.
    2. You can enable SSH access on you router using the web GUI.
    3. Windows users are encouraged to use Putty for SSH, OSX and Linux users can just use the Terminal app.
  4. We need to figure out which version of udhcpc is installed on your router. In recent versions of DD-WRT, the udhcpc binary was updated and the command needed changed. This step will help you figure out if you have the old or new version and therefore which command to use.
    Execute the following command on the router via SSH:

    udhcpc --help

    This should print out the various arguments that udhcpc accepts. You should see either a line like:

    -c,--clientid=CLIENTID Client identifier

    (You have the old version of udhcpc)

    OR

    -x OPT:VAL	Include option OPT in sent packets (cumulative)
    		Examples of string, numeric, and hex byte opts:
    		-x hostname:bbox - option 12
    		-x lease:3600 - option 51 (lease time)
    		-x 0x3d:0100BEEFC0FFEE - option 61 (client id)
    

    (You have the new version of udhcpc)

  5. Now we’ll construct the command to get DD-WRT to connect to the internet.
    1. If the udhcpc you found in step 4 was the old version then the command you need is:
      udhcpc --background -i vlan2 -p /var/run/udhcpc.pid -s /tmp/udhcpc -c "mac_address@skydsl|password_from_wireshark"
      

      Note that you need to replace the -c section with your client identifier you found earlier. You need the quotes.

    2. If you found that it was the new version, then the command you need is a little different.
      1. Use this website to convert your client identifier to hexadecimal. Convert the whole client id string from the start of your mac address to the end of the password (including the ‘|’ symbol).
      2. The command you need is:
        udhcpc --background -i vlan2 -p /var/run/udhcpc.pid -s /tmp/udhcpc -x 0x3d:YOUR_HEX_STRING_HERE
        

        Note that you need to replace YOUR_HEX_STRING_HERE with the hexadecimal version of your client id.

  6. So let’s test it!
    1. SSH into your router.
    2. Kill all existing udhcpc tasks using the following command:
      killall udhcpc
    3. Take the command you constructed in step 5, remove the –background and execute it. You should see output like this:
      udhcpc (v1.19.4) started
      Sending discover...
      Lease of 111.222.333.444 obtained, lease time 3600

      If things aren’t working properly, you will just see the ‘Sending discover…’ line repeated as udhcpc re-tries. Let it make a couple of attempts, but in my experience when it is working, it works very quickly.
      If it isn’t working then double check everything is wired correctly and that the DSL light on your modem is on. Failing that, try reverting back to the Sky Hub and check that still works. If it does, try all the steps again.

    4. Once you have obtained a lease your internet connection should be working! Hooray!
  7. Time to set this up permanently so your router connects automatically after each reboot.
    1. In the web GUI of your router under ‘Administration > Commands’ enter ‘killall udhcpc’ followed by the command you constructed in step 5.
      1. Include –background this time.
      2. The killall and command from step 5 need to be on separate lines.
    2. Hit ‘Save Startup’.
    3. Restart your router – your internet connection should now work.
  8. Put the Sky Hub back in the box in a cupboard where it belongs.

FunctionFlip on OSX Yosemite

Those of you who have read my previous post Google Music & Hype Machine keyboard controls on Mac OSX will know that I use a neat little tool called FunctionFlip so that I don’t have to hold the fn key to use the F1 through F12 keys.

Unfortunately I recently upgraded to OSX Yosemite and found that FunctionFlip no longer worked. It complained that it needed me to “Enable access for assistive devices” in the system preferences. OXS Yosemite does not have that feature. Hmm.

Anyhow, I manages to figure it out. The process is hard to explain but easy to do so I have created a video guide – it only takes 2 minutes.

Please note that I am assuming that you have installed FunctionFlip 2.2.2 already.

Enjoy 🙂

UPDATE 14-01-2015:

The above solution works great, however I found that after a reboot FunctionFilp was not working and required me to manually stop it and start it again from the preferences.

Miro in the comments below was facing the same problem and his investigation led me to a solution:

  1. Navigate to Macintosh HD/Library/PreferencePanes/
  2. Move FunctionFlip.prefPane to somewhere like your Desktop
  3. Double-click on FunctionFlip.prefPane to re-install it.
  4. Reboot and check that FunctionFlip is working 🙂

Many thanks to Miro for helping to get to this solution and please let me know in the comments if it works for you.

Adding a SIM card to the Photon Q 4G LTE

Context:

Let’s face it, the people want candy-bars. The European and North American smartphone markets are all about thin, lightweight glossy monoliths to fawn over and gently caress in a way that would sicken Charles Babbage.

“But Charlie! I yearn for the days of old, when men were men and keyboards were king. Touch screens are for teenagers and arthritic pensioners.”

All joking aside, some of us are quite happy to sacrifice a little svelteness for the clearly superior utility of a full keyboard. Who enjoys typing even a moderate length email on a touch screen keyboard? Chumps! That’s who. So, what choice do we have? In Europe the last full qwerty device was the HTC Desire Z. This was the best handset I have ever owned, hands down – I used it for years. The only problem was that it was getting a bit slow. I kept it going with Cyanogenmod, but the poor thing just didn’t have enough RAM to handle JellyBean with any gusto. In the US the pickings are a little better:

  • Motorola Droid 4 – A very nice looking little device but at the time of writing the CyanogenMod support for this device was next to zero which is a deal breaker.
  • T-Mobile myTouch 4G Slide – It’s pretty ugly and the keyboard sucks. It’s also not exactly a top-tier device and so has mediocre specs.
  • Motorola Photon 4G LTE – Another winner from Motorola on the design front, marred only by Motorola’s crap software, something easily fixed by Cyanogenmod.

So the path appears to be clear – import the Photon 4G LTE from the States right? Wrong!

The Problem:

Unfortunately, the Photon 4G is sold exclusively by Verizon, uses CDMA networks and does not have a SIM card slot. It is capable of using 3G networks, but only on a special (read über expensive) contract with Verizon which you can’t get outside of the states anyway. Indeed, the situation is grim.

The Solution:

Crack out the soldering iron and crank it up to eleven! Yes, that’s right, thanks to this enterprising chap it is possible to install a SIM card slot into the Photon 4G. You can find the original XDA Developers thread here.

Prerequisites:

  • A flagrant disregard for warranties.
  • A hot air reflow station. I used and recommend an Aoyue 850A.
    • Search Ebay. Expect to pay £80 – £100 for a decent unit.
    • No, you cannot do this with just a soldering iron.
    • No, you cannot just use a heat gun or blowtorch – the air/gas moves to fast and will just blow half of the components off the board the moment the solder melts. Seriously, some of the components are like grains of sand.
  • A decent soldering iron.
  • A Dremel with a decent cutting wheel.
  • Several SIM card slot assemblies from the Samsung Galaxy S3 like this:
    i9300 sim card and micro sd assembly

    • You need several because I guarantee you will melt at at least two before you get it right. They are mostly made of tiny plastic parts which melt almost instantly during soldering.
    • You can find them for a few quid on Ebay quite easily.
  • Some fine, enamelled wire – I used the wires from an old pair of headphones.
  • Helping hands with a magnifying glass – like this.
  • Long precision tweezers.
  • Torx 5 screwdriver.
  • A steady hand.
  • Patience. It took me several attempts to get it right and getting angry or impatient with it does not help.
  • Read this whole guide before you start!

The Guide:

Phase 1: Flash CyanogenMod

In order for this mod to work, you need to ditch the stock ROM. I used CyanogenMod. To do this you will need to:

  1. Unlock your bootloader. See Motorola Bootloader Unlock.
  2. Flash ClockworkMod Recovery (or similar).
  3. Flash CyanogenMod. Rom here.

In this guide I will not cover exactly how to do this as there are loads of guides already out there and frankly I did it ages ago and can’t remember the steps clearly. The XDA developer forums are your friend.

PHASE 2: Prepare the board

  1. Set your hot air torch to about 300 ºC with a medium air flow (3 on Aoyue units).
  2. Clamp the Galaxy S3 SIM card assembly in your helping hands and using tweezers, gently peel the flexible circuit board element away from the sim card slot whilst heating the contact points using the hot air torch until the solder melts. Completely separate the sim card holder from the circuit board in this manner. Take care not to over-heat the assembly as you can easily melt the plastic inside.
  3. Disassemble the handset by following this video: You don’t need to follow the whole video, just up to the point where you have separated the main board from the display.
  4. You need to remove the plastic mounted keyboard contacts so that you don’t melt it when soldering. This is essential. Lift the main board out of the handset, turn it over and GENTLY peel the plastic off as shown: IMG_20130608_014448 Set the sticky plastic aside somewhere where it won’t get any dust or other detritus stuck to it.
  5. Remove the EM shield covering the 3G chip we are going to remove. That’s this one highlighted in red: IMG_20130608_013418 To do this you need to use your hot air reflow station.
    1. Place some small pieces of metal over the MicroSD card slot and other surrounding components to protect them a little from the heat. I used a couple of coins.
    2. Set the temperature quite high – I had to use around 430 ºC – and use the hot air torch to evenly heat the whole EM shield.
    3. After 20 – 30 seconds you should be able to lift the shield clean off with your tweezers.

    Here is a video of CornholioGSM demonstrating how to do this:
    N.B. I recommend you practice doing this on a scrap board to get your eye in before you start on your £200 handset.

  6. Use the same technique to remove the chip underneath: Really do take extra care with the tweezers because the resistors and capacitors around the chip are important and are like motes of dust.
  7. Use the same technique to remove the EM shield from the chip highlighted in red below: IMG_20130608_013418 Take care not to touch any components underneath the shield – we are only removing the shield to make a bit of room for the SIM slot when we add it later.
  8. When you are done your board should look like this: IMG_20130608_022142

PHASE 3: Prepare your wires

Now it may seem like overkill to have a whole phase for something as trivial as preparing wires however getting this right has taken years of trial and error messing with this kind of enamelled wire so I think it is worth sharing my technique.

  1. Select a sacrificial offering from your collection of old/knackered headphones, cut a length of wire and strip off all the rubber sheath.
  2. Ensure that the inner wires are the enamelled kind and don’t have their own rubber sheath.
  3. Separate the twisted pairs of coloured wires and create 5 equal length bundles of wire about 10 cm long. Twist each of the bundles together so that you have 5 enamelled wires. Pro tip: Some wires are twisted with nylon fibres for strength. Carefully untwist and remove these fibres as the residue they leave when they melt seems to interfere with the tinning process.
  4. Heat up your soldering iron on quite a hot setting (I usually use about 370 ºC) and glob a bead of solder onto the tip.
  5. Dab the tip of each wire into the solder bead and hold it there for a few seconds in order to tin the end. Don’t leave it to long or the heat will burn the enamel off the wire above the solder which will cause a short later.
  6. Trim the tinned ends with scissors or snips so that only less than a millimetre of the end is tinned.

Phase 4: Soldering

The following picture shows you which points on the board go to which points on the SIM card slot:

connections

Basically you need to solder the wires you tinned earlier as shown in this diagram. This is friggin difficult, and impossible if you have not tinned the wires you are going to use before you start (see above).

As such, here I can only really offer you hints and advice rather than steps:

  • Solder all the wires to the sim card slot first as that is the most difficult part. It melts almost instantly.
  • Do not try and solder it with the sim card inserted, this does not work. Inserting the sim causes compression on the contacts and leads them to warp the moment heat is applied.
  • Test that the sim card can still be inserted and removed after soldering and before trying to solder to the phone.
  • Less is more. You only need a tiny bit of solder and the connection only needs to be electrically sound – it won’t be load bearing. Don’t be tempted as I was to splurge more on ‘just to be sure’.
  • When you solder them, make sure you orient the wires as shown in these two images below:
    1. When soldering to the main board:wire_layout_1
      I also recommend adding a thin strip of electrical tape to provide added insulation as shown in case the enamel on the wires creeps up with the heat far enough to short with the large solder pad.
    2. When soldering to the sim card slot:wire_layout_2

Here is the soldering pr0n from my own adventures:

Before you attempt the next step, for goodness sake test that everything is working!. Best to jiggle things around a bit to make sure there are no dodgy connections. I had a few issues with shorts and dud contacts.

Phase 5: Nearly There!

If you’ve got this far, well done! But don’t rest on your laurels… The next part is not quite as fiddly, but in your excitement you can easily wreck all the good work you have done so far. As I did. Twice.

  1. Test the positioning of your freshly soldered sim card holder. You will need to position it so that it is almost encroaching on the components you removed the EM shield from earlier, so that it is flush with the edge of the main board. You can see how I positioned mine further down.
  2. Score lines on the main board where the wires soldered to the sim card slot will lay. This will mark the borders of a channel you are going to cut for them using your dremel:
    IMG_20130609_093026
  3. Very carefully use the cutting wheel of your Dremel to cut a shallow channel in the board just deep enough for the wires to fit in – about half a millimeter.
  4. Use a glass-fiber abrasive pen or gentle scraping with a knife blade to expose some of the copper on the board so that you can solder the sim card slot to it.
  5. Solder the slot on like so:

    Things to consider:

    1. It works a lot better if you pre-heat the general area of the board with your hot air reflow tool before attempting to solder – the board acts as a pretty effective heat sink.
    2. Take care not to over-heat the sim card slot itself. It is made mostly of plastic and has a compressed spring in it which bursts through the plastic the moment it gets soft. I busted two slots due to this and had to start all over again 😦

PHAsE 6: Case Modding

Congratulations, you have done the hard parts 🙂 All that remains now is to complete the job by trimming the plastic back cover of the handset to make room for the new sim card slot.

Again, there aren’t really any explicit steps here, so instead here are some basic tips based on my own experience:

  • Use the cutting wheel on your Dremel – mangling and tearing out chunks with your pliers or snips is probably going to end in tears.
  • You will have to trim off more than you would think.
  • When test-fitting do not use excessive force – If it doesn’t fit, you haven’t trimmed enough in the right places. I busted all my good work by doing this as it crushed the sim slot. I had to start over and nearly destroyed my workbench in the ensuing rage.

When you’re done it should look something like this:

Followup – 4 months on:

Ok, so it has taken me 4 months to write up this guide due to work commitments and laziness. However the good news is that I can report on the longevity of this hack straight away.

I use this handset every day. It lives in my pocket and endures the usual level of use/abuse that a handset should. In truth I have found it to be occasionally flakey – it lost signal totally and required a reboot once or twice a month. Initially I thought this might be down to a dodgy solder joint, however I am now beginning to believe that it is a software issue. I updated my ROM recently and have seen much improved stability – although this is anecdotal at this stage.

On balance, I consider this hack a success and the result is exactly what I was after. Plus, when friends and colleagues wave their iPhone at you to try to tell you how much more they know about phones than you – photos like the ones above act as a total spice weasel to the face. Bam.

Using External SD Card with Google Play Music App

Update 5th Dec 2013: Today an update to the Google Play Music app has added a new feature in the app’s settings, allowing you to choose to store files on the external sd card instead which solves this problem.

Context:

I use Google Play Music as my main media player because I like having my music stored in the cloud and the Google Play Music App is pretty good.

The Problem:

On a device with both internal and external storage such as the Motorola Photon Q, the Google Play Music android app will only store files it saves for offline playback to the internal storage.

This is a real problem since most devices with this configuration have a relatively small amount of internal storage (8 gigs usually) which even a modest music collection will fill up quite easily. This is not only a pain since you can’t cache all your music, but also means that you have run out of space for anything else such as installing more apps.

The Solution:

Create a couple of sym-links from the internal storage to the external SD card.

Prerequisites:

  • Your phone must be rooted.
  • You must have a terminal emulator installed.
  • You must have a file explorer app installed.
  • You should know what a terminal is.
  • Read here to learn what a sym-link is.

Steps:

  1. Go to Settings > Applications > Google Play Music.
  2. ‘Force Stop’ the app and clear all app data.
  3. Open your file explorer of choice and create a directory (folder) on your external SD card called ‘GoogleMusic’.
  4. Inside this directory create two more: ‘files’ and ‘cache’.
  5. Open terminal emulator and enter the command: su –
    1. The superuser app will ask you to grant root privileges. Hit ‘Allow’.
  6. Enter the following commands in order:
    1. cd /data/data/com.google.android.music
    2. ln -s /mnt/external_sd/GoogleMusic/cache cache
    3. ln -s /mnt/external_sd/GoogleMusic/files files
  7. You’re done!

7400 Logic Combination Lock

Reading Hackaday the other day I came across this article about a combination lock built from logic gates only. This reminded me of a similar circuit I designed and built at school for my electronics AS-Level and spurred me enough to dig it out and share it here 🙂

The Circuit:

7400 Logic Combination Lock

Inputs:

  1. A bank of momentary switches represents a keypad with ten digits (0-9), a ‘Reset’ and an ‘Enter’. This is similar to many mechanical door locks available.
  2. A bank of simple SP-ST switches act as a memory block and are used to store the combination. For the combination ‘1234’ simply close switches 1, 2, 3 and 4.

Output:

Inputting the correct combination and hitting ‘Enter’ will result in the output going high for around 5 seconds. In the circuit above the output is represented by an LED although in a real application this would most likely go to a transistor or relay to drive a solenoid for the lock mechanism.

How it works:

  1. A latch comprising of an Or and an AND on each input digit which holds high once the digit is pushed until the reset is triggered.
  2. An XNOR for each digit compares the value of the latch with the value of the corresponding ‘memory’ switch.
  3. A tree of AND gates evaluates the outputs of all digit blocks (the output of each XNOR) and outputs high if the combination was correctly entered.
  4. When the ‘Enter’ button is pressed:
    1. If the combination was incorrect an XOR gate is used to trigger the reset.
    2. If the combination was correct the a 555 monostable is triggered which holds the output high long enough for the user to enter the door.
  5. The moment the output of the monostable goes high, the reset is triggered.

Limitations:

The only real flaw that I see with this design is that you can enter the code in any order. However since many commercial mechanical locks have the same limitation I think I can live with it.

Does it work in real life?

I did actually build this thing many years ago, but I cannot for the life of me find any photos of it. I can confirm however that it did work and have found the photo evidence!:

Circuit on three breadboards

Additionally for those interested, you can download the circuit simulation from here and run it yourself in the quite fantastic Yenka simulation suite. Yenka is a free download and is free for home use.

Google Music & Hype Machine keyboard controls on Mac OSX

Update 9th March 2016: Fixed the workflows to work with new changes to both Google Play Music and Hype Machine

Music, music everywhere…

For some time now I have been using Google Music and Hypem as my main source of music. These services are great – Hypem always has a great selection of fresh music and a great user experience. Google Music is useful because of it’s companion app on my Android phone.

The only problem with these great services? Having to switch back to my browser and to the correct tab when ever I want to play, pause or skip to next or previous tracks. Frankly it’s a pain in the arse – particularly when you consider the music controls staring back at me from the top of my Mac’s keyboard.

The solution

Naturally I did some poking around on Google and found an interesting solution – use applescripts, registered as global services, accessed by key combinations.

Installation

  1. Download the Zip archive containing the workflows and extract it.
    • The code is available on GitHub if you want to contribute 🙂
  2. Move all three extracted workflows to ~/Library/Services/ (/Users/{you}/Library/Services/)
  3. Open System Preferences and open the Keyboard section.
  4. On the left-hand side, select ‘Services’.
  5. On the right hand side, scroll down to the ‘General’ section and you will find the three new services. Here you can enable them and select an appropriate key combination for each as per the screenshot below:
    Screenshot
  6. Fire up Chrome, load up the Hype Machine or Google Music and give it a whirl.

Using Function Keys

The more hawk-eyed reader will notice that in the screenshot above I have mapped the three services to the playback control keys on a Mac keyboard. In fact, I haven’t – I have mapped them to the corresponding Fn keys.

OSX does not let you override actions assigned to the playback keys themselves. This means that if I wanted to use the Play/Pause service mapped to ⌘F8 I must press fn + F8.

Clearly reaching for the fn key is going to get tiresome very quickly. Luckily you can use a neat little tool called FunctionFlip to make the three playback keys default to their Fn value instead of their standard playback action so that you don’t have to press fn. Neat!

Update:

FunctionFlip stopped working on OSX Yosemite, but I got it working again. See here: FunctionFlip on OSX Yosemite

Update 26th July 2016: I can’t seem to get FunctionFlip to install on OSX El Capitan, but have found that Karabiner can do the same thing (and more). There are loads of intimidating settings – don’t panic though, you only need to enable the one shown in the image below:

karabiner-change-functional-key

Usage

  1. The scripts are written only to work with the Chrome browser. They could however be adapted to work with other browsers so by all means do so if you feel so inclined.
  2. If you have both Hypem and Google Music open in the same window, the one in the right-most tab will be controlled.
  3. Opening Hypem in one window and Google Music in another will not cause anything to explode, but you will have no way to predict which one will be controlled.

Troubleshooting

If you have any issues with these scripts please let me know in the comments below and I will try and help. If you would like to contribute any improvements, again leave a comment below and I will get back to you 🙂

References

This solution was originally implemented by nathanator11 over at Mac OSX Hints. I have simply picked up where he left off.

Also credit goes to k10g for his original work on this.

Thanks guys!

DD-WRT and PPPOA BT ADSL using a ST510 v6

This is something I did a while ago, but I thought I should write it up properly.

The problem:

DD-WRT does not support PPPoA ADSL.

For my old PPPOE ADSL internet connection I had a WRT610n v2 running DD-WRT and a separate simple ADSL2+ modem (ST510 v6) which I have running in bridged mode to avoid double NAT. This worked great as DD-WRT supports PPPOE, however I moved house and had to set up a new connection with British Telecom who use PPPOA.

Phoning BT tech support was as pointless as I thought it would be. DD-WRT does not appear on their scripted responses and they all think that the BT Home Hub is the best thing since boobs despite the fact that it is quite clearly crap – a single gigabit ethernet port! Really? WTF?

The solution:

Basically I had to set up the st510 v6 modem into half bridging mode. From what I understand of it, this involves getting the modem to handle the PPPoA connection, then enabling PPTP on it for the DD-WRT router to be able to connect to it and supply the credentials.

To configure the modem:

  1. Use the standard wizard in the web interface and choose any configuration you like (I picked a PPPoA template) but make sure that you choose a VPI/VCI that is NOT 0.38. Complete the wizard and let the thing settle.
  2. Use the web interface to configure the modem how you like. Things you probably want to do include:
    1. Disabling the firewall (the DD-WRT router has a better one)
    2. Setting the password to something decent
    3. Turning off DHCP (again we’ll let DD-WRT handle that)
    4. Simplifying the network interfaces. My modem defaults to have an IP of 10.0.0.138 which is fine, but it also creates a vlan in the 192.168.1.x range. I removed this. N.B this is why you have to assign your local IP statically for this part.
  3. Restart the modem just to help it settle.
  4. Telnet into the modem (Google it if you’re not sure what telnet is)
  5. Issue the following commands:
    (You can ignore any messages about things being in use and unable to be deleted)

    ppp relay flush
    eth flush
    atm flush
    ppp flush
    atm phonebook flush
    saveall
    atm phonebook add name=BrPPPoA_ph addr=0.38
    service system modify name=PPTP state=enabled
    saveall
    exit
  6. Use the modem’s web interface to restart the modem.
  7. Hook the modem up to the wan port of the DD-WRT modem and log into DD-WRT.
  8. In the wan settings of DD-WRT use settings like mine:DD-WRT PPTP Settings
    (Don’t worry about the subnet mask and gateway, they will set itself when your connection is established).

That’s it! Good luck 🙂

Originally posted on the BT forums here: http://community.bt.com/t5/BB-Speed-Connection-Issues/Alternative-Modem-Router-using-DD-WRT/td-p/295165