Category Archives: Uncategorized

Rfduino Chip vs Thermometer

Well, I’ve now debugged a few issues with my scripts from my last post.
(made them a bit more fault tolerant and actually take notice of $? exit statuses) .
Recap: Temperhum (USB) -> Raspberry Pi -> Xively chart, now also
RFDuino (bluetooth wireless) -> Raspberry Pi -> Xively chart

Tip:  If you’re struggling with the bluetooth on linux giving rx timeout errors (check the syslog if it’s not in the console),
update the software with the following commands:

sudo apt-get update
sudo apt-get upgrade

The Rfduino has been sitting next to my usb Temperature and Humidity sensor for a few weeks collecting data.

IMG_20140514_223244041r

RFDuino and Temperhum

Since it had been both collecting data for a few weeks and sending them to Xively / Pachube / Cosm, I had a quick look to see how closely the readings match.

Rfduino vs thermometerr

The graphs do show correlation, thank goodness, but it looks like the RFDuino’s temperature scale isn’t right. The RFDuino is only updating the graph once a minute whereas the Temperhum is 2x a minute.

I didn’t really expect great accuracy for the RFduino thermometer seeing as it’s measuring from the chip. But this would still be useful in some more basic cases.

I think next on the roadmap for the RFduino is connecting sensors/remote controls (it would be cool to attach my RelaySockets to this and control the 2 connected relays via bluetooth from my Pi and Android smartphone!

 

My Humidity and Temperature sensor

A Temperhum from PCSensor.

A great little bit of kit – once you work out the conversion values for the C++ USB/i2c/HID code that lets linux talk to the thing!

Getting Rfduino working with Linux

Intro:

I ordered this nifty ‘RFduino’, an arduino-compatible device which was also my first ever kickstarter purchase over a year ago now.
However, when the device arrived, the company behind it seemed exclusively interested in the iPhone handset to the detriment of all other platforms.
Personally, the lock in monopolistic attitude of Apple and its customers really gets my goat, but I digress.

The lack of support and that the device arrived half a year late left me with a sour first taste of Kickstarter.

Since then, I’ve played with the Rfduino using JT’s iGear (no, I don’t know why fell into the Apple pit either) using the only app available to use the sketch it comes with – the internal thermometer

But that’s rather limiting!! I bought this device with plans to build a Wireless ‘Internet of Things’ sensor network for my house.

I have designs on talking to every platform available using protocols such as mqtt, backends like rrdtool and web interfaces for my housemates to see and control the action.

This is something I’ve been dreaming and sketching out  for years, because lets face it, who doesn’t think having the lights turn out when you leave is super cool?

So without further ado, how do we get the RFduino to talk to a linux machine, in my case a Raspberry Pi running Raspbian.

Ingredients:

Hardware:

You will need

  • Internet connection to download tools
  • Bluetooth packages installed (bluez-tools)

Howto:

Power on the  RFduino and linux machine. I used two Alkaline AA batteries to power the RFduino although Rechargeables do work.

Install the Bluetooth 4 usb adaptor on the linux machine
Install the necessary bluetooth programs:

sudo apt-get install bluetooth bluez bluez-utils bluez-firmware

(you may need to reboot the machine afterwards, I don’t believe I did)

Bring up the bluetooth interface:

sudo hciconfig hci0 up

Run a Low Energy scan to find the address of your RFduino:

sudo hcitool lescan

Should elicit results similar to this:
EA:BA:20:48:37:80 (unknown)
88:D8:CD:08:12:FA (unknown)
99:D8:CD:10:66:FA (unknown)
DD:AF:13:17:23:80 RFduino

Select and copy the MAC address given for the RFduino on your system.

(I have no idea why you have to scan as root, someone please leave a comment if you do, and if theres a way to run as a normal user…groups?)

 

Read the temperature attribute from the RFduino using gatttool. Paste your devices MAC address in instead of mine of course.

sudo gatttool –device=DD:AF:13:17:23:80 –interactive
[   ][DD:AF:13:17:23:80][LE]>
[   ][DD:AF:13:17:23:80][LE]> connect
[CON][DD:AF:13:17:23:80]][LE]>char-read-uuid 2221
[CON][DD:AF:13:17:23:80][LE]>
handle: 0x000e value: 00 00 a8 41 00 00 00 00 00 00 00 00
[CON][DD:AF:13:17:23:80][LE]>disconnect
[   ][DD:AF:13:17:23:80][LE]>quit

Now from that exchange with the RFduino, we have gained a long hexadecimal string.
From a post on the RFduino forum, I learned that the value we want is always after the ’00 00′ string (in bold above).
This is the temperature read from the RFduino’s internal sensor * 8.
So we need to convert this to Decimal and divide by eight to retrieve the temperature value in celsius (American readers, why aren’t you on SI units yet? :P).

Convert the hex value to decimal temperature

decimal=$((0xa8))
decimal=$(($decimal/8))
echo $decimal
21

The above method returns an integer value. This is because Bash has limitations working with numbers that are not whole (decimals).
Workarounds use the command bc to interpret string inputs as decimal numbers. I think there is a method to define variable types in bash, but I didn’t get very far with this.

My attitude is that once you start hitting the limitations of a shell scripting language, it’s time to migrate to a proper programming/interpreted language (at least python).
Spending hours and using multitudes of additional programs make it work is often pointless.

Just think, if you had to run the script on a embedded system without most of those commands, wouldn’t it just be better to do it in C++?

 

Next time:

Now that I’ve successfully read the values being sent by the RFDuino I need to figure out how to automate the process – in non-interactive mode.

These commands do the same thing but respond differently

sudo gatttool -b [MAC] –char-read  –handle=0x000e
Characteristic value/descriptor: 00 00 a8 41 00 00 00 00 00 00 00 00

sudo gatttool -b [MAC] –char-read –uuid=2221
handle: 0x000e   value: 00 00 a8 41 00 00 00 00 00 00 00 00

Simple bash script to read temperature in celsius (accuracy is lost here as the decimal is converted to an integer)

#!/bin/bash
stringZ=$(gatttool -b [MAC] –char-read  –handle=0x000e)
stringZ=${stringZ:39:2}
hex=$((0x$stringZ))
decimal=$(($hex/8))
echo $decimal
exit

don’t forget:
chmod +x [whatever you called the script]

and run it as root:
sudo [whatever you called the script]

Afterword:

I won’t pretend to understand the naming conventions of Bluetooth 4.0/LE.
I don’t! I spent a whole day looking into it and could not find a single source that easily explained the structure, naming, and profiles. If someone has seen something good, please post in the comments!

It’s frustratingly close, like I can see there is a neat logic to it, but I just don’t care to spend any more time trying to figure it out, when all I want to do is use it. This does make it slightly more hacky and less neat and quick of course, but that’s life!

 

Sources:

gattool commands to read the sensor:
http://lilyhack.wordpress.com/2014/02/03/ble-read-write-arduino-raspberry-pi/

howto convert hex to decimal on the command line:
http://linuxcommando.blogspot.co.uk/2008/04/quick-hex-decimal-conversion-using-cli.html

howto do calculations on the command line:
http://www.tldp.org/LDP/abs/html/arithexp.html

Hacked up way of using gatttool non-interactively, using ncurses and a python script:
http://thomasolson.com/PROJECTS/BLE/RFduino/LINUX/

Bash string manipulation:

Bash String Manipulation Examples – Length, Substring, Find and Replace

Others:

http://joost.damad.be/2013/08/experiments-with-bluetooth-low-energy.html

Linux Beep Music #2

So I just noticed that our beep music post has become popular enough to have been reddited, and used as a source in a video!

So thanks for that guys and girls of the interwebs! I almost feel appreciated!

In recognition, I thought I’d list our referrers, and possibly some beep music. Maybe we can become a repository for this kind of stuff.

 

#0 So you have a shiny new Raspberry Pi, and you want to make some noise?

You can in fact make beep music on the raspberry Pi!
All you need is a Piezo thingy (transducer or beeper or whatever it’s called)
(Available from Maplin in the UK: 3v ceramic Piezo transducer only £1.29 as of 2/2/14!!)


Thanks to Kronalias (is that a linux reference there? `alias kron=’crontab’`)?

 

#1 Here’s a video from smeezekitty on youtube:

From the comments: running beep music on a 486!

Yep that’s code from our last post being run!

Reminds me of this old beastie of JT’s:

IBM Thinkpad 380z

Still working in 2014! I am in fact a IBM Thinkpad 380z with a PII processor, 64mb of ram, and most inexplicably a 40GB hard drive. I also have a very loud beeper which will hurt your ear if you are next to me when it goes off. Lucky i have a volume knob.

I will definetely try all the beep codes that have been submitted in the comments so far on this awesome machine, and I promise to make a video of it if I get three more beep-songs to add to our beep music tracks. (I might even make an Album…on tape cassette [if i can find one haha], or maybe just put it onto a floppy disk if and mail it to you guys [if i can find one that works ROTFL])

#2 The redditors of the web have heard of us!

It must be true if there’s a screencap of it!

Popularity!! and i'm certainly condering repository of beep music. Probably a wiki though.

Popularity!!
and i’m certainly condering repository of beep music. Probably a wiki though.

#3 We were linked to on Stackoverflow

I can’t be figged to give you that link or clip an image, so here’s a link to another source posted.

Ubuntuforums: What is your favourite ‘beep’ song?

#4 Bleep music in the Blogosphere: Blog post: Davidak is playing with beep music

I have no idea what he’s playing as my laptop speakers are bust! I can’t be held responsible it’s rude, honest!

Musik mit BEEP (Linux) from davidak on Vimeo.

 

#5 Axel Foley – Beverly Hills cop

Credit to ? Øyvind Hvidsten at Bolt Blog for his post – fun with beep
He has both the Axel Foley theme tune (listed below) and also Beethoven’s Für Elise.

beep -f 659 -l 460 -n -f 784 -l 340 -n -f 659 -l 230 -n -f 659 -l 110 -n -f 880 -l 230 -n -f 659 -l 230 -n -f 587 -l 230 -n -f 659 -l 460 -n -f 988 -l 340 -n -f 659 -l 230 -n -f 659 -l 110 -n -f 1047-l 230 -n -f 988 -l 230 -n -f 784 -l 230 -n -f 659 -l 230 -n -f 988 -l 230 -n -f 1318 -l 230 -n -f 659 -l 110 -n -f 587 -l 230 -n -f 587 -l 110 -n -f 494 -l 230 -n -f 740 -l 230 -n -f 659 -l 460

 

#6 And finally, some beep music. From the comments on Linux Beep Music, ‘Easy Mitrontix Billing’

(I have no idea how that passed the spam filter, but I’m glad it did).
He submitted the following, including note frequencies – now I can translate any song!!!
Maybe I’ll write a bash script to automatically do that given the notes interactively.

“Mission Impossible Song.

#Note Frequency
C=261.6
C1=277.2
D=293.7
D1=311.1
E=329.6
F=349.2
F1=370.0
G=392.0
G1=415.3
A=440.0
A1=466.2
B=493.9
C2=523.2

C22=554.3
D2=587.33
D12=622.2
E2=659.26
F2=698.46
F22=739.99
G2=783.99
G22=830.61
A2=880.00
A22=932.33
B2=987.77
C3=1046.50

#First

beep -f $G -l 250
beep -f $G -l 500
beep -f $G -l 250
beep -f $G -l 250

beep -f $A1 -l 250
beep -f $C -l 250
beep -f $G -l 250
beep -f $G -l 250
beep -f $G -l 250
beep -f $G -l 250
beep -f $F -l 250
beep -f $F1 -l 250
beep -f $G -l 500
beep -f 10 -l 500

beep -f $G -l 250
beep -f $G -l 500
beep -f $G -l 250
beep -f $G -l 250

beep -f $A1 -l 250
beep -f $C -l 250
beep -f $G -l 250
beep -f $G -l 250
beep -f $G -l 250
beep -f $G -l 250
beep -f $F -l 250
beep -f $F1 -l 250
beep -f $G -l 500
beep -f 10 -l 500

#end”

Conclusion:

(i’ve been writing too many technical document recently!)

I couldn’t find Chop Suey in beep music, but with the work done in #3, it shouldn’t be too hard to translate!

Next time I’ll have to compose something entirely new!!

 

 

My life, part 3, 1998-2005

This is part three of my autobiography so far. Part one is here. Two is here.

Grin

So, just before I went to secondary school (age 12+) for the first time, we went to a covie camp. This was important for one main reason. During one of the sermons, we were shown a film, and whilst watching, I had an moment of absolute clarity, and total conviction. Christianity is true, there is a God, and he does love me. You know, typing that will never not be strange.

I broke down crying. I remember that moment as if it were an hour ago. I became a Christian. So, in a weird sort of way, my parent’s divorce kinda led me to converting to Christianity.

