Archive

Archive for October, 2009

How to tweet from your website with your own tinyurl URL shortening service

October 30th, 2009 Ed No comments

As this is my first post about Magic Hat, a little introduction. Magic Hat is a site for magicians to learn magic, with over 50 thousand users. I started it in 2004, and since then have gradually (or not so gradually) being changing it. We’re now at the 8th major redesign. It started as a good way to learn PHP/MySQL/HTML, so I didn’t touch any content management systems, and wrote the entire first 3 versions with linux’s best text editor, vim! I then treated myself to using Eclipse, which saves a lot of work – Ctrl + Space and your website’s done (I wish!). Then I chucked in a phpBB forum, modified it and my site so that they’re nicely integrated. Finally, I changed to using smarty templates, which has made changing the look of the site in the last few versions significantly easier – would highly recommend it.

So, you’ve probably gathered that I’ll happily reinvent the wheel many times over, but hopefully for a good result. Magic Hat is very dynamic and has lots of complicated features that I don’t think would have been feasible to get working in something like WordPress without having to learn and change most of WP.

I’ve setup the Magic Hat forums to tweet every time someone posts, but I didn’t really want to use tinyurl/bit.ly as I’d like to keep magichat.co.uk in the links.  So, here’s some code that creates the smallest possible hash.

Read more…

Categories: Web Tags: , ,

Two-way communication via Nuelectronics ethernet shield…

October 30th, 2009 Ed No comments

…is possible, and does work – but only sometimes.

I struggled last night for several hours trying to get reliable two way communications.  The idea is that every time the arduino receives a home easy command from a remote or motion detector, it sends a message to the MPC-L.  Then, with some funky programming, the server will decide what events to fire off.

Unfortunately while I can reliably receive messages, and reliably send messages, I can’t do both – it just hangs.  I’m thinking it’s the nuelectronics ethernet shield, the software certainly isn’t very nice, so as I’ve only been playing with this for a few days, I’m splashing out on an official shield.  As a by-product of this, it is supported by Nicholas O’Leary’s MQTT code.  So, moving away from last night’s PHP start, I’ll write a small java program to receive these, process them, and fire off any events if need be.

The logic for the event firing will end up being more complicated, but initially, I want a bunch of events/desired actions, and each event has a sequence of signals required, each of which have to happen within a changable amount of time.  Only if a path through the sequence is achieved in the right time will the action be fired.

For example, a motion detector in the hall, and a door open/shut detector on my front door.  An event (i.e. turn off all lights) with a sequence of 1. Motion detector fired, 2. Door opened will detect when someone has just left the house, but obviously you only want it to happen if the time between 1 and 2 isn’t too much, otherwise the person could have walked upstairs and someone else came in through the front door!

I got this working in PHP, so will Java-it-up tonight.  Then will code the more complicated (and more useful) central heating logic (i.e. I want the house at 18 degrees at 7PM, it’s now 16 degrees, and takes 45mins to warm up to 18degrees, so turn on centreal heating at 6.15PM).

Graphing Current Cost

October 29th, 2009 Ed No comments

I bought a current cost and Viglen MPC-L (15W low powered computer running Ubuntu) last year, and have since been recording power and temperature.

Power consumption

Temperatures

Adapted from Jibble, I have been recording data in “RRD”, a round-robin database in a single file.  Initially, I didn’t have a computer on 24×7, so added some cheap and tacky code to pull the historical data from the current cost meter and log that.  A couple of weeks after buying the current cost, I realised I couldn’t live without live readings, so bought the Viglen MPC-L.

View code.

Part of that code runs “colours.pl” with the current power consumption, which sends a message to the arduino telling it to change the ambient light’s colour to a colour that depends on how much power the house is eating up. More about that shortly.

AM Transmitters Arrived

October 28th, 2009 Ed 5 comments

Farnell delivered two packages, ordered at 4PM, the next day via UPS – very impressive, must have costed more than the £8 it cost me (free P&P).

So, with the help of the arduino playground and homeeasyhacking, my arduino could receive and transmit home easy messages.

Prototype

The photo shows my prototype of all parts of the project (ambient light – bit of paper coiled up, will be improved soon – and home easy controller).

Wire the data line of the receiver (any of the two work on my receiver) to pin 8, and the data line of the transmitter to pin 6, and connect power/ground/aerials accordingly (I haven’t used an aerial for the receiver yet). A 23cm piece of wire works well as an aerial. All my cables are strands from CAT5 – I’m a cheap-skate!

To use the following code, first download the HomeEasy package from homeeasyhacking, add the .h and .cpp file (Sketch > Add File), then copy and paste the following code. Upload it, then start the serial monitor.

Press a button on a home easy remote and you should see the sender code – copy this, and replace “2427994″ in the code below with yours. Then restart the program, and whatever you programmed the first button on the first slider of the remote should turn off and on. Make sure, unlike me, you haven’t plugged your computer into that device – I eventually got the code working only to kill my computer’s power, oops!

To control another device, change the setHEDevice(0) line.
Read more…

BlinkM Arrived

October 27th, 2009 Ed No comments

BlinkM, 6xAA power-pack container arrived from oomlout (arrived next day, despite being in the middle of postal strikes), along with a free RGB LED – seem like a good place to buy from.

Downloaded the examples and got it working within a few mins.  Slight gotcha was that after I told it to change colour, it changed, then did something else.  Turned out that  a sequence was still running, so I now stop the sequences in the setup() method with BlinkM_stopScript( blinkm_addr );

Categories: Arduino Tags: , ,

First bits arrived

October 26th, 2009 Ed No comments

Freeduino and nuelectronics ethernet shield arrived a couple of days ago, so spent the first evening setting up my machine with Ardiouno 0017 (the development environment/serial monitor) and then started playing with the examples.  Appears to be reasonably simple to do relatively cool things.   Got the LED blinking, a simple webpage being hosted, reflectivity sensor working and ran out of things to do – need more hardware!

Initial plan is to monitor gas usage as I’m currently using currentcost to monitor electricity, so would be nice to get the full picture.

Ordered a BlinkM to start work on an ambient light that will be used to show power consumption, number of emails, traffic, weather – anything really!

Categories: Arduino Tags: