Monday, 7 December 2020

Dead Smartthings (Samjin) button

 As I'm in the process of switching from Samsung SmartThings to Home-Assistant for my home automation, I've been re-pairing various Zigbee and Zwave devices.

 One of those devices, a Samjin button, branded as SmartThings wouldn't come back to life after I removed the back cover (it was too tight against the wall to reach the reset switch).  I recall having two buttons in a pack of 5 that also did the same thing.  Those two seems to be dead-on-arrival, but I knew this button had been working fine.  After much fiddling, I managed to coax it back to life by holding the CR2450 battery in with one finger.  Whenever i put it back onto its battery cover however, dead.

No amount of bending the battery contacts made any difference.  So, I put a tiny square of folded tissue paper behind the battery (between it and the rear cover where the magnets are.  Hey presto - immediately works.  Slightly snug to twist the battery cover on, but I now think I know what was 'wrong' with those original  two buttons which went back to Amazon...

Tuesday, 1 May 2018

How do I follow a post on Facebook?

I have seen lots of posts on Facebook recently with comments along the lines of "Following this", or even just a stream of comments with just the letter "F".

The purpose of these comments seems to be so that the commenter can be alerted to any further comments and discussion on this post.

So, if you weren't already aware of the right way to do it, it's simple.  Click on the menu for the post.  This is usually displayed as 3 horizontal dots at the top right of the post.

Then it's as simple as clicking on "Turn on notifications for this post".  Same effect, much cleaner.

Thursday, 22 March 2018

Ford B-Max owner review - 2 years on

I bought my B-Max from a Ford dealer in Kent just over 2 years ago and I've now done 38000 miles in it.  I thought I'd share why I bought it, and hope my insights are useful to others.

Size:

The car had to be a certain length to fit with the other car on the driveway, so anything too long was immediately out of the question.  There's not a huge amount of cars in that bracket that can fit a family of 4, but the extra 6 inches of length and headroom over the fiesta makes a big difference in rear legroom.  It means there's enough room for my 18 year old daughter to sit comfortably.

The boot is just about big enough for two suitcases, as there is a board that comes out, to give a level loading surface, or a slightly deeper boot space.  It's packed full for a week-long family of 4 holiday but it's just about enough.  We wouldn't survive if my youngest still needed the baby paraphernalia.

Spec:  

I bought the Titanium edition, as a key requirement for me was that I wanted cruise control.  I commute for 2 hours every day, and you end up with a sore foot otherwise!  The Sony stereo is really good quality and I can plug a 128GB USB stick  and have all my MP3s in the car, with voice control to select the artist or album.  There's also a second cigarette lighter plug in the centre console which is ideal for powering chargers for the kids in the back seat.

Engine:

This was one of the most important decisions for me - I wanted an automatic transmission, but that was only offered on the much older 1.6L engine, and the EcoBoost 1.0L engine was more important too me, both for fuel economy and the fact it has start-stop engine technology.

I went for the 120bhp Ecoboost engine option to give the car a little bit more oomph (the standard engine is 100bhp), and I'm happy to say that unlike my old 1.2L Honda Jazz, I can keep it in 5th gear and still accelerate up hills!

I use the Android app Fuelio to track my fill-ups, and I'm getting an average of 44.3 mpg.

Servicing:

I bought a service plan from the dealer for £24 per month, but as I've done more mileage than the salesman put down for, I've exhausted it after 2 years (rather than 3).  It was nice to have while it lasted.  The only thing that's gone wrong with the car is a brake-light bulb which was spotted and replaced at service.  The garage also send you a YouTube video of your car being inspected, which is a nice touch.

What next?

I'm on a 36 month PCP, and ideally when I get my next car it will be electric or at least hybrid-electric, which sadly with the current range rules out a lot of Ford models.  There won't be a new B-Max and the closest two cars - the Fiesta Active and the Ecosport - are both SUV-style, which doesn't really float my boat.  I'm keeping a keen eye on the new Nissan Leaf.


Sunday, 11 March 2018

Top 3 things to do in Tromso, Norway

A few weeks ago I was lucky enough to visit Tromso in Norway to see the northern lights for my wedding anniversary with my wonderful wife.  Rather than sticking everything on TripAdvisor I've documented it here:

Flights

We flew to Tromso from London with Norwegian Airlines.  The outbound flight was via Oslo but the return was direct back to London Gatwick.  We went Friday morning to Monday evening. We were quite impressed by the transfer in Oslo - as you go through passport control a picture of your suitcase pops up and asks you if this is your luggage.  There was also facial recognition for passport control rather than a long queue for a border guard.

Hotel

The hotel we stayed at was Skansen hotel.  It was fairly basic but nice enough.  The staff were incredibly friendly and helpful.  It's only a minute's walk into town too.  There's a basic breakfast buffet included but no dinner restaurant.

Tromso

Tromso is quite a small city, the airport is a few miles outside, through a network of tunnels, the taxi cost around £15.  We went in February and the high street was covered in a couple of inches of ice, but the pavements either side were clear.  Where the pavements weren't clear there was a layer of gravel.  This is a different approach to the UK, rather than salt to melt the ice the gravel just makes the ice grippier.  There's a few shops, and a huge number of hair salons, the reasons for which we couldn't fathom.  There's only one shop in the city which has an off-licence, so once we'd found it we bought a bottle of wine for the hotel room.  The wine, along with everything else was quite pricey due to Norway's strong economy, and our rubbish one.

There's a really nice harbour, lots of restaurants and gift shops.


Restaurants

We ate out at two really nice restaurants, at different ends of the scale - a pizzeria called Peppe's and a restaurant called Kitchen and Table.

We ordered a large pizza between the 2 of us at Peppe's and we're glad we did as I've never felt full after a single slice before, there's no way we could have eaten one each as I was originally considering.  It was really nice with a draught beer.

Kitchen and Table was a different proposition - fine dining, and prices to match, but the food was delicious and strongly recommended.  Not a huge choice but everything we had was well presented and very tasty.



With that out the way, here's the top 3 things we did, and would recommend anyone do in Tromso, Norway:

3. Polaria

Polaria is an aquarium and education centre a few minutes walk from the centre of Tromso, there's a gift shop, cafe, cinema screen and various bits to see and do.

The cinema screen is a very wide wrap-around display which shows nature and conservation videos on a regular schedule.  The main attraction though is the aquarium - there's a walk through glass tunnel where you can observe the two species of seal they have, and a couple of times a day is a really good show with the seals, in which you genuinely believe the seals are enjoying themselves rather than just being about entertainment for the audience.  Allow around 3 hours. 

2. Husky sledding

We found this prior to the trip on TripAdvisor and booked through them for the Monday morning starting at 8:30am.  Everyone meets in the Clarion hotel near the harbour and a coach takes you to the huskies, which was about a 30 minute journey.  Each couple gets a sled and 6 dogs and you're taught everything you need to know to stop/start/control the sleds.  It was a great experience and the dogs are lovely.  I took a few short videos on my phone as you can only bear to have your hands out of the gloves for around 20 seconds at a time.




1. Aurora tour

Again we found the tour on TripAdvisor prior to arrival. A minibus picked us up at 7:30pm along with 5 others and we set of in search of the darkest place we could find.  Once away from the lights of the city, the sky was magnificent, and we didn't have to wait long.
We were very lucky to have two good 'shows' on the night, one about an hour into the trip and one just before midnight.  There had been a solar 'storm' about 5 days before and I think we caught the tail end of it.  Within 2 hours of getting out of the minibus we were all desperate for the provided snow-suits and warm snacks despite already wearing every item of clothing we had.  I alternated between marshmallows over the fire, and nipping to my camera to take more photos.

Photographing the lights

I took my Canon EOS 650D SLR with the Canon 17-85mm lens and a Manfrotto tripod.  I used a 20-30 second exposure with the lens wide open most of the time (lowest F-stop), focussed manually at infinity.  I set the ISO to 400-800 and recorded the images in JPG+RAW so I could post-process them afterwards.

An article I read warned about dew building up on the lens, but I didn't have any such problems, and the battery survived the cold temperatures fine.  Here's a couple of photos taken straight from the back of my SLR screen.  If you're interested in seeing the full-size processed images let me know!



A few people didn't have their own cameras, but the guide took many of his own pictures and shared them with us afterwards, including ones with us in them, by 'painting' us in with a torch flash to get the exposure correct.

We were really lucky to be able to see the aurora and we've just had it blown up on a large canvas to put in our hallway.

I would not hesitate to recommend Tromso, there's no guarantee you'll see the lights but it's a brilliant experience - just wrap up warm!

Saturday, 13 January 2018

Asus MB169B+ USB Monitor

Now I'm doing everything on my laptop (coding, reading, betting) in the evenings, I started to miss the screen real-estate I enjoy at work (4 monitors!), so I started looking into a laptop-friendly way of extending my desktop without peppering the lounge with extra monitors.  I came across this product, and I've been using it for a few weeks now. 



It's a standard Full HD 15.6" non-touchscreen display, but it's really thin, fairly light and best of all, it takes all it's power and display signal through a single USB port, so you don't need extra plugs or power bricks around.  The display is bright, clear and there's no real lag if you're just using it for 2D windows applications and web browsing.  I haven't tried it for 3D gaming but you're probably better off with a full-blown HDMI monitor if that's your use-case.

It comes with a faux-leather slip case, and you're supposed to be able to prop up the display in the stand, however I haven't found it to be the most stable solution (the monitor is prone to falling backwards).  This is the only downside and I've ordered a tablet stand to try to prop it up a bit better, but a plate holder/stand would probably do the same job.

You can Buy the MB169B+ here

"Invalid Username or password" when mapping a network drive for a Windows service

Another recent issue I've come across required such a bizarre fix I thought I'd document it here in case it helps anyone else.

We had a Windows service running as Local System account on Windows Server 2016, and a mapped drive using Azure File Service over SMB.  So our server was on a separate Active Directory domain to the storage (the Azure storage is effectively on a domain called AZURE).

When we tried to access files on this share using a named drive letter, we would always get an error back saying Invalid username or password.  So after reading StackOverflow and other sites, we tried several different tactics:

1) Try to map the drive using a Windows Scheduled Task running as SYSTEM user, to run a batch file with a net use command in.

2) Try to map the drive using an administrative command prompt and the SysInternals PsExec tool (psexec -s -i cmd.exe)

3) Try to save the credentials for the network location in Windows Credential Manager

But whatever we tried, either the logged in windows user could see it, but the system user couldn't, or vice versa, but nothing would allow the service to see the drive.  We couldn't use the UNC path without mapping it because you can't embed credentials (username and password) in a UNC path.

After much more reading, it turns out that:

a) Each user has it's own record of mapped drives and credentials (which we knew anyway).
b) In some cases, such as Windows Services, different logon sessions for the same user have different mapped drives.
c) All Windows services running as the same user share the same session.

It was (c) that allowed us to finally find a (slightly Frankenstein-esque) solution.

If you create a new windows service (using C# and TopShelf for example) which shells out (System.Diagnostics.Process.Start) to run the net use command, and install this service to run as the SYSTEM user (TopShelf defaults to this), then it magically works, now your existing service can see your mapped drive!

P.S. If you get into a situation where you can't un-map a drive, you need to log back in as the user who mapped it in order to delete it (net use * /d)

P.P.S. If you're in a situation where you're able to change the user a service runs as (we weren't), then this whole thing might be a lot easier.  I think it's the special SYSTEM login that complicates things.

Friday, 12 January 2018

IIS w3wp hangs indefinitely with low cpu

Recently I investigated an issue with an old application (think asp / unmanaged code / cgi) which had been working for years on IIS 7 but when it was migrated to IIS 8.5 on a newer Windows server we started to see a gradual decrease in stability. The website would just stop responding to new requests and the existing request would never time out. As it got worse over a couple of weeks it would not recover even when recycling the app pool or killing the w3wp.exe process. After trying several different things with no success we eventually found a huge number of .TMP temp files in c:\windows\temp had built up (hundreds of thousands). I believe these files were possible remnants of ODBC connections that were never cleared up properly by the runtime.

Clearing these files cleared the issue immediately and the application has been completely stable since. Hopefully this article will help you and you won't spend as long googling as I did!

Wednesday, 10 January 2018

Matched betting with OddsMonkey

Late last year I got introduced to a new concept, that of matched betting.  Initially I was disbelieving but after watching a friend make hundreds of pounds in quick succession, I had to give it a go myself.

How it works

Matched betting or bonus arbitrage is the process of taking advantage of a difference in odds between a bookmaker and a betting exchange, or where a bookmaker will offer risk free bets or bonus money for betting on an event or outcome.  There are actually dozens of these offers every single day across the 100+ UK bookmakers.

A basic example is the odds of tossing a coin, they should be 2/1, so you've got a 50% chance of winning if you choose (for example) heads.  Matched betting works because often a bookmaker (trying to get more business) will offer enhanced or boosted odds, so they might offer odds of 3/1 on heads.  The actual odds haven't changed however, so if you place a bet at 3/1, and place the opposite bet (a lay) against heads at 2/1, you can make make a profit no matter what the outcome is.


So what is a betting exchange?

A betting exchange is a special type of bookmaker which allows you to not only 'back' an outcome (e.g. Arsenal to win) but 'lay' or bet against an outcome (e.g. Arsenal not to win, which seems more likely these days).  Whereas a bookmaker makes money by offering odds on an event that add up to more than 100% (their 'overround'), a betting exchange makes money by charging a small commission on each winning bet (between 2-5%).

Expected value and casino offers

In addition to sports betting, a big part of matched betting is casino offers, e.g. "deposit £10 play with £20".  These offers often require you to wager your winnings a certain number of times, for example a £5 bonus might have 20x wagering requirements, so you'd have to spin/bet £100 to release the bonus.  Some offers are +EV, others are not.  EV or expected value is a measure of long term outcomes, i.e. if you did the same offer 100 or 1000 times, you would expect on average for this amount to be won.  If the wagering requirement is too high, the offer becomes -EV and you would expect on average to lose money completing the offer, so we ignore those.

What is Oddsmonkey?

To put it simply, OddsMonkey is a website that explains all of this better than I can, has a daily list of all the available offers, and exactly how best to complete them.  It has dozens of guides and calculators, and a rich and active community of helpful people all doing the same thing.  Their customer support is outstanding, even at 10pm at night.  It's only £15 per month, which you can make back in a single day without breaking a sweat.


Expected earnings

During the first month it's very easy to make money just by signing up to several of the bookmakers and taking advantage of their new customer offers, you should easily be able to make over £750 in the first month.  In subsequent months, you can make as much as you're willing to put into it, there's a great deal of offers and techniques available that can bring in anything from £500 to several thousand each month.

Downsides

The only downside is that the more bookmakers you sign up for, the more text messages, app notifications and emails you'll get every day.  However on the flip side, if you didn't get the notifications you can risk missing out on a decent offer.  In the long term, you are likely to get restricted by several of the bookmakers - matched betting isn't illegal, but bookmakers like making money, and if you consistently make money, then they don't.

If you're interested, you can sign up here.

Saturday, 6 January 2018

Starting small scale investing

Entering 2018 I'm looking to grow my income, after the obvious-but-shocking realisation that with UK inflation consistently above 2%, and my savings interest rate consistently below 0.5%, my savings are doing a great job of actually losing me money every month.   One way I'm trying to rectify this is to put some of my money into investments.  After searching around for a way to start small, and not have to put in thousands, or tens of thousands of pounds, I found a site called eToro.  Excitedly I signed up, only to be disappointed to find on first impression it's much like any other investment site or fund, in that there's (large) minimum amounts to invest in stocks or shares, etc.

However one interesting thing they allow you to do is piggyback on other people's trades.  In doing so you can get involved for only 100USD.  It's not pennies, but it's not thousands or pounds either.  Safe in the knowledge I've got an emergency fund in an instant-access savings account, I've decided to have a dabble.  Thanks to the ability to invest in crypto-currencies as well as stocks and currency pairs, investment returns seem to be well over the 0.5% I'm getting at the bank.  In copying other people you can spread your risk, and rely on the fact that the people you're copying almost certainly know more about it than you do.  This is not investment advise, your money is at risk, etc, etc.

If you're interested, you can sign up here, and maybe follow me.

Discovery Planet

I'm excited to have recently become involved in a local community project in Ramsgate called Discovery Planet.  It's a social enterprise focused on science education for kids (and adults), and it's something that my daughter has enjoyed attending for the past year or two.  After chatting with the founders at recent events I suggested I might be able to help by updating their website and managing their digital presence.  I'm currently working on the website and I hope to have it ready within the month (Jan 2018).

When I met with Nikki and Xanthe it became clear that the project is a labour of love, and is not run for profit - the grants that they are able to secure don't stretch far.  So as part of taking over the website I've set up a Patreon link. For anyone who can afford to do so, any financial support goes a long way towards making these events possible.


The next event is due to be announced shortly, and will revolve around DNA.  You can keep up to date on the Facebook page.  I hope to see you there!

Saturday, 31 October 2015

Milight Smart LED bulb review

I've just bought a Milight bridge, 9W RGBW bulb and 2.4Ghz remote.  All from Amazon Uk (from sellers Datawize, BatteryLogic).  From researching online it seems there's at least 5 different names for these bulbs (milight, easybulb, led logic, limitlessled, etc).  The seller of the bridge/hub/controller/box/thingy assures me it's version 4 (there have been 5 versions) but I can't see how to tell without taking it apart.  

I downloaded the android app 'Milight 2.0' by 'Sunny' which seems to be the official app. The instructions actually refer to 'Mi.light' app, which seems to look and work exactly the same (i.e. not very well).  I managed to use the app to find the bridge by connecting to it's own Wifi network.  You can then go into configuration and "AP configure" which allows you to join it to your own Wifi network.  The inbuilt wifi then seems to turn itself off.

Now at this point I repeated the above steps several times, because I couldn't (or rather the app couldn't) see it after it had been configured.  You can re-set the thing by holding in the hidden reset button with a pin until the lights flash rapidly.

I also at this point went into my router settings and made sure DHCP would always give it the same IP address (based on its MAC address).

After a few attempts I went back to the Play store and found the Wifi RGB Led controller app by Cold-Core which actually recognized the bridge and allowed me to pair it with the bulb (to do this, turn on the bulb at the switch and press "on" on one of the zones (1-4) within 3 seconds - the bulb will then flash 3 times for success.  The pairing process is identical for the plastic remote control.

Now that all worked I configured the openhab binding by following this page https://github.com/openhab/openhab/wiki/Milight-Binding - substituting my newly assigned static IP address and putting port 8899 and using channel number 6 rather than 1 to reflect how the new bulbs/bridges work.  I can now turn bulbs on/off and change colour both remotely and automatically (e.g. when home is unoccupied, or when i stumble downstairs in the middle of the night).

With that all working, overall I'm impressed - for a fraction of the price of Hue/Lifx they seem to do the job.  The only downside I can see is they don't report status, so sending messages is "fire-and-forget".  I haven't had any problems so far however.

There's some detail on development and versioning of the APIs, bridges etc on www.limitlessled.com/dev/

Sunday, 21 June 2015

Quainton Village Society

Just a quick one to say I'm now hosting another website for the folks in Quainton - check it out at Quainton Village Society

Wednesday, 10 December 2014

Getting the Dell Laser printer C1760nw working on 64 bit Debian

I've just taken delivery of a Dell C1760nw from Amazon for just over £100 to replace the knackered inkjet which went before it.  As expected, getting the drivers working wasn't plain sailing, so for everyone else's benefit, here's what worked for me:

1) Download the 32 bit deb from here: http://www.support.xerox.com/support/phaser-6000/downloads/engb.html?operatingSystem=linux&fileLanguage=en_GB
2) Open a terminal as root
3) dpkg --add-architecture i386
4) apt-get update
5) apt-get install libcupsimage2:i386
6) dpkg -i xerox-phaser-6000-6010_1.0-1_i386.deb
7) /etc/init.d/cups restart
8) Navigate to http://localhost:631
9) Add a printer (Xerox Phaser 6000B v1.0)
10) Print test page
11) Celebrate.

Thursday, 30 October 2014

My Z wave and Openhab configuration

Over the last few weeks I've dived into Z Wave home automation with both feet, and now have several things working well (after much fiddling).  For those of you thinking of doing the same, or having issues with anything, you might want to look over my github repository which contains my openhab configuration files.

I'm using OpenHAB and I've been nothing but impressed with it, fully open source, and the google group is insanely helpful (Thanks Chris!)

I'm currently using:
An ASUS eeePC 901 running Debian Jessie
An Aeon Labs Z-Stick S2 USB Zwave stick
2 x Aeon Labs 4 in 1 multisensors
2 x Vision Security door/window sensors
3 x TKB Home wall plugs
1 x Horstmann ASR-ZW + HRT4-ZW boiler control / thermostat combo

I'm currently implementing the "wasp in a box" presence detection to control heating temperatures to attempt to save money, and busy thinking of more use cases for it.

I'll commit to the repo whenever anything changes, and hopefully keep you updated here if I remember.

Friday, 27 June 2014

First Adventure with Z-Wave Home Automation

As we're (hoping to) soon be moving house, I wanted to look into home automation, starting with a set of Philips Hue lightbulbs on my wishlist, but reading led to yet more reading and I've ended up with the beginnings of a Z-Wave network.

I've purchased an Aeon Labs USB stick to stick in the side of my old unused netbook, and am dabbling with python-openzwave.  My first task was just to get the sensors (Aeon labs MultiSensor) recognised, and then start building some logic to monitor the temperature and turn on a fan if it rises above a threshold.
 
I've put some code up on github called flask-openzwave which I hope to grow as I learn more about Open ZWave.

Maybe foolishly, I decided this would be more fun than just buying a box (essentially another linux computer) pre-build with pre-made software.  The only thing I'll miss is a nice Android app, but this can be mitigated by some keyfobs and a REST-like web interface.  My wife will love it (maybe)...


Tuesday, 29 April 2014

Your machine slowly runs out of disk space after using Assembly Binding Log Viewer

I came into the office this morning to find my laptop complaining that disk space on drive C: was critically low - which was odd as my 240GB SSD should be less than half full.

After running SpaceSniffer it was taking ages in C:\Windows\system32, further digging through the graph pointed me to C:\windows\system32\config\systemprofile\appdata\local\content.ie5 which had around 300,000 files in it.  All of them were .htm files, so I (tentatively) opened a file up in Vim (so it wouldn't run any scripts, etc).  It was then I realised what they were - all of them - were "Assembly Binder Log Entry" files.

I then remembered several weeks ago trying to debug a .NET assembly binding issue, and I'd turned on "Log all binds to disk" in Fuslogvw.exe, fixed my problem but didn't really "click" that it needed turning off afterwards.  I naively assumed it would only be logging for the duration I had fuslogvw open.  Wrong!

Clearing out the Temp htm files from the above location (by running explorer.exe as an administrator and granting myself permissions) only freed up around 500MB however, I was still missing around 100GB(!).  

Running spacesniffer again gave me a new location to investigate: C:\windows\syswow64\config\systemprofile\appdata\local\content.ie5 - which makes sense as it's a 64 bit machine running mainly 32 bit binaries.  However, no matter how many times I tried, I couldn't grant myself access, there were simply too many files and it kept timing out.

In the end I followed the process listed here to use psexec to open a command prompt as the relevant user, and set off a del *.htm command which took a good 6 hours to complete, but at least I've got my disk space back, and I won't be making that mistake again in a hurry.




Sunday, 17 November 2013

Controlling lights from the web using Raspberry Pi and Arduino

I've just got back from a weekend with my parents, where I had lots of fun attempting to get an Arduino Uno to control a cheap set of remote control mains sockets.  My dad has a set of 3 of these (http://www.maplin.co.uk/remote-controlled-mains-socket-set-531547) and has them plugged into desk and pedestal lamps in the living room.  Since my last two christmas/birthday presents to him were a Raspberry Pi Model B, and a book about home automation using Arduino, he'd picked up an Arduino starter kit from Amazon, and had bought a second remote control and taken it to pieces, all we needed was some solder and some code.

First step, solder 3 wires onto the remote control extracted from the plastic housing, as per http://blog.sui.li/2011/04/12/163/, and connect it up to the Arduino's 5V, ground and digital out pins (I chose pin 11).

Next, import the library from https://code.google.com/p/rc-switch/, then write a quick app to set switch one on and off.  Once we'd proved this works, we worked through a quick example using a photodetector, then decided it'd be fun to get this working over the web.  Since we didn't have any network connectivity, we roped in the Raspberry Pi to serve a very basic website, and use the Pi's GPIO to signal to the Arduino to turn on the lights.  I hope you'll forgive the gross insecurity of the web server, but it's quick and does the job - here's the code:

Python Code: 

#! /usr/bin/python

import sys
import RPi.GPIO as GPIO
import BaseHTTPServer
from SimpleHTTPServer import SimpleHTTPRequestHandler

class LightsHandler(SimpleHTTPRequestHandler):
    def do_GET(self):
        print "handling " + self.path
        if ("lightson" in self.path):
            self.lights_on()
        elif ("lightsoff" in self.path):
            self.lights_off()
        self.send_response(200,'OK')

    def lights_on(self):
        print "on"
        GPIO.output(18, True)

    def lights_off(self):
        print "off"
        GPIO.output(18, False)


HandlerClass = LightsHandler
ServerClass=BaseHTTPServer.HTTPServer
Protocol="HTTP/1.0"

server_address= ("", 8080)

HandlerClass.protocol_version = Protocol
httpd = ServerClass(server_address, HandlerClass)

sa = httpd.socket.getsockname()
print "serving"

GPIO.setmode(GPIO.BOARD)

GPIO.setup(18, GPIO.OUT)


httpd.serve_forever()

Arduino Code:


#include

RCSwitch mySwitch = RCSwitch();
int d_raspPiInputPin = 10; 
int d_transmitterPin = 11;
int onboardLedPin = 13;
int lightsOn = 0;
int delayTimeout = 1000;
int delayCommand = 500;
int valueFromPi = 0;

void setup()
{
  mySwitch.enableTransmit(d_transmitterPin);
  pinMode(onboardLedPin, OUTPUT);
  pinMode(d_raspPiInputPin, INPUT);
  Serial.begin(9600); 
}

void loop()
{
  valueFromPi = digitalRead(d_raspPiInputPin);
  if(valueFromPi == HIGH){
    allLightsOn();
  }
  else {
    allLightsOff();
  }
  delay(delayTimeout);
}

void allLightsOn() 
{
  if (lightsOn == 0) {
  mySwitch.switchOn(1, 1);
  delay(delayCommand);
  mySwitch.switchOn(1, 2);
  delay(delayCommand);
  mySwitch.switchOn(1, 3);
  delay(delayCommand);
  mySwitch.switchOn(1, 4);
  delay(delayCommand);
  lightsOn = 1;
  }
  digitalWrite(onboardLedPin, HIGH);
}

void allLightsOff() 
{
  if (lightsOn == 1) {
  mySwitch.switchOff(1, 1);
  delay(delayCommand);
  mySwitch.switchOff(1, 2);
  delay(delayCommand);
  mySwitch.switchOff(1, 3);
  delay(delayCommand);
  mySwitch.switchOff(1, 4);
  delay(delayCommand);
  lightsOn = 0;
  }
  digitalWrite(onboardLedPin, LOW);
} 


And a photo of the Arduino all wired up:


Notes:

  1. Don't forget to connect the grounds of the Pi and the Uno together
  2. We used GPIO 18 on the Pi as a digital output connected to pin 10 on the Uno
  3. Be careful if you're using the Pi for digital input as it'll only take 3.3 Volts
  4. We used the onboard LED on the Uno to check that we were sending the right signals to the transmitter
  5. We needed a short delay between sending commands to the transmitter, otherwise we'd only get some rather than all the lights to respond.
  6. You'll need to run the python script under sudo to be able to write to the GPIO

Monday, 11 November 2013

BBC's websites killing Press and threatening local democracy, says Theresa May - Telegraph

I'm all for competition and freedom of expression, but on the other hand, I've already paid for the BBC (whether I like it or not - but on the whole I like it), so if I can get good content and news that I've already paid for, she's right I'm not going pay someone else for the same thing:

BBC's websites killing Press and threatening local democracy, says Theresa May - Telegraph:

'via Blog this'

Tetris & The Power Of CSS

I found this link today, it's an excellent read, and explains succinctly what I've been wanting to do with my photo library for ages.

Tetris & The Power Of CSS
'via Blog this'

Another good one, which I haven't got round to implementing yet is this:

The algorithm for a perfectly balanced photo gallery