About year two or three of secondary school, I started going to visit the school counsellor. I remember nothing of those visits, only that they were helpful. During that time, I shunned friends, and mainly stayed in the school libary during my free time, or read books. I used books as an escape, leaving this world for different ones, preferring anything strange or different. I stripped through crime, fantasy and science fiction books rapidly. I also volunteered to help in the school library, putting books away, keeping it tidy and neat.

At some point, the school counsellor left, and a new one arrived. I didn’t gel with the new counsellor at all, and so didn’t go back. That would be my last counselling session for quite some time. Time passed.

At some point during this time, I felt snubbed by the librarian, a silly thing, I felt I’d been passed over for some additional responsibility. Additionally, I had a very brief ‘girlfriend’ and a relationship that I wouldn’t really engage at all with. That also led to an embarassing suituation a little while later, which I won’t repeat, which helped solidify my intent to remain a bachelor for some time, and would be the only time I briefly had a girlfriend, or any sort of significant other, to date.

Watching the solar eclipse at a covie camp

Watching the solar eclipse at a covie camp

I switched from volunteering at the school libary, to helping out in the school IT suite, spending any spare time playing with the computers. I was the source of at least two spates of communication tools getting around the IT department’s lockouts to prevent them, since I just continually played with the sandbox I was given. For those geeks, at this point we were running windows XP. I however didn’t keep my mouth shut about the ways to talk to other pcs, and they spread like wildfire around the school, till they were locked down.

That was the first point I really got interested in computers.

During all this time, we had an… interesting contact schedule. Dad got us 2 and a half weekends out of every 4, and a weekday evening. We were with mum the rest of the time. Dad was at this point working for Kleeneze, delivering catelogs and taking orders. Since mum and dad didn’t really get on, or talk that much at all, we had basically different responsibilities and rules at each place. To an extent, we just got used to it. Mum and dad took turns to have us christmas, with the other parent having us over new year.

New year 2000, the milienium, I was at a relatively boring party at my church. I never did really get the whole new year thing, and to this day I still don’t.

Eventually, I did A-levels. I am the proud bearer of 2 A levels in vocational Information Comunication Technology, or in other words, how to use Microsoft Word. I only got a C in that, mainly because I was bored out of my mind, and the spec was just a bit mad. We did get taught some useful snippets though, I learnt basic binary and database normalisation. That was also the first time I created a website.

Next up, my first job.. To Be Continued…

Windows Command Line Ping Replacement

So the windows version of ping is really stupid.

I was writing a batch script to mount up a network share that involved checking to ensure my NAS unit was turned on. The script is scheduled to run after the computer resumes.

What I found out is that the built in version of Ping.exe is terrible at telling you whether the ping has returned successfully or not. I was checking the ERRORLEVEL – %ERRORLEVEL% variable to find out what ping was returning. It should be 0 for success and 1 or higher for a failure.

What I found was, i was getting replies from the local pc (dunno why, leave me a comment if you know) and ping was reporting a success even though the correct pc failed to reply. The solution?
Replace the Windows ping.exe with Fping. It has a lot more options and appears – from some initial quick tests – to correctly report the errorlevel.

Kudos to Wouter Dhondt for developing it. I’ll update this post with any more news!

 

image Fping vs Ping errorlevel return values

Sports headphones Review

I’ve been looking for a really good set of headphones to use while doing extreme sports (Bocking) which has got to be the best test of how well the headphones stay in your ear!

