Tuesday, 27 May 2014

DIY clamp-meter current flow indicator

 This is a brief one. After my clothes dryer arduino sensor, I quickly realised I wanted to determine when my dryer was powered on. I didn't want to modify the dryer itself, so started to look as passively sensing when the dryer was turned on. To do this I looked at the clamp-meter method of determining current flow. (I use this for my electricity consumption for the entire house, but using a commercial product).

Checking various websites I found that this was something that could be made with some success, so I started to look for the relevant parts. I had spare copper wire, a spare caribena and set about it. The result was this:

As you can see I had to use a couple of different wires that I joined. But the basic principle remains. I could hook this around one of the two feeds to the dryer (Only live or neutral, round both cause a cancellation effect) and then read the millivolts induced by the crude 'transformer' I have made.

However, no luck. I re-wrapped this several times, tried different methods and different ways of connecting it up and no matter what I tried I never got any output on my multi-meter.

So here it is. What have I done wrong, or how could I improve my design to make this work?

 

Clothes Dryer arduino moisture alert

 So, since moving house we've had to relocate our clothes dryer to the garage. This being slightly inconvenient I keep forgetting to check when it has finished drying clothes which ends up either leaving them ages and having to put the dryer back on to help get damp back out of the clothes, or having trips every 20 mins to the garage to check on it. Either way, I'm lazy and wanted technology to solve my problems.

Searching the web, I found a few people doing smart things with dryers, based around the premise that when clothes become dry, they stop emitting moisture (pretty obvious) and so if you can monitor the operation of the dryer and the moisture still present you can estimate when the clothes are dry and either shut off the machine or advise that it's time to take the clothes out. The general principle is to put a moisture sensor in the vent/output of the dryer to see how much moisture is being emitted. Less moisture, then clothes dryer. You can then build up a reasonable threshold for when the clothes are dry by observing the values and testing.

The plan is to use a spare Arduino Uno I have, plug its usb into the server already in the garage and take readings off this. When a pre-determined threshold is reached it can then alert me by some means (Not sure what yet, tweet, email, sms, bluetooth alert, whatever!). So onto the sensor. Checking around you can get moisture sensors pretty cheap, so I went for the DHT11 moisture/temperature 1-wire sensor (not the usual 1-wire protocol, but well documented and there is an Arduino library for it).

 The sensor itself is around 5-10cm in size, so easily hidden and has 4 terminals along the base. These are for +vcc data (unused) and -vcc

These can be bought on ebay from UK sellers for under £2 which is a bargain I'd say! So I got one ordered to play around and test. So next step, link it up to the arduino and load the library, see what happens. Here it is connected up to my Arduino Uno for testing.

So far so good, running a simple sketch I could retrieve the moisture value (in %) and temperature (in oC) so I was getting together something I could use.

By soldering a long cable onto the sensor and wrapping it a little in electricians tape I then needed to tackle the dryer itself and identify how to make this work. My dryer is a Hotpoint self-ventilating dryer (avoids the external hose requirement) as it uses a condensing technique to convert the moisture-rich hot-air back into water (which then collects in a tub to empty).

So, I didn't want to modify the dryer in any way (I'd get into trouble off the mrs!) so I then looked at how to sense whats in the drum. The following image shows the layout with the door open:

Here you can see the main filter which fits into the dryer drum in the middle. This is all snug-fitting plastic, so no option here really, plus the sensor would end up getting clogged with dryer lint. However, following the internal plastic duct it comes out at the bottom, if you look at the middle+bottom you can see the cut-out that then feeds into the condenser fittings and into the water collector. This seemed like a good place, it was relatively lint-free and would take the hot air coming out. This seemed like a good spot, and it fits when closed using rubber+felt fittings, so I could fit the cable in quite easily.

I therefore put together the sensor onto a long wire and duct-taped it inside the duct (Yep, duct-tape actually being used in a duct).

After the initial test, the humidity rose rapidly with a full load of wet clothes and as the dryer kicked in it heated up. Initially this looked good, temperature going up and then I found a rapid drop in humidity, checking this did indicate that the clothes were reaching the optimum dryness, so it looks like it works. I waited longer to let the temperature level off and then the moisture dropped rapidly showing completion of cycle.

(The dryer isn't smart, it doesn't have a moisture sensor and will continue to run on its timer, so I think this may also let me help save energy by shutting it off early, but that will be a future change)

Unfortunately, I didn't keep a graph of this test, so I cannot show the simple correlation I did. However, something odd I noticed. Afterwards the graphing continued (I use the excellent Munin for graphing as it is so easy to write plugins) and I saw the humidity jump up and then remain at around 95%. This seemed odd, and I did a few things to see if it was a fault, but now I suspect that when the dryer is idle, and not heated its at quite a low temperature, and residual water in the dryers mechanics must stay there and keep moisture high. This also makes me worry about the dryer itself, as it cannot be healthy for it idle at high moisture, but again that is something to worry about another time.

The final design seems to work, and I'm going to continue doing some more test runs before setting up a threshold monitor and alerting part of this. The graph below is from the days after the test and shows the very high humidity. If you can think of a better explanation than mine I gave above, please feel free to add to comments and put me right!

As you can see the temperature remains around the same, but humidity sits up at 95% almost constantly (I'm going to assume the drops in humidity are graphing/serial errors and can be ignored. I should really write that into my code!)

 

I'll try and get another capture of when the dryer is being used to illustrate the correct graphing values that I captured.

You'll also noticed I added an "On" to the graph. The idea is that this will indicate when the dryer power is applied. This is proving tricky. I looked at and made my own caribena induction power monitor to hook around the mains cable and measure when power was flowing (Poor mans clamp meter), as my thinking is that this beast takes around 1kW of power, so its significant and I should be able to see even a tiny voltage showing on my home-made pickup coil. But alas I've failed miserable and I'll address that in another article. So for the moment I'm still working out how to monitor when the dryer power is applied (I still want to avoid intrusively digging into the dryers control panel/inners, especially as it would also probably involve an opto-isolator or something else wired into the 220v mains on the dryer which I like to avoid where possible)

 Also, code for the arduino sketch is at github: github.com/andyb2000/dryer-humidity

 

-- Additional --

I've had a little longer now to look at the code/stats, and have determined that when the dryer isn't being used I should ignore any values, as the moisture values often sit at 95% which I assume is just from the dryer having residual moisture. I'm also building up a decent picture of when clothes are dry. Take a look at this graph from today when the dryer was used 3 times:

 

As you can see on the graph, when the dryer is on (the green ON isn't working correctly, so it's not showing all 3 switch on times) the moisture goes down as temperature goes up. And the final drying cycle you can see the moisture drops rapidly slowly followed by temperature going up. Therefore this looks like a good set of threshold values to monitor. I suspect having a condition such as:

if temperature > 45 && moisture < 50 then clothes are dry

 

-- Addendum--

Thanks to everyone visiting from hackaday.com !

 

Monday, 12 May 2014

Fetchmail IMAP multiple folders and IDLE

 This is more as a reminder for myself than anything the mass public may find useful, but here goes!

I use fetchmail to keep a remote server updated with email from the host system. So I use fetchmail for this, run it in daemon mode and have a config like this:

 

 set daemon 300 set syslog poll myserver.co.uk protocol IMAP username [email protected] password mypassword is me@localhost no rewrite keep smtphost localhost 

Pretty simple so far! So I then wanted to pull down the "Junk" folder from the remote server, as I realised mails were getting missed as they got stuck there and I never checked there wasn't something I wanted in there. So I checked and fetchmail has the option to provide multiple folders, in the man pages, web pages, etc, it specified you add 'folder' followed by a comma separated list of the folders you wish to poll. Great, so I tested it, added 'folder inbox' and it identified it was only fetching specific folder 'inbox' I then changed it to 'folder inbox, inbox.junk'

And it failed. It retrieved the first folder, and then stopped. Checking all over I couldn't work it out, man pages appeared correct, in the right section. I tried various different ways of represending it. With quotations, without, spaces, no spaces, multiple lines, etc. And none worked, it always stopped after the first one. I then found a very obsure statement in an online document:

"The ‘idle’ option is intended to be used with IMAP servers..... It also doesn’t work with multiple folders; only the first folder will ever be polled."

Ah, and as I use IDLE the code is obviously just hitting the first folder and stopping (Probably because the code for fetchmail isn't multi-threaded or very smart, it just hits the first thing it finds and sits waiting there on IDLE). So to fix it I set "no idle" in my config, and it works now! (OK, It's a trade-off/performance hit, but I'll have to live with that I guess)

 

Monday, 7 April 2014

Powerline Ethernet

 Hello once again, sorry for not posting more regularly, as usual I have quite a few projects I should/could post, so will start with this one.

After moving house recently the new battle to 'tech-up' the house took place. I had various goals and needs to fulfil fairly quickly after moving. The first and primary being, how to get the TV systems working again. As many of you will know I use XBMC and TVHeadend on all TV sets, so each TV needs network access to be able to access the TV systems we use (DVB-T and DVB-S over ethernet). In the old house, I had managed to pipe network cables around from the garage pretty well, as I had a duct up into the loft-space from the garage and could then reach all of the rooms I needed.

However, our new house having a 3rd floor stopped all of this, no loft space that could access each bedroom, no easy link between garage and the rest of the house (The garage was not separate from the house, but there were no obvious ducts/cable runs, etc, between the two, only a power socket). My first thought was WIFI (I've not had much luck with HD over WIFI, but it might work!), so setup my wifi router in the garage (where the servers, TVHeadend live, etc) and started to see what the signal was like. Bad news, the house was built with good thermal insulation (read - tin foil) and so signal was next to non-existant even beside the wall where the WIFI router was setup, so looks like that was out. I then started to think how to cable at least one location and run everything from there, naturally I didn't really want this as did not want to start modifying a brand new house! So I turned to powerline ethernet. Not something I'd used before, but had played about with it at work as a trial, and it seemed pretty good.

I did some reasearch on Powerline Ethernet (Or Homeplug as its sometimes called) and found there are lots of different manufacturers licensed to it, but they all use the same standards pretty much so seem compatible with one another. I looked up the different speeds, and types. My theory being, the higher the stated throughput of the units, the higher chance of it working at HD video that I needed (I'd guestimated up to 30Mb). I found the TP-Link products and that they were on various deals at the moment.

I settled on the TP-Link PA411KIT AV500 which are the 500Mbps twin pack, for around £35 from argos, which is a bargain really for the potential these things had. A few initial observations though, just to be wary before you rush out to buy them!

They are quite stylish, in a white/grey casing and pretty small too (around the size of a regular wall-wart). They have one button on them for security/pairing, 3 LED's (power, powerlinethernet, ethernet) and an RJ45. Here was the first odd thing, its was a 10/100 network port. But the adapters are supposed to do 500Mbps, so why only a 10/100 not giga? After reading, the 500Mbps is as usual a bit misleading, they mean total, so 250Mbps is actual throughput (when in full duplex), but even so, we're still not at 10/100. But then there is the loss of the whole system, generally this can drop you down quite a bit.

My initial testing was very good. One in the garage plugged into my server/switch. One in the living room (Do not plug them into multi-ways, or adapters as it does affect them. I managed with a 2/3-way direct wall plugged splitter for power. If you have to, just make sure it doesn't have surge filters, etc, as those degrade the signal terribly). Doing that I was getting great results, TV streamed fine, as did HD content and all as fast as I needed. So I went out and bought another pair, plugged these into the TV's upstairs in two bedrooms. Again, these worked great, streaming TV was no issue, internet was fine, etc. So I went out again and bought another 2! (These things act almost like a small switched network, very neat). Now depending on what you read maximum is either 6 or 8, so I should be fine. Plugged them in and all did appear fine.

For a few days....

Then it started slowing down, I was having problems with HD content, it just stuttered after a few seconds (basically filling the xbmc buffer and emptying it again). I was also starting to get occasional stutters from SD content, network traffic was slow, etc. So really not good news. I was worried. Was the technology just not that good?

Troubleshooting involved unplugging all the homeplug adapters, so I just had one in the garage and one in the living room. No difference. I updated their firmware, and setup the network to be on my own named instance (By default you pair them and they use their own 'network name' and security), and ensured they were all set the same. Using the TP-Link windows utility it also showed the throughput available to each device, which worried me. They started to show 11Mbps to a few adapters. Depending on which one I plugged into it showed different ones with 11Mbps. So that made me think, what has changed, something has degraded the powerlines and caused this to happen.

I started to read up on the technology, to see what affects it. Seemingly everything! Just going between different phases or breakers in the fuse box can degrade it (Yep, mine was on different breakers). Different floors of the house as they tend to each have their own ring-main (Yep, mine on different floors). Long distances (Possible, I'm not sure what the length of cables, etc, around the house were, so unsure if sockets were say at the start of the ring or the end). Other interference (Yep, I use X10 and setup an X10 house alarm system, which I know uses powerline technology for their control signals).

So I was starting to worry, had these only worked when we moved in, since nothing else in the house was connected at that time. Next stop, I read that many devices cause interference. Biggest culprit, those cheap mobile phone chargers, computer PSUs, Laptop PSUs, basically anything that was a switch-mode power supply.

My next step of testing was to start switching things off and testing. So I began again with just the two TP-Link adapters plugged in, living room and garage. Loaded up an HD video and sat watching it jump and stutter. I then went round and unplugged all of the mobile phone chargers (wow, we have loads of them, at least 2-3 per person in our house!). Still no different, video stuttering. I then unplugged one laptop, no difference. Then my laptop, and it stopped. The HD video suddenly jumped back to life and ran. I let it run for a good 10 minutes and without stutter. Switched my laptop charger back on, almost the second I did, stutters came back. Aha! This was it. Plugged all the other stuff back in (except my laptop) and it was fine. So looks like that was the problem. Thinking back, this was a replacement PSU for my laptop, and was a cheapo copy, not manufacturer, so that would explain it! Cheap and nasty electronics in there caused it. So now I wanted to fix it, so I could use my laptop. I grabbed a surge protected multiway, and tried with that on a different wall socket, and hey presto that worked! So I still have my laptop, and my powerline ethernet works great!

I hope this maybe helps another individual who wants to use this and has interference problems, etc.

I have to say, I'm a big fan of these units, they are impressive units and do a very good job. At some point I'll run some speed tests and see what I can actually get out of them now, but for now they're streaming my HD tv great.

 

Thursday, 12 December 2013

Arduino controlled outdoor motion sensing xmas lights

*Edited 20-12-2013 to update Arduino code and de
 I finally managed to get on with my next Arduino project, and as its Christmas, why not do something with Christmas lights, an arduino, some PIR sensors and relay board. My idea was to use some little xmas trees I bought a few years earlier and do something a little smarter with them. Out of the box they are a chain of 7 1-foot high trees with various lightbulbs on them all powered from an AC power supply (low voltage). Nothing amazing, they didn't even flash originally, so the plan was to do this:
* Disconnect each tree, so that they could be controlled independantly
* Attach a PIR (Passive Infra-Red [motion sensor]) to each tree
* When the tree senses movement, light it up
* Run in a sequence to flash all the trees

So, first job, was to cut the tree cables down so that I had a single common wire running to each, I could then wire a cable to each one to run as the 'trigger' cable. The small trees look like this:

So I cut each of the cables and remade them with new cable runs, tested them and I could light up each tree individually.
Next job was to start with the PIR sensors. These are ones I picked up from eBay and were only around 1-2 uk pounds each, so pretty cheap really.

As you can see there are 3 pins for connection, +ve (5 volts), ground and trigger. When powered and operating they will send high the trigger to +ve to indicate the unit has sensed motion. The sensors also had two pot's on them to control the TX time and the distance control. I didn't get a lot of difference playing with either to be honest but that didn't matter, the defaults seemed to do the trick. I powered them up as a test and found that movement in front of them triggered the output for around a second then when motion stopped it removed the trigger. All looked good, but I had to waterproof them. First attempt and the cheap solution was to wrap them in freezer bags, not sure what this did to the PIR sensitivity I covered on and re-tested, no real difference to the triggering so this was ideal. I wrapped each one in the bags and tied them shut with freezer ties and wound the bag around so they were pretty snug in there.

There you can see the bagged up PIR, and also it nestling inside the tree, I opted to put them low down and try to bury them inside the tree a little, this hid them as much as I could from view and let me put the other tree branches up over them so the general view wasn't the rather unsightly bag and PIR sensor itself.
Next up, to control them I needed a relay board. This is because I was going to be controlling AC and an unknown current (Yes, I could have tested, but to be honest I knew it would be within the ratings of the relays, but way too high for an Arduino output, and I wanted isolation). So again I turned to eBay and found relay boards that you could get for around 5 ukp, and these were optically isolated too, so even better keeping the Arduino isolated and safe so it wasn't going to stress the outputs. Below is an image of the relay board as I was starting to wire it up.

The pins along the left of the board were labelled as ground, 1-8 and +ve. The relays are triggered by 0/LOW from the Arduino, initially I wired the relays up to be powered by the Arduino +5v rails and used the digital outputs as a test. This all appeared to work correctly, setting the digital pins to OUTPUT and when driven LOW the relay clicked and engaged. The relays are single-pole changeover so the outputs can be triggered on either throw of the relay. I wanted to use mine when the relay was engaged/energised the output to the tree would be on. The only thing that started to appear was as I did some test Arduino sketches that sometimes everything would hang and just stop dead, the arduino wouldn't continue its loop and the relays would be left on whatever sequence they were in. After some playing around I made an assumption. The 5v draw from the relays was proving too much, or too electrically noisy to be driven from the Arduino itself, so I separated it. I got another 5v supply, connected its ground to the GROUND on the relay board, and the +5v to the +ve on the relay board. I had to also tie the +ve to the Arduino 5v pin to keep it common but that worked great, the Arduino now only gave signals to the relay board and the other 5v supply powered the relay board itself.

Next was to start wiring the Arduino Uno up. I have the digital pins 0-13 available, so since I need 7 outputs I chose pins 6-12. Setting them in the code to OUTPUT pins and setting them to HIGH initally (Remember the relay board uses LOW to trigger!)
As you can see, I used a small breadboard to use as breakouts for a few of the connections, this was just to make the links to the tree lights themselves and common 5v rails easier to wire up.
For input I used the 5 analogue input ports but used them in a digital way, as all I was detecting was +ve or not that was simple. Referring to them in the code as pins 14-18 as they were being used as digital input pins.
Also you'll probably notice a tri-colour LED on the breadboard, another initial idea (since I already had 5 of them) was to put these on top of each tree and let it cycle through colours, in the end I gave up on that idea as I needed more output pins, and more importantly a lot more wires and the wire I was using already looked a little untidy/unsightly, so I gave up on that idea.
The code for the Arduino too quite a few attempts to get it right, mainly because I needed a few different sequences and logic to make it work right. The completed code is shown below, but it's not very neat, any modifications to it would be welcome! But the general program works as expected, so it will sit in a sequence flashing each tree lights in a sequence until one of the PIRs sense movement. When they do, they will turn off all trees except the ones sensing movement, so you can 'walk' up past the trees and they will light sequencially, you can also jump to particular trees and they will light in any order too!
The biggest bug/drawback that I've found is the PIR sensing component. since the PIRs aren't very precise sometimes they detect movement when none happens (I'm guessing this is because they're outside and picking up all sorts of stray IR activity or heat signatures), but also their field of vision is difficult to control, so knowing where they will detect movement is a bit of trial and error. But they generally work!

   

Merry Christmas everyone!
Arduino code below:
 (Moved code to pastebin) : pastebin.com/FJ2qP74m

Problems: 20-12-2013
I hit a few problems after setting it all up and letting it run a while. The biggest problem I'm having is the Arduino locking up and just stopping where it is in the code. The result are the lights getting stuck at whatever point they were at. I've tried to work around this in various ways. Firstly I thought it was the PSU I was using for the Arduino as it was a USB phone charger and I was feeding the Arduino over the USB port. I've swapped this to use a 9v PSU into the barrel jack so its got a 'proper' power supply and this made no immediate difference. I suspect this is due to EMI (Electro-magnetic-interference) from the relays and switching the low-voltage AC for the lights, so trying to re-route cables and move the relays away from the Arduino has helped but not enough. Finally I've put in a watchdog timer/code into my software so that at least if the Arduino locks up, it'll reboot itself and reset the sequence. I've not managed to figure this out much further other than it being an utter annoyance as its when I want to show the system off to somebody! I still suspect its due to EMI and need to try and protect things a little better, perhaps I've not isolated enough of the relay board from the Arduino output pins, but open to suggestions please folks!

Tuesday, 27 August 2013

Regional DAB switch-off and digital radio in the UK

"@RadioToday Digital Radio News: Regional DAB turned off in West Midlands"

Well, is this a good thing or a bad thing? I was puzzling over this whole setup for quite a while, as I'm very disillusioned already over the state of DAB and digital radio in the UK. Firstly I suppose a little bit of background to it. We all know that in certain areas the use of FM frequencies is tight, there are far too many for the old analogue spectrum to handle and since each station has to keep a 'gap' between the other (to avoid interference overlap, etc) then you start to run out of frequencies available for everyone to use. As an example, take a drive around London, and just seek through the radio frequencies, you'll find the radio stops every .3 or .4 steps and finds a new station. That's the problem. So in very lucrative areas there are no further frequencies available. The big radio firms in the UK are also wanting to expand their empire and go national, as the BBC has been able to do easily for many years, and so the advent of DAB/digital radio offered such an option.

Regional multiplexes of DAB transmitters could be linked and provide the option for a radio station to exist nationally quite easily, and with the ability to fit many stations within a single mux it also allowed a much larger number of channels to become available.

It sounded like the perfect answer to the UK radio industry. Except that the operation of those DAB transmitters/mux's would be auctioned off to the highest bidder, which therefore meant that only the biggest of big boys in the radio industry could get to operate the MUX's. So that did happen, and the big groups such as MXR (A combination of Chrysalis, GMG, Capital and Choice. There were a large number of commercial big boys all going for DAB and getting the infrastructure in and operational.

A good explanation of DAB and what the regional turn-off of DAB means is written here " @RadioToday: Digital Radio News: Regional DAB turned off in West Midlands radiotoday.co/14X9Lz5 "

However I'm still not convinced the current model of DAB and digital radio in the UK is a good thing.

I have to say, I have a vested interest, I'm with the 'little guys'. The smaller independant radio companies (Very very few) and the even more minority group, community radio. To be honest, my vested interest is with the community stations I work with, and on many occasions I'm asked "When can we go to digital/DAB". And unfortunately my answer is always the same. Only when we can make a huge profit and do some serious cap-ex.

I have questioned this time and time again, and the answer is always the same. You speak to the regulator (Ofcom) and advise on the DAB/Digital licensing, which in itself isn't a huge expense (And isn't huge for Community stations on FM/AM either). However you then have to arrange to actually transmit on a digital MUX (Multiplex). And that you do by contacting the local regional mux operator (Generally Arquiva, Capital, Chrysalis, etc), and that is where the problem comes in. They're a commercial company, working to a profit and making profit. So you get quoted between 4 and 5 figure sums and then you have to go into rental charges and more. Terrible when its for a community station that barely can pay for the building it runs from, never mind paying staff, expenses, kit, etc. To give it contrast, if you setup a community station to broadcast on FM you can use your own transmitter, your own transmitter site and equipment, making yourself totally self-contained and purchasing the transmission kit yourself. It could be as low as a 3 figure sum if you use the basic kit to get up and running. That plus the relevant fees to regulatory bodies, etc, and you're running in a few 1,000's which is generally within reach.

So my view on DAB and digital radio in the UK is still a very pessimistic one. To get full scale take-up of it by the public, it will need you to be able to get EVERYTHING you do now on analogue radio. At the moment this just isn't possible, and doesn't even look remotely feasible in the medium term. So something has to happen.

I'd love to hear what you think about this, whether you're in the radio industry, part of the licensing or just generally a radio listener, please leave comments and thoughts!

 

Sunday, 7 July 2013

Community Radio

 Well,

It's about time I wrote this one up as it's been in use for a good few months now and I've not mentioned it. As some of you may be aware I like to get involved with Community Radio Stations in the UK. These not-for-profit stations are run purely by volunteers who have a passion in radio, broadcasting or just want to be involved in something a little different. I've been interested in radio since I was very young and always wanted to be involved somehow, so around 6 years ago I started to get involved with local community radio in the area. I've never looked back, helping a few more and more community stations get up and running, or just offering a bit of assistance now and again. My proudest achievement was being a part of setting up and starting a community station in Hartlepool, the station is still running, going strong and have had their license extended beyond the initial 5-year period so I'm thrilled I've been part of something as exciting as that.

So onto another challenge, I was approached to help with a Community station in Redcar, and as usual I couldn't refuse, so started to help with the planning, FM application, documentation and everything that goes with it. Needless to say I get into a lot of trouble for using up so much of my free time on projects like this but I absolutely love doing it! And so, we're now up and running online and just hoping and waiting to hear if Ofcom will grant us an FM license. This would be really exciting if it is granted as its then a mad rush to get a studio fitted out, FM transmitter, audio processing, etc, all in place. It feels like its taken forever to get to this stage, but in reality the station at Redcar has come together in a very short time period. Just around about a year from the original planning and ideas to having the station running 24x7 online streaming and having presenters on-air live from 10am to around 6pm each weekday is so rewarding. Fingers crossed the FM license comes through soon and it can go full-time on FM!

 

I should also talk a little about what I'm interested in with radio. It's not primarily as a presenter, as unfortunately I'm not the worlds best radio presenter, I mean, don't get my wrong I believe I can do a reasonably job of it, done quite a few interviews over the years and played music, chatted a bit and quite happy in front of the microphone, but alas, I'm not the most thrilling in the world and have the voice to match so this will never be my strong point! So where I aim for is the technical side of radio. The playout systems, broadcast chain (thats the audio processing, FM transmitter, RDS encoder, etc) is where my interest lies firmly. I've been lucky enough to be a part of two start-up stations now, both with their own slightly different needs and so the playout system and equipment behind the scenes needs to be a little different too. At the first station I'm pleased to say we could do things in quite a structured manner. There are two studios, one main playout and a second for pre-recording and voice work. Both use the central database of the playout machine in the primary studio. Audio output from the broadcast desk is then fed over low-oxygen high-grade audio cables up to the 'rack room' where it goes through two levels of audio processing before it hits the FM transmitter, via the RDS encoder and out at 25watts to the end-fed dipole antenna. The coverage is pretty good, even from a congested central town location with lots of noise polluters nearby (noise in terms of r/f interference such as mobile phone transmitters, taxi radios, etc).

This is such a brief insight into what I've put in and done so far, but hopefully I'll get more time in the coming weeks to talk a bit more in depth about each of the elements of broadcast chain and producing a 'decent' output for listeners. If you're interested in community radio too, I'd love to hear from you so please get in touch or pop by on twitter: twitter.com/andyb2000/

 

Friday, 21 June 2013

Power ON PC from usb/remotely using Arduino

 Right folks, It's been a while so thought I should start to write up a few things I've been working on. Unfortunately I don't get the free time I used to because of other projects now (See another post shortly, hopefully!) but this one has been a constant pain since I moved the household TV over to XBMC+TVHEADEND.

Turning the home TV system on is done from an all-in-one remote, the Harmony from Logitech. It has a smart switch-on function that sends the various power and channel change events to the devices (TV, Sound System, channel switcher) but one thing it can't do is power the XBMC PC on. This is a Dell PC with a usb-ir receiver that is powered off most of the time unless tv watching is going on. It cannot go into standby as standby and USB infra-red devices are still problematic under linux and results in no remote control ability after wake-up.

So how to turn it on using the IR remote then? The USB ports are powered off when the system is off (All it leaves powered on is the ethernet adapter for wake-on-lan functionality). So I'm thinking that to power the system on I need to use an external device and 'press' the power button/trigger the ATX power supply to wake up. An Arduino seems the obvious choice for this, mainly because they are good little boards, low powered and can do simple tasks with input+output pins and also because I have a couple of them lying around at the moment as I've not done any projects with them for a while.

So to get the arduino to turn the PC on, I need to trace the power switch inside the PC and the control lines it uses on the ATX power supply connector. So as some of you may know, ATX is a standard an so colours and pin numbers are standard. Pick out the right ones, pull it to ground and it should power the ATX supply on. WRONG when it comes to DELL machines. They decided a while back that using a standard like ATX was silly and so invented their own ATX standard.... Hmm, so this meant the pins and wires didn't translate, and so trying to probe them or work them out might cause a blown PSU. Looking at this particular PSU it is one of Dell's finest custom units and I didn't want to replace it in a hurry so decided this option was out. Next option was to trigger the power button that we press on the front. Again in theory this is just closing a contact so should be straight forward. Well it would be if you could get to it! The power button is sat on a PCB installed at the front of the chassis. From this PCB there is a ribbon cable with around 20 connections on it! This handles the Dell diagnostic LEDs on the front of the machine also, along with some USB, firewire and other functions. So if I removed the board could probably trace them and figure it but this seemed a lot of hassle too, and again if I broke it, it was game over.

I needed a solution that wasn't doing ANYTHING custom to the Dell PC. So my only option really was to look at the Wake On Lan option. This could power the machine up 'remotely' and without modifying it.

To actually trigger the Wake On LAN, I needed to receive IR remote presses. Since the all-in-one remote handles power on for various devices I could just sniff for any of these power on signals and use them to trigger my power on function. Hooking the Arduino up to the IR module and then sniffing codes was straight forward, there are various nice IR libraries to do this. I have the 'Keyes IR Receiver module' which is the one on a small PCB with a metal can-like surrounding. Hook up the pins to the arduino (central pin is + , S is marked and the remainder is -) to one of the digital PWM pins and with the library you can start to decode IR.

Now IR itself is a bit complicated. Because you have lots of different 'standards' and methods of doing things. I finally settled on a very simple bit of code that included the IR library, and then sent the HEX code to the serial port. This worked fine and I found a unique-enough code used when power-on was sent from the IR remote. This let the Arduino do its job. How the hard part, how to get this into a Wake On LAN signal. Unfortunately I don't have an ethernet shield otherwise this would have been simple! So my next option was to use the serial/usb cable to send this HEX code to another device that could send the WOL signal. My trusty FTTC router looked ideal, its a Vigor that has an entire busybox system on it, so ssh, telnet, and most of the normal shell commands there ready, plus two USB ports. Plugging the arduino in, I happily could see the /dev/ttyACM0 appear and dmesg confirmed that it recognised the ftdi interface.

So I could now communicate with the arduino, if I cat /dev/ttyACM0 I could see codes working, so all looked good. I then got back to my dreaded problem from some time ago with the outside temperature sensors. The biggest issue with the setup, everytime you opened the serial port, the Arduino rebooted (for its code upload routine), and also it generally didn't hold the serial port open well enough to actually receive data consistently. This was and still is my biggest hurdle that I've not overcome yet. At the moment I'm trying with a bash script like this:

#!/bin/sh

while [ /bin/true ]; do
        grab=$(grep -m 1 valid /dev/ttyACM0)
        
        wget -O - http://192.168.1.1/wake_xbmc2.php >/dev/null 2>&1
        sleep 5 

done

However, this suffers from several problems. (You'll also note, I'm watching for the word valid to appear, I amended my Arduino code to only put out valid when the relevant IR code was received, this cut down noise on the serial port to try and help things along. Firstly the serial port doesn't always seem to want to send data. So sometimes this will just sit there ignoring any IR input. I'm guessing the Arduino is seeing the IR (The LEDs on the arduino show this) but the serial port just isn't seeing the reply.

Secondly if the serial port is disrupted, the wake on lan gets triggered regardless. This is just a bash scripting tweak but I've not got round to fixing this yet.

So I'm still stuck with reading from the Arduino serial port reliably in this manner, and so I'm hoping for inspiration! Arduino people, feel free to comment and assist!

 

Sunday, 20 January 2013

Linksys WRT54GL bricked

For years I've used the Linksys WRT54 range of wifi routers, I like these units as they have a decent form-factor, generally just keep on running for years without any attention and two wifi antennas that have screw-terminals on them so can easily add or change the aerial. I've always flashed these routers with different firmware, generally I use DDWRT as this has a new GUI, easy setup and quite a few advanced functions to switch WIFI on and off at certain times, captive portals, firewall rules, etc.

Recently I was going to upgrade my firmware, so did the usual, downloaded from DDWRT and uploaded it, then waited for the reboot, wifi didn't come back. Let it do its longer reboot, still nothing and it just wouldn't come back. I checked on the unit and the power light was constantly flashing, this is a bad sign, this generally means the FLASH/firmware isn't working correctly and its stuck in a boot loop. The recovery options on the Linksys/Broadcom hardware are to try their failsafe IP, this is 192.168.1.1 and initialise during their CFE bootloader. The trick here is to see if you can get a ping from 192.168.1.1 during power on. Unfortunately, this also didn't work for me, so it looked increasingly likely that I'd lost the unit completely, so it would be down to using a JTAG re-flash of the system to recover. This isn't easy! So popped the cover off and located the JTAG port. JTAG is a 12-pin (6x6 pins) port that you can access the Broadcom chipset directly to re-flash and debug it. In my case I was trying to use my FTDI cable FT232RL. I now realise this was STUPID of me! This is simply a low-voltage (3v) TTL to serial/usb converter cable, not a JTAG. So I started to give up hope. Until I realised, on the Linksys board was a SERIAL pin header. I soldered up some pins and connected up at 115200-8-N-1 and powered on. Sure enough I saw the bootloader!

This was a relief, it showed me that the bootloader wasn't damaged, but it just hun as it tried to load the O/S (As expected). It also confirmed that it should have been listening on 192.168.1.1 but the time it waited was tiny, almost 1-2 seconds! But it gave me hope as I reckon I could try to recover it from this point. Here is the screen output I had:

 

CFE version 1.0.37 for BCM947XX (32bit,SP,LE)
Build Date: Tue Jun 20 16:22:41 CST 2006 ([email protected])
Copyright (C) 2000,2001,2002,2003 Broadcom Corporation.
 
Initializing Arena
Initializing Devices.
 
No DPN
et0: Broadcom BCM47xx 10/100 Mbps Ethernet Controller 3.90.37.0
CPU type 0x29008: 200MHz
Total memory: 16384 KBytes
 
Total memory used by CFE:  0x80300000 - 0x803A39C0 (670144)
Initialized Data:          0x803398D0 - 0x8033BFE0 (10000)
BSS Area:                  0x8033BFE0 - 0x8033D9C0 (6624)
Local Heap:                0x8033D9C0 - 0x803A19C0 (409600)
Stack Area:                0x803A19C0 - 0x803A39C0 (8192)
Text (code) segment:       0x80300000 - 0x803398D0 (235728)
Boot area (physical):      0x003A4000 - 0x003E4000
Relocation Factor:         I:00000000 - D:00000000
 
Boot version: v3.7
The boot is CFE
 
mac_init(): Find mac [00:1C:10:36:41:9E] in location 0
Nothing...
 
eou_key_init(): Find key pair in location 0
The eou device id is same
The eou public key is same
The eou private key is same
Device eth0:  hwaddr 00-1C-10-36-41-9E, ipaddr 192.168.1.1, mask 255.255.255.0
        gateway not set, nameserver not set
Loader:raw Filesys:raw Dev:flash0.os File: Options:(null)
Loading: .. 3916 bytes read
Entry at 0x80001000
Closing network.
Starting program at 0x80001000
 
You can see it was giving me its IP and trying to boot. So now to try and interrupt it and get a ping reply. It also occurred to me at this point, previously trying to connect/talk to it I had plugged the cable directly from the router into my laptop. This was problematic as linux was trying to auto-negotiate and DHCP to the interface, which seemed to also introduce a delay, the delays were small but when I'd see the bootloader via serial I realised how time-sensitive the whole approach was. So using a mini-hub I connected the two together and started the ping again. Again I rebooted and found it didn't reply to pings.
The CFE bootloader can be interrupted by a CTRL-C to go interactive (like grub, lilo, etc) so the next trick was to try and interrupt it. Again this was time-sensitive and I found I had to keep hammering away at CTRL-C whilst plugging power into the router. A very tricky thing to do, but keep trying. Probably 10-20 attempts. Finally I got in and it responded:
 
mac_init(): Find mac [00:1C:10:36:41:9E] in location 0
Nothing...

eou_key_init(): Find key pair in location 0
The eou device id is same
The eou public key is same
The eou private key is same
Device eth0:  hwaddr 00-1C-10-36-41-9E, ipaddr 192.168.1.1, mask 255.255.255.0
        gateway not set, nameserver not set
Automatic startup canceled via Ctrl-C
CFE> ^C
CFE> ^C
CFE> help
Available commands:

rndis               Broadcom USB RNDIS utility.
et                  Broadcom Ethernet utility.
modify              Modify flash data.
nvram               NVRAM utility.
reboot              Reboot.
flash               Update a flash memory device
memtest             Test memory.
f                   Fill contents of memory.
e                   Modify contents of memory.
d                   Dump memory.
u                   Disassemble instructions.
autoboot            Automatic system bootstrap.
batch               Load a batch file into memory and execute it
go                  Verify and boot OS image.
boot                Load an executable file into memory and execute it
load                Load an executable file into memory without executing it
save                Save a region of memory to a remote file via TFTP
ping                Ping a remote IP host.
arp                 Display or modify the ARP Table
ifconfig            Configure the Ethernet interface
show devices        Display information about the installed devices.
unsetenv            Delete an environment variable.
printenv            Display the environment variables
setenv              Set an environment variable.
 
As you can see, we can now get to the bootloader commands, whilst this appeared my pings to 192.168.1.1 worked, so I now had a chance to get into it! I immediately tried sending a new firmware via TFTP to the Linksys. Trying to send the firmware over tftp was failing, so I was a little confused, until I read about CFE and how it works, and realised, by interrupting its boot process, it stopped its ability to receive firmware. So I now started to read about the commands, as I wanted to do it all in one go now, no more reboots as who knows if I'd get back into this mode again! Checking the commands I saw the erase and flash options. Checking again at DDWRT it showed that I could erase the existing/faulty flash 'nvram erase' which confirmed back with a 0 (for ok). I then found parameters to the flash command, and this accepted flashing from a TFTP source, so by doing:
flash -ctheader : flash1.trx
I could start the flash, at the same time sending the file via tftp it started to upload:
 
CFE> nvram erase
*** command status = 0
CFE> flash -ctheader : flash1.trx
Reading :: CODE Pattern is CORRECT!
upgrade_ver[v4.20.6] upgrade_ver[42006] 4712_ver[15000]
Done. 3032064 bytes read
fname=flash1.trx 
CODE Pattern is correct! (W54G)
Programming...done. 3032032 bytes written
*** command status = 0
 
At that point I typed 'go' which told it to boot, and sure enough after a few seconds DDWRT kernel boot messages appeared and eventually got the DDWRT root prompt, so I'm back in.
 
Hopefully the above will be handy to anyone in the same situation and thinking their router is toast. Persistance and keep on reading for solutions, good luck!
 

 

Friday, 28 December 2012

Arduino and Sky box innards

 Well as its Christmas I've had a bit of time on my hands so thought I'd start on a project a friend of mine, Adam thought of. He's key developer on TVHeadend and liked the idea of replacing the Sky+ box. That's been the drive behind TVHeadend, XBMC, etc. So why not go a step further? Take that old Sky plus hardware/case and re-use it for the XBMC PC with fully functioning front-panel.

I've had a few Sky+ boxes lying in my garage for a while now (Faulty capacitors, or just old hardware so they just sit there), so I thought I'd rip one open and see whats going on. Firstly we know the insides of the Sky+ box,

its 1 main motherboard, a PSU board and hard-drive. Then a ribbon cable feeds the front panel. So HDD comes out, and I pull apart carefully the front panel. Luckily they're made to disassemble, so a couple of screws at the side and the front panel then can unclip with gently prising the locking tabs all round it.

This revealed the front panel innards, and a 2-part circuit board with a lot of circuitry on it.

   

Not what I was expecting, I was thinking more along the lines of either I2C or a simple LED cluster that fed back to the motherboard. I powered up and started to probe the pins to see what I was getting. Unfortunately I don't have an oscilloscope so I couldn't see any data/signalling, so just went on voltage initially. Unfortunately all I found was ground, power and standby-power. Pretty disappointing. I then tried to find out what the LEDs that light up the Sky playback circle (The sequence of LEDs that go round in a circle when playing back video, etc). Unfortunately as I don't have an active SKY card in, even the demo won't display this sequence, so again I've had to give up on this. So I've decided to pull the circuit board out, and do my own thing! Fit a cluster of LEDs in the back and just feed those back to my Arduino board.

The idea is that I'll plug the arduino into the XBMC/Openelec box using USB. I can then write a serial communication language that will send status to the arduino that will then display on the LEDs. On top of that I'm going to cut out part of the front panel of the Sky box and put in a backlit LCD screen, that will show current channel, now/next, something like that (Not fully decided). Last night I got as far as mounting the LEDs behind the facia and started to check they were aligned (tricky!). Next will be to start wiring that to the arduino to see if I can get the 'animation' of the LEDs looking anywhere near OK.

If anyone has done any more interfacing with the Sky+ front panels or figured out the control lines, etc, please let me know! I'd love to get the original circuit board running somehow.

 

 

Thursday, 20 December 2012

Borri UPS for home use

Around a week ago my APC Smart UPS SC420 decided its battery needed replacing (again!). I only seem to get around 2-3 years out of mine which started me thinking, why on earth do I get such short life from something 'relatively' expensive. These units come in at around £120 and batteries around half that. For 420va that doesn't seem too great, as all I do is power 2 machines (desktops with a few add-ons) and a network switch/wifi. Mainly to protect the computers from nasty spikes and unexpected shutdowns more than running without power (since the internet router is in the house, not connected to a UPS).

However, I wanted to replace the UPS to keep the protection up, mainly as the power in my area seems to spike and brownout quite a bit and I've had a lot of things go pop as a result of this (X10 kit hates this kind of choppy power, hence most of my X10 home control stuff going bang). So I duly went to APC and looked up the replacement battery. It came out at around £50 after postage, etc. So I then looked at the APC upgrade wizard, see what they would offer me for a trade-in, as I particularly like the idea of trading in old hardware to get new for a bit of discount and I feel I've done the environment some good with them having batteries inside, etc. For trade-in I was disappointed. I could get a replacement unit for around £100, thats with the same 420va limitation, which since I run that at around 80-90% load isn't great (and I suspect why I go through batteries so often). So looking at the next up capacity 450va, this was £151 for really very little difference, or the 550va model for around the same price. Not very impressive.

So I started doing my usual answer to everything, google for recommendations or alternative brands, Borri kept coming up as they appear to do all sorts of UPS and generator equipment from SOHO right up to datacentres, etc, and looking quite promising I looked at the B60 range. These started at 800va and went up to 2000va, and shopping around for prices. I was pleasantly surprised, the B60-800va version would be £71 delivered, etc. So thats approximately double the rating for a nice £71.

The next issue before ordering, was it linux compatible? For years I've used APC units and used the ever popular opensource APCUPSD to shut down servers when batteries neared depletion, etc. Firstly Borri provided a download of linux software. An excellent start. Checking the software it wasn't what I'd hoped, it was a java-based server/applet that basically talked to the ups over USB and presented output via a flash-based web-ui on a custom java-tomcat url on your machine. OK, not the end of the world. I did more digging and thought of NUT for linux. This looked to support it, so worth giving it a go.

UPS arrived next day and it's quite a nice looking unit, really clear permanently lit LCD on the front telling you input volts, output volts and current status (Battery level in bars, current load level). I plugged it into my laptop to play around with and get an idea of the java tomcat web interface. It actually was quite neat, just a pity it was flash and didn't seem to have a raw data port/method of extracting data from it otherwise I'd have stuck with it.

Installing NUT and setting it up for the Borri wasn't too bad, it's partially supported according to NUT using the blazer_usb driver, but this doesn't give you battery level/capacity and time to depletion. No real issue, I can survive!

I've yet to add my load of machines to it and see how it copes, but so far its looking pretty good. If I figure out the battery level/capacity part of it I'll be very happy with this solution.

 

Sunday, 9 September 2012

TVHeadend

 Quite a while since I did a post, and things in the TVHeadend and XBMC world have moved on quite a bit. TVHeadend is now being actively developed, primarily resolving the EPG issues that were around in the past, but then also moving onto loads more improvements. Therefore things have moved to a development environment, so if you want to try out the latest you can on github.com/tvheadend. Or via the original www.lonelycoder.com site where you can get debian packages and official releases. Hope you like all the updates!

A few people have also asked me about the dev stuff I've done, I've got a few testing areas for TVHeadend at my own github (http://github.com/andyb2000/) so take a look, and drop me a note if you want to try anything out as I'm always looking for new testers, or join the TVHeadend lot on IRC freenode.net #hts

 

Saturday, 14 July 2012

XBMC, TVHeadend and watching live TV

 As some of you may have followed in earlier posts I've been replacing our old Sky satellite setup with my own setup here at home. Well over the past month or so its improved considerably so I thought I'd write up where I'm up to with the whole setup and how the family are getting along with it.

Firstly the problem, Sky is expensive and to be honest the majority are repeats and most of the channels we frequently watch are FTA (Free-to-air/satellite) in the UK, so dropping Sky was logical. So I then had the Sky dish and the problem of how to feed it into the house setup. Firstly the front-end. I've used XBMC since the early days on the original XBOX thanks to Bunnie Huang and his amazing books, etc. (Google it!). So I'm happy with XBMC, so setting that up on a small footprint PC with quiet fans and HDMI out. I bought a cheap Nvidia card with HDMI out (Cost around £35), as these cards can do hardware decoding, this is important as it takes the load off the PC's CPU and very important when your machine isn't the most powefull on the planet. So with that in the PC (It's a slim-line Dell so fitting the Nvidia was a pain, the case doesn't quite close properly, but its hidden out of sight so not a problem). The HDD in the XBMC machine isn't too important, big enough to hold the XBMC install is enough as you won't really be storing anything on it. Save your disks for the 2nd bit of hardware! Networking is also important, make sure its cabled up right and if possible use Gigabit network cards+switches as it'll speed the whole system up (Although for HD tv you can get away with 100Mbps as HD tv streams are 35Mbps (at worst) dropping down to 6Mbps.

Install XBMC: Simply download their Live CD XBMCUbuntu, burn that and run it. There is the option to install, choose that and wait whilst it flattens your HDD, partitions, installs, etc. Now a word of caution. Make sure your graphics card, hardware, etc, are all plugged in at install, as the installer does a really good job of installing the right components if it finds the right hardare. It'll save you a world of pain later! So now you should be booting XBMC from HDD and getting things looking reasonable. You can tweak this as you need. Insert a MS media centre remote for remote control/IR functions (Pretty much any will do, I found the older silver ones work better than the newer branded editions (HP badged, etc, I found didnt work reliably). There should be little else you need to do.

To get TV functions into XBMC you need the latest packages, Pulse-Eight provide these in an easy script, SSH to your XBMC machine, then run these commands:

       cd /tmp; wget http://packages.pulse-eight.net/ubuntu/install-xbmc.sh; chmod +x install-xbmc.sh; ./install-xbmc.sh

Thats all one one line to make copy/paste easier! What this does is grab the install script from Pulse-Eight, set it to executable and run it. This adds a repository into Ubuntu with the relevant updates, upgrades and does it all for you. When its done, just reboot and you should have XBMC again but this time it will have additional TV functions hiding. This is all we do with XBMC for now.

(NOTE: XBMC has a few problems with standby, resuming usb devices at the moment, this appears to be an Ubuntu issue and not XBMC, so if you set your settings > power savings to standby when power pressed and after resuming you find it won't make the IR remote work you've got the bug. There are loads of forum posts about it. I've tried them all and with no success as yet unfortunately).

If by chance your IR works after resume then you'll want to be able to wake the XBMC machine from its sleep by the remote (So a simple power button press on the remote will wake it). If thats the case you want to look at adding the following to /etc/rc.local:

 

echo "USB0" > /proc/acpi/wakeup
echo "USB1" > /proc/acpi/wakeup
echo "USB2" > /proc/acpi/wakeup
echo "USB3" > /proc/acpi/wakeup
echo "USB4" > /proc/acpi/wakeup
echo enabled > /sys/bus/usb/devices/7-2/power/wakeup
 
That last line you need to find the correct numeric value (Instead of 7-2). Do it just by typing lsusb, look for your IR device and the numbers you need are the BUS and DEVICE. So in mine above I had:
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 002: ID 0644:0200 TEAC Corp. All-In-One Multi-Card Reader CA200/B/S
Bus 002 Device 003: ID 046d:08cc Logitech, Inc. Mic (PTZ)
Bus 007 Device 002: ID 045e:006d Microsoft Corp. eHome Remote Control Keyboard keys
 
So the last entry is my IR remote, take the 2 numbers 007 002, remove the 0's and you have the 7-2 needed for the wake command. This will allow your USB devices to wake the machine when its in sleep.
 
 
 
Now onto the Satellite part of things. TVHeadend. This is best ran on a separate machine. A few people run it on the same machine as XBMC but this appears problematic and you will also need to leave the machine on, or do some trickery to wake it at the right time to handle recordings, so we're skipping that and using a dedicated machine. The other advantage is you can stick this out of the way (In my case, my modified Garage) so its on all the time. This means you don't need to use quiet fans, etc. So purchase some Satellite/Terrestrial cards. I use 2 satellite cards (DVB-S DVB-S2 are Satellite), and one terrestrial (DVB-T). If you're buying satellite cards then I'd strongly recommend to get DVB-S2 (And not the S1 cards), because some channels in the UK now are only available on the more advanced S2 streams, so to future-proof I'd go DVB-S2. I'd also recommend against combination cards (2 receivers on one card, one sat one terrestrial, etc), as in some cases Linux won't be able to use the different elements separately and you'll end up restricting what to do.
So I installed one DVB-S card, one DVB-S2 card and one DVB-T card (All PCI as USB is also problematic in some cases). I did a normal/basic Ubuntu server installation (No graphical interface needed, but if you're a novice it won't harm). Get it all up to date and then get ready for the other installations.
 
Next I created a storage area for recordings. On my network I have a NAS (Network Attached Storage) so I used this, however for these instructions I'll show you how to make your TVHeadend server into a basic NAS for TV use. The reason I did this was that it allowed all machines on the network (Regardless of if they ran XBMC or TVHeadend integrated) to view and playback recorded material. On my network at home I used NFS as the majority of my network is Linux-based. So you need to install the nfs server to your TVHeadend machine:
apt-get install nfs-kernel-server
After install you need to create your storage area, so do something like:
mkdir /home/recordedtv
We'll use that to save all our TV to. So you need to export that from NFS:
echo "/home/recordedtv *(rw,sync,no_subtree_check,no_root_squash)" >> /etc/exports
This adds the folder to the export for NFS with a few parameters, WARNING: we are letting anyone that connects full read/write access without restrictions. Only do this if you trust your network, otherwise read up on safer NFS settings.
 
Now we need to install TVHeadend. At the moment there is some active development which is providing amazing changes to how EPG and the main TVH system works, this work is done by Adam Sutton who has made some great updates to TVH. I've been very lucky in being able to beta-test a lot of code and provide input to its development, so I'm very grateful to Adam who has humoured me all along! So at the moment this would be the branch I would recommend over the main tree or the debian packages. So it's a little more involved compiling but its worth it! So here are a few simple instructions to get you started:
apt-get update
apt-get install build-essential git 
cd /usr/src
mkdir tvheadend
cd tvheadend
git clone https://github.com/adamsutton/tvheadend.git
git pull origin initialscan
You should now have a full copy of the latest dev code. Go into that folder (cd tvheadend) and you can then start compiling. I can't remember if there were additional dependencies for TVH so if configure fails you will need to add the dependencies. If you're unsure pop a comment/tweet over to me and I'll help out and update this doc.
 
cd tvheadend
./configure --prefix=/usr --release
make
 
That'll give you a working TVH binary to use. Only a couple more steps to go now! 
Create a user for TVHeadend to use:
adduser tvheadend
You can then use that to run TVH, etc. So change to that user and do a simple setup task. This is because at present the work is in development. So carry out:
mkdir ~/.hts
mkdir ~/.hts/tvheadend
cp -Rp /usr/src/tvheadend/tvheadend/data/epggrab ~/.hts/tvheadend
All this does is creates the TVHeadend config folders, and also copies the libraries needed for EPG grabbing to work.
I tend to run TVHeadend it in a screen process so you can see if any errors occur, so you can do this:
screen (Press enter on the information screen that appears)
cd /usr/src/tvheadend/tvheadend
./build.linux/tvheadend -s -d
 
That'll fire up TVHeadend. Hopefully it'll run and got exit with an error. If so you can now swap to the webui and start to configure it.
The rest of the config is fairly standard, in the new EPG grabber tab make sure under the OTA section you enable OpenTV: Sky and EIT grabbing. The channel name/number/icon is experimental so you may wish to leave this off for now. Continue on to the TV Adapaters section and setup the rest of your TVH setup as normal. This is documented elsewhere and I've documented under my old XBMC section so take a look there is you're totally new to TVH.
 
Good luck, and as always please do get in touch if you'd like a bit of extra help with your setup.
 

 

Wednesday, 13 June 2012

UK Cookie Law

 UK Cookie Law Compliance.

Well the ICO have required all EU websites that use cookies to apply a compliance method on the 26th May 2012. What my views are on this? Well if you want to accept cookies, your browser will accept them. If you don't you set your browser to NOT accept cookies and you're done. But apparently that isn't the 'right' way according to the ICO's techs, so all website authors, operators, etc, have to do something a bit different. In most cases you have to block the cookies until you get confirmation from the user. However these have been updated and now gives us the option of implied consent which gives us a little simpler option to take here. We'll implement this on the website here, basically by visiting the site you are accepting that we will use cookies to assist in the website experience, however if you do not login or provide account details then this information will simply be used for statistical analysis and production of website usability.

The above is basically our cookie policy for this website, the website is a not-for-proft, hobbyist site and so the use of cookies are simply for user statistics, or where a user registers for easing their use of the site/login/administration.

 

(PS: You'll also notice at the bottom-right of the website my cookiecontrol compliance, this is a nifty little free add-on that helps you with the compliance, its from  http://civicuk.com/cookie-law/index if you want one!)

Monday, 11 June 2012

Arduino - Cheap wifi connectivity

Building a cheap ethernet connection for my Arduino. I needed to relay data from my Arduino back to my home server. The location
makes wired prohibitive, but I also don't have CAT5 cabled to the location I had the Arduino in. I then looked at the various
shields available, the Ethernet shield wasn't too expensive at around £20, but this would mean wiring, and the location in the kitchen
was particularly difficult to get wiring to.
 
I then looked at wifi shields, these came in at around £85 and way too expensive for just a little hobby project, the in-between options
of using Zigbee interfaces, which is a slightly cheaper option, but I was concerned about the distance and complexity of setting
this up with my server.
 
I therefore started posting to mailing lists and trying to find a way of doing a wifi-bridge cheap, or USB over wifi. All I needed was
to get the usb/serial data out from my Arduino to my server so that I could graph it, monitor it, etc.
A kind chap on an ISP mailing list brought forward the TP-Link TL-WR703N suggesting that this device can be flashed with OpenWRT
and then act as a wifi bridge. This sounded interesting, and you can get them on eBay for less than £15 inc delivery. This was sounding
good.
 
The TP-Link TL-WR703N has 3 physical ports (RJ45, USB host and power (via a micro-usb port)). It also has integrated WIFI. So my
idea was to connect the wifi up to my house wifi, then use the USB port to monitor the serial output from Arduino. Ideal!
 
The TL-WR703N arrived, all in its chinese writing and unfortunately its chinese web admin interface. Luckily for me, the OpenWRT
site for this device was very detailed and told me exactly what to click to upload OpenWRT.
Then OpenWRT site at http://wiki.openwrt.org/toh/tp-link/tl-wr703n Had all the details to flash it, very simple and quick.
Once flashed with OpenWRT a little more tweaking was needed. I've generally not done much with OpenWRT in the past, I stick to DDWRT
which has a nice web-gui, so OpenWRT involved SSH'ing to the unit and setting the rules correctly for what I wanted.
 
I did a bit of reading on the OpenWRT recipies site on what I needed which was to be a client on a mixed WPA2-Personal AES 
encrypted wifi with MAC protection.
The basic method is follow the outline of a MASQUERADE CLIENT on OpenWRT and adjust accordingly. So my /etc/config/network looked like:
 
config interface 'loopback'
option ifname 'lo'
option proto 'static'
option ipaddr '127.0.0.1'
option netmask '255.0.0.0'
 
config interface 'lan'
option ifname 'eth0'
option type 'bridge'
option proto 'static'
option ipaddr '192.168.1.1'
option netmask '255.255.255.0'
 
config interface 'wan'
option ifname 'wlan0'
option proto 'dhcp'
 
(Note that I left LAN on the 192.168.1.1 setup, this meant that if the WAN or dhcp failed I can plug into it and still admin the thing)
 
/etc/config/wireless was a bit more tricky:
 
config wifi-device 'radio0'
option type 'mac80211'
option channel '1'
option macaddr '8c:21:0a:d8:7b:57'
option hwmode '11ng'
option htmode 'HT20'
list ht_capab 'SHORT-GI-20'
list ht_capab 'SHORT-GI-40'
list ht_capab 'RX-STBC1'
list ht_capab 'DSSS_CCK-40'
 
config wifi-iface
option device 'radio0'
option mode 'sta'
option ssid 'MYSSID'
option encryption 'psk2+ccmp'
option key 'MYPSKPASSWORD'
 
To find these settings you issue 'iwlist scan' and look for your SSID and the other settings. So in my case I set the channel of 1.
The encryption of psk2+ccmp (This refers to wpa2 with AES encryption). After doing that you can then do 'ifup wan' and 'wifi' which
should then get things working. Except in my case it didn't. I checked, I had the MAC address in my wifi router, all looked fine but it
wouldn't join the WIFI. The settings in OpenWRT are a little hazy so I assumed this was the problem and spent a while here, but in the end
I found turning MAC protection off temporarily on my DDWRT allowed it to connect, enabled it, saved and it all works each time now,
so unsure if I hit a bug in my DDWRT on my wifi access point or something, but for future, debugging with MAC protection turned off
is a lot easier!
 
Now I had it connected I needed to get info from the Arduino over the USB port. I plugged it in hoping for the /dev/ttyACM0 to be
created, but no luck. I got the USB insert message:
[   10.020000] usb 1-1: new full-speed USB device number 2 using ehci-platform
So it looks like the kernel driver doesn't exist.
Luckily the OpenWRT group have a packaging system that includes a lot of drivers and add-ons, so using the package management to install:
 
opkg update
opkg install kmod-usb-acm
 
Reboot, and when I plugin the arduino, success, I see:
[   10.020000] usb 1-1: new full-speed USB device number 2 using ehci-platform
[   10.160000] usbcore: registered new interface driver cdc_acm
[   10.160000] cdc_acm: USB Abstract Control Model driver for USB modems and ISDN adapters
[   10.210000] cdc_acm 1-1:1.0: ttyACM0: USB ACM device
 
And the /dev/ttyACM0 is there. Last trick is how to get a couple of lines of data from the serial connection and SSH/SCP it up
to my server. This proved a little tricky, as first of all getting just a couple of lines of data from a constantly flowing serial
terminal, then the scp function itself.
 
To get just a couple of lines of serial I firstly tried the stty trick "stty -F /dev/ttyACM0 9600 -echo -onlcr time 50 min 0" and then
cat /dev/ttyACM0 which will read data for a specific amount of time. This was very unreliable and often hung the /dev/ACM0 interface.
So I looked to alternatives. I then tried a constant/background "cat /dev/ttyACM0 > /tmp/serial.log", periodically from cron reading
it and zero'ing it. Problem here was the filesize growing and causing the device to hang due to the limited ram on the device. Also when
/dev/null'ing the /tmp/serial.log the cat then failed and a kill/hup to the cat caused the ACM0 to hang again! So no good there.
Finally I tried "head -n 12 /dev/ttyACM0 > /tmp/arduino.log" So this output the last 12 lines from the serial console to a file.
(Overwriting the file each time keeps it low filesize). Then I can parse this for the info I need, and then scp it over. Except scp
doesn't exist as the ssh is just dropbear! So again to opkg and install the ssh client tools so I get the scp binary. Generate an
id_rsa key and then I can scp my output over: "scp -i /etc/dropbear/id_rsa /tmp/arduino.log [email protected]:/tmp"
Success! I can now parse this with my graphing tools.
 
Enjoy, and thank you to the TP-Link TL-WR703N for a cheap and nifty solution! (PS: Got any direct questions? See me on twitter: www.twitter.com/andyb2000 )