I’ve tested a few different sets headphones designed specifically for sports (jogging) and ones that are not (in ear/noise isolating silicon ones.
Here’s a short review with ratings 1-5 (where 5 is best) in various categories. Scroll to the bottom to find out the overall winner!

Sennheiser Mx55 ((£15 from HMV)
Comfort 4 (can get a bit unconfortable after a few hours in)
Sound 5 (excellent sound quality)
Volume 4 (Not as loud as i’d expected, but also doesn’t leave my ears ringing after listening with my player on full volume)
Quality 4 (the snap on interchangeable covers designed to let you bling it up a bit are pointless and come off too easily. I’ve superglued one already, but at this price, who’s complaining?!)
Hold/fit 5 (they stayed in for hours while i bounced around, amazing!)

EDIT: Superglue the rubber bits on too, they fall off in pocket!

Skullcandy in ear
Comfort 4 (pretty comfortable until i took them out then found my ear holes were quite sore)
Sound 3 (good, but lacking something, and no matter of EQ tweaking could give me that…too crisp)
Volume 5 (ear blisteringly loud :()
Quality 2 (poor, the metal mesh on one of them fell off after about a week, and then the speaker on that side got kind of bent in and the volume halved)
Hold/fit 2 (fall out often, not suitable for jogging/sports)

Sony Active MDR-AS20J Ear Clip Sports Headphones ~£12
now it’s been a little while since i used these headphones so forgive me if i’m a little less specific. These have got to be my second favourite since the Sennheiser MX55.
They disappeared a while back and I can’t seem to find them anymore 🙁 lol.
Comfort 4
Sound 4
Quality 5 (survived being chucked into my bag with various implements until they disappeared)
Volume 4 (not as good as the in ear ones obviously, but louder than the MX55’s)
Hold/Fit 4 (the stay on, but its a bit fiddly to get them on)

Sennheiser CXII300 In ear noise isolating ~£30
These were quite expensive for me, but sounded greate and lasted ages. The hold while Bocking wasn’t too bad (it helped taping the cable to my neck with a plaster to prevent tugging).
I killed them by accidentally snagging the cable on a street sign and turning round. The cable separated at the connector.
Comfort 3 (got a bit uncomfortable after an hour or so)
Sound 5
Quality 4 (good, rubbery cable didn’t seem to kink and was easily wrapped but the rubber cable ends on the buds slid down after a good few months of kicking around in the bag)
Volume 5
Fit/hold 4 (not best suited to sports, the cable always caught on my clothes and dragged them out of my ears. Better fit than the skull candy though.)

My recommendation? Get the Sennheiser MX55. Great hold and sound quality for an amazing price. I don’t miss the volume, my hearing seems to be improving now (i think a volume rating of 5 is excessive!!).

The in ear/noise isolating ones especially the sennheiser were pretty good, but i quite like being able to have some sound from the surroundings. Even though the hold was pretty impressive for something not secured to your ear, the cable always won and ended up yoinking them out of my ears.

Edit: added comment to Senheiser Mx 55 section.

Network Monitoring

I’ve been searching for some simple tools to monitor my internet connection for some time, and finally I’ve found a few tools that do the trick.

If you’re looking for a console application to give you a quick heads up on the transfer speeds across a network interface have a look for ifstatus (not to be confused with the ifplugd suite) .

Ifstatus

If you’re looking for something to log and display network statistics checkout vnStat

vnstat graphvnstat graph

Minor niggle: both these programs needed compiling and required additional dependencies which I recall were GD, for the graph creator of vnStat (vnstati) and curl for the console interface of ifstatus.

If you have any other suggestions, queries or points, please leave a comment!

Haymarket Metro Station, Newcastle

Fore note: Garreth has gone up to Newcastle to study Building Services (foundation) at Northumbria University.
This has to be the most random and unrelated note (i won’t call it a blog, it’s not worthy of that).

Tonight after chowing down on a awesome kofte kebab from Get Stuffed (Newcastle fast food 😉 ) and feeling much better from having some sugar in my veins I was in a chatty mood. Here is the information I gathered!

Guy with guitar, looks like a student, sitting on a chilly step eating a kebab:
Newcastle Student Union hold a Open Mic night every monday!
(Finally some real music!)
There’s a Jazz club that also hosts real music, there’s a guy who hands out leaflets for it during the day near the church.
He’s a fresher.

Builder on St Mary’s street, by the church:
Turns out tonight they are removing the cabins located literally right next to the church. They’ve just completed the new Haymarket Metro station after a 2 year build. Coincidentally, he mentioned off the cuff that they had to use 125ft drilled piles!
Phew! It’s coincidental cos that’s what I was studying today in my Building Construction lecture with Kevin Elliot.

So they drilled 120ft (presumably couldn’t use displacement piles cos it’d disrupt all the buildings nearby, and the underground!), put steel in and poured concrete.

Mr Builder said they had to be really careful with the positioning of the piles or they’d have gone bankrupt – after all the client is not going to be too happy if you drill into the tube you’re building a station for!

It’s strange how you can reinforce your learning with random late night chats with builders! I’d recommend anybody studying built environment courses give it a try 😉

Now about that darn assignment :'(

Btw I have some half decent posts in draft too (Web 3.0, firefox addons), if only I had the motivations to finish them!