May
20
Widget, it’s got a widget…
13 years ago, mid-May | Leave a Comment
John Smiths have a lot to answer for there I can tell you.
It’s been a busy few weeks at work while we launch our revamped online shop and how did I go about relaxing? I did more development work at home. Since we’ve moved into our house I haven’t really had a lot of time to do much development, more tiling grouting and renovating than anything else. This last week though, as we started to get on top of things, I took some time to put together a widget for Android. I’ve been collecting, storing and graphing data from various sensors around the house for some time now and while the graphs are pretty they aren’t really a quick or efficient way of reading the status at a glance.
Step forward the widget. Each widget requests XML data from the server and presents it on the widget, this allows an infinite number of widget variations since the only change is the data received. In other words, if it’s in the database it can be served. The widget itself has a number of coloured backgrounds which the server data can trigger if and it’s also capable of playing an alarm sound if required. I still need to fix this because the alarm sound triggers on each update and there’s currently no way to tell the widget to be quiet.
Update: Fixed this, tapping the widget will silence it until the next alarm trigger ie once the state returns to normal and then alarms once again.
Incidentally, since I only have a self signed certificate on my server but still wanted encrypted access I had to extend the DefaultHttpClient. By default Android will just refuse to connect to a server if the certificate isn’t signed by one of the ‘trusted’ certificate authorities – it wont tell you that it refused, it’ll just silently fail. You’d only ever really know if you’d connected to your device via adb and done a logcat. You can get round this by adding a keystore to your application, which is good enough for testing or personal applications.
If you want to do this you need to make sure you have the Bouncy Castle cryptography jar in your CLASSPATH. The first thing you’ll need is a copy of the certificate which I hope you’ve generated and installed on your server. If you need to get a remote server certificate you can use the following command (all one line).
echo | openssl s_client -connect your.server.goes.here:443 2>&1 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > mycert.pem |
Replace the “your.server.goes.here” with your server, obviously. Once you’ve done that export the CLASSPATH to the Bouncy Castle jar you downloaded replacing the path I’ve used with the location you downloaded it to:
export CLASSPATH=bcprov-jdk16-146.jar |
You can now use the following script, note that the keystore name is appkeystore.bks as on line 3
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | #!/bin/bash CERTSTORE=appkeystore.bks if [ -a $CERTSTORE ]; then rm $CERTSTORE || exit 1 fi keytool \ -import \ -v \ -trustcacerts \ -alias 0 \ -file <(openssl x509 -in mycert.pem) \ -keystore $CERTSTORE \ -storetype BKS \ -provider org.bouncycastle.jce.provider.BouncyCastleProvider \ -providerpath /usr/share/java/bcprov.jar \ -storepass MyPaSsWoRd |
Replacing the MyPaSsWoRd on line 19 with a password of your choosing, you’ll need it later too. If you run the script you should get some output like this, obviously with your server information – remember to answer yes to the “Trust this certificate” prompt.
Owner: EMAILADDRESS=info@ automated.it, CN=www.automated.it, OU=Tech, O=Automated IT, L=Eye, ST=Suffolk, C=GB Issuer: EMAILADDRESS=info@ automated.it, CN=www.automated.it, OU=Tech, O=Automated IT, L=Eye, ST=Suffolk, C=GB Serial number: 4dce9c74 Valid from: Sat May 14 16:15:00 BST 2011 until: Sun May 13 16:15:00 BST 2012 Certificate fingerprints: MD5: 32:0F:33:0C:42:8D:FF:78:90:46:31:7A:4F:D3:33:23 SHA1: BD:A8:B8:21:B1:48:C3:53:BB:01:22:65:9E:00:6E:14:7B:DE:4E:F6 Signature algorithm name: SHA1withRSA Version: 1 Trust this certificate? [no]:yes Certificate was added to keystore [Storing appkeystore.bks] |
Create a directory called “raw” in your project’s ‘res‘ folder and copy the appkeystore.bks file to it.
In your Android application or widget you can now create a new class for the following code which will extend the original DefaultHttpClient class. You’ll want to change the package name on line 1 to match your application.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | package your.package.name.here import android.content.Context; import org.apache.http.conn.ClientConnectionManager; import org.apache.http.conn.scheme.PlainSocketFactory; import org.apache.http.conn.scheme.Scheme; import org.apache.http.conn.scheme.SchemeRegistry; import org.apache.http.conn.ssl.SSLSocketFactory; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.impl.conn.SingleClientConnManager; import java.io.InputStream; import java.security.KeyStore; public class myHttpClient extends DefaultHttpClient { final Context context; public String UserAgent="Android dataWidget (ScaredyCat 0014150511-0.1b) [http://blog.automated.it]"; public myHttpClient(Context context) { this.context = context; } @Override protected ClientConnectionManager createClientConnectionManager() { SchemeRegistry registry = new SchemeRegistry(); registry.register( new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); registry.register(new Scheme("https", newSslSocketFactory(), 443)); return new SingleClientConnManager(getParams(), registry); } private SSLSocketFactory newSslSocketFactory() { try { KeyStore trusted = KeyStore.getInstance("BKS"); InputStream in = context.getResources().openRawResource(R.raw.appkeystore); try { trusted.load(in, "MyPaSsWoRd".toCharArray()); } finally { in.close(); } return new SSLSocketFactory(trusted); } catch (Exception e) { throw new AssertionError(e); } } } |
Note that the password used in the script earlier should match the one on line 37– use your own different password in production for security purposes. You can now use the class as required in your application, for example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | myHttpClient httpclient = new myHttpClient(context); httpclient.getCredentialsProvider().setCredentials(new AuthScope(host, port), new UsernamePasswordCredentials(username,password)); BasicHttpContext localcontext = new BasicHttpContext(); BasicScheme basicAuth = new BasicScheme(); localcontext.setAttribute("preemptive-auth", basicAuth); httpclient.addRequestInterceptor(preemptiveAuth, 0); HttpHost targetHost = new HttpHost(host, port, scheme); HttpGet httpget = new HttpGet(url); httpget.setHeader("User-Agent", httpclient.UserAgent ); |
Once I’d got the SSL connection I could get the application to download a list of sensors from the database, this only happens the first time the first widget is added to the home screen. I need to sort a way of allowing the user to delete the list if more sensors are added. At the moment clearing the data for the widget application works but it erases the widget settings too.
When I’m at home I want to connect to a local server for the information for the widgets and when I’m out and about (using a 3G connection) I want to connect to an external server. I implemented the ability to automatically switch when my phone connected to my WiFi access point. One final thing I did was to add the ability to long press on a text field and then select ‘Save as default‘ allowing things like servers, Wifi MAC address, username and password to be saved as the defaults for all widgets.
Tagged with: 1-Wire • android • currentcost • opensource • software
May 20, 2011 21:10
Jan
18
LinkUSB(i) and 1-Wire setup
13 years ago, mid-January | 2 Comments
I’ve just configured my monitoring machine to use a LinkUSBi 1-Wire interface and it’s a rather simple process. First of all we’ll setup One Wire File System, or OWFS for short, then we’ll add some udev rules and finally plug in a device and get some readings. Since we need to build OWFS we’re going to need a new libraries and files installed, I’m making the assumption that you already have automake, autoconf, autotools-dev, gcc, g++ installed so you can go ahead and install the libraries we need.
apt-get install libtool libusb-dev fuse-utils libfuse-dev swig python2.6-dev tcl8.4-dev php5-dev
You don’t actually have to have Python, Tcl or php5 installed if you don’t want them they add to the interfaces you can use with OWFS – unless you specifically don’t want them you may as well include them. Once the installs above have completed you’ll need to get a copy of OWFS – be sure to download the latest version of it.
Update : I’ve rolled back to using 2.8p4 since 2.8p5 seems to have some problems with owserver (owfs still works fine).
Once you’ve downloaded you’ll see the file is called something like owfs-2.8p5.tar.gz – this file name is made up of owfs-[version of owfs].tar.gz In my case I have version 2.8p5. Your version may differ, don’t worry about that (unless it’s older!). Now extract the tarball with
tar -zxvf owfs-2.8p5.tar.gz
replacing the file name with whichever version you downloaded. This will extract a lot of files and place them in a directory with the same name as the file you downloaded, minus the ‘.tar.gz’. Move to that directory with
cd owfs-2.8p5
now we need to run the configure and make scripts. First configure, if this fails make sure you have all the dependencies required.
./configure
this will spit out reams of text which really only matters if something goes wrong. The last few lines should be something like this
Current configuration:
Deployment location: /opt/owfs
Compile-time options:
Caching is enabled
USB is enabled
I2C is enabled
HA7Net is enabled
W1 is enabled
Multithreading is enabled
Parallel port DS1410E is enabled
TAI8570 barometer is enabled
Thermocouple is enabled
Zeroconf/Bonjour is enabled
Debug-output is enabled
Profiling is DISABLED
Tracing memory allocation is DISABLED
1wire bus traffic reports is DISABLED
Module configuration:
owlib is enabled
owshell is enabled
owfs is enabled
owhttpd is enabled
owftpd is enabled
owserver is enabled
ownet is enabled
ownetlib is enabled
owtap is enabled
owmon is enabled
owcapi is enabled
swig is enabled
owperl is enabled
owphp is enabled
owpython is DISABLED
owtcl is enabled
Now we build OWFS using make
make
After some churning, spewing output, cpu usage and warning messages (ignore them), which may all take 10 minutes or more depending on your cpu and memory, you should get your prompt back. Finally install owfs – do this as root.
make install
Since we need to mount the OWFS somewhere we create a directory
mkdir /var/lib/1wire
Ok, so now we come to the hardware side of things – I got my LinkUSBi from HomeChip – the ‘i’ variant has it’s own identity which may or may not be useful to you. If I’m honest I accidentally picked the ‘i’ version and could have easily saved 80 pence and gone for the non-‘i’ version without trouble – Quick Note, as I write this Quinten has had some issues that need investigation, he has the non-‘i’ variant – for now I’d stick with the ‘i’ variant that we know works. I’ll update once I get more information about the issue. Turns out that version 2.8p4 of OWFS worked with the LinkUSB for Quinten. The LinkUSB or LinkUSBi is the interface to 1-Wire devices, so now’s the time to plug it in. Be aware that if you have other FTDI devices you might want to set up some udev rules. This is what I have in a file called /etc/udev/rules.d/60-usb-serial.rules
# /etc/udev/rules.d/60-usb-serial.rules
# Determine XBEE, Current Cost and 1wire USB ports
KERNEL=="ttyUSB*", \
ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", ATTRS{serial}=="A600eD0C", \
SYMLINK+="1wire"
KERNEL=="ttyUSB*", \
ATTRS{idVendor}=="067b", ATTRS{idProduct}=="2303", \
SYMLINK+="currentcost"
KERNEL=="ttyUSB*", \
ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", \
SYMLINK+="xbee"
Since I have 3 USB serial devices, a currentcost unit, some Xbee based wireless 1-wire devices I made and the LinkUSBi, two of which are FTDI I need to identify each so use the ATTRS{serial} to uniquely identify the LinkUSBi via its serial number. You can glean the serial number by using
lsusb -vv
and look at the output for the serial number of device you’re interested it. Once our LinkUSBi is connected and detected we can mount OWFS with
/opt/owfs/bin/owfs -d /dev/1wire -m /var/lib/1wire
Note that I use -d/dev/1wire because my udev rules create a symlink. If you don’t create the symlink then your device will be something like /dev/ttyUSBx – where x = a number. Now we can look at any attached devices with
# ls /var/lib/1wire/
01.BA0E0E140000 28.1842A1020000 alarm bus.0 settings simultaneous statistics structure system uncached
The 01.XXXXXX device is the LinkUSBi and the 20.XXXXX device is a DS18S20 temperature sensor. To read the output of the temperature sensor we simply do
cat /var/lib/1wire/28.1842A1020000/temperature
16.0625
As you can see the temperature is a rather chilly 16.0625 degrees Celsius. Stuart Poulton has some 1-Wire kits available to buy for creating some domestic environment friendly temperature sensors and Quinten has some good pictures of them. Kevin has also got some newer pictures up – thanks for the headsup Kevin.
Tagged with: 1-Wire • linux • opensource
January 18, 2011 20:47
Oct
20
I am an IAMS cat
14 years ago, mid-October | 1 Comment
After an eternity of waiting Current Cost have finally made their IAMS available to buy. One might have expected a fanfare, we’ve been waiting for these for over a year now, but there was nothing, no blog post, no tweet, nada. Thankfully Kevin Turner (@netcompsys) spotted them for sale. For those not familiar with the IAMS (Individual Appliance Monitors) when used in conjunction with a Current Cost monitor (compatible with Trec, Envi, EnviR ,EnviRW) an IAM allows you to measure the electricity usage for an appliance. Multiple IAMS can be used with a single monitor to give you an overview of your total usage.
As you can see from the graphs at the bottom of this post there’s clearly something not quite right with my fridge-freezer. Every hour for half an hour it uses 400 Watts. Lets do a couple of calculations and find out what this really means in electricity usage and how much money I’m frittering away.
400 / 2 == 200 (Watts per hour) - half 24 * 0.2 == 4.8 (kWh) 4.8 * 365.25 == 1753 (kWh per year)
You read that right. It’s using 4.8kWh a day! Most modern fridge freezers use around 300kWh a year, depending on their size, and I’m using nearly six (6) times that. Let’s say I’m paying 12.5 pence per kWh. In one year my current fridge-freezer is costing me £219.13 versus £39.50 if I were to buy a new one – that’s £179.63 difference. If I pick a new fridge-freezer that uses less than 300kWh a year the saving increases. I could almost buy a new fridge freezer each year with the money I’m wasting!
As you can see, being able to measure what’s going on by using the IAMS has highlighted that I really need to replace my existing fridge freezer with something much more efficient.
Taking another look at the graph you can see one other area that needs to be looked at. Those computers are eating a lot of electricity. Only this morning did I get round to plugging my laptop into an IAM to measure it’s power use. 45W .. all day .. every day.. Let’s just say that it’s prime for replacement but also that it does now get powered off when it’s not being used.
So, get measuring and get saving!
Tagged with: currentcost • electricity • iams
October 20, 2010 13:13
Oct
2
LG TV Serial Control
14 years ago, at the start of October | 1 Comment
Finally, upgraded the TV after living with a 28″ Sony CRT for 14 years. If I’m honest I didn’t really spend much time thinking about which TV to pick, I went for the LG32LD350. So far the TV has worked perfectly and has the added bonus of a serial port. LG don’t hide what this port is for, in fact the protocol and port settings are in the user manual. This is a real breath of fresh air. Look at Sony with their Control-S / Control-L protocols that they didn’t really want you to use. So that’s put LG in my good books and I hope they continue to supply this information. I was also intrigued to get copies of both the GPL and LGPL licences with the documentation. Another project to take a look at.. but later.
Straight away I decided to get working on some serial port control interface. As I said the documentation is there but control needed to be very simple. Luckily I’d already got a SheevaPlug for my birthday in February, so I was just a case of connecting this to the TV with a USB to RS232 device and a Null modem adapter or and serial cable. The USB Serial port uses the PL2303 so is detected without issue. The serial port settings are nothing special, standard console settings
Baud rate : 9600 bps Data length : 8 bits Parity : None Stop bit : 1 bit
I installed apache2 and php on the SheevaPlug and set about building a test class to control it. It works, although it needs some tidying up. If you want to try it out you can download it. It makes use of the PHP serial class, which I’ve included in the tarball.
LGTV.php - Main class control.php - Example script channels.csv - Channel list data.csv - Command list
Configuration and setup is simple. After including the class we create an instance
include('LGTV.php'); $tv = new LGTV; |
There are a couple of variables that we can set, first of all we set the setId. This should match the id of your TV set, configured from its “Options” menu. If you use a value of 0x00 then all TV sets connected would respond to all the commands issued. I guess this could be useful if you had a big wall of screens or were using them as in store displays or something.
$tv->setId=sprintf("%02x",1); |
The default serial port is set as /dev/ttyUSB0 but you can change this using the tty variable.
$tv->tty = '/dev/ttyS0'; |
Next we need actually try and connect to the TV. If all is well the result of the serialInit command will be true.
$stat = $tv->serialInit(); |
You can now send commands and query the TV set. By default the variable confirm is true. This means that after you send a command and that command is executed, the class will also query the TV for its current state of that command. In other words if your TV has a current volume of 10 and you request a volume of 9 the command will execute and then will return the current volume. In this example it should be 9. This allows you to verify that a command has taken place, although it does mean that two commands are sent to the TV, not just one. You can disable this by using
$tv->confirm=false; |
You should remember to end your script by closing the serial port
$tv->serialExit(); |
Take a look at control.php to see some basic example code. Please note that this is a preliminary release which I’ll keep updating.
October 2, 2010 22:12
Nov
25
Tivo Return to UK Via Virgin Media
15 years ago, at the end of November | Leave a Comment
This would be so awesome…. if I could get Virgin connectivity. This bit saddens me though, unless Virgin start releasing set top boxes for the rest of us.
“Virgin Media will become the exclusive distributor of TiVo services and technology in the United Kingdom. “
The full announcement is here
Virgin Media Selects TiVo For Next Generation TV Platform
PRNewswire
ALVISO, Calif., and LONDON
(NASDAQ-NMS:TIVO)
ALVISO, Calif., and LONDON, Nov. 24 /PRNewswire-FirstCall/ -- TiVo Inc. (NASDAQ: TIVO), a leader in the creation of television services and advertising solutions for digital video recorders (DVRs), and Virgin Media Inc. (NASDAQ: VMED) (LSE: VMED), the UK's leading entertainment and communications company, today announced they have entered into a strategic partnership under which TiVo will develop Virgin Media's next generation TV platform. Under the mutually exclusive agreement, TiVo will develop a converged television and broadband interactive interface to power Virgin Media's next generation, high definition set top boxes. The terms of the deal are not disclosed.
TiVo will become the exclusive provider of middleware and user interface software for Virgin Media's next generation set top boxes. Virgin Media will become the exclusive distributor of TiVo services and technology in the United Kingdom.
Neil Berkett, CEO of Virgin Media said, "TiVo's proven track record of innovation, strength of its patented technology and experience in developing best in class user environments, make it an ideal strategic partner for Virgin Media as we move aggressively to bring our next generation TV service to market. The superiority of our fibre optic network combined with TiVo's capabilities, will allow us to offer consumers the most significantly advanced and compelling TV service available in the UK, and we believe will do to the TV market what Virgin Media has done to the high speed broadband market."
The next generation platform will offer a superior television viewing experience which will allow Virgin Media customers to search and discover content through major advances in video-on-demand integration and broadband video delivery creating the ultimate one-stop-shop for in-home entertainment.
"This deal underscores TiVo's commitment to expanding its global footprint through strategic alliances with leading international media companies to help them deliver the best in-home entertainment experience for consumers," said Tom Rogers, president and CEO of TiVo Inc. "We are very excited about this new distribution relationship with the UK's most advanced pay television provider and are particularly proud to have been selected as Virgin Media's core software partner for its next generation DVR-enabled set top boxes and its next generation non-DVR set top boxes. Virgin Media is a true leader in the world of entertainment and their enthusiasm for building the next generation of pay television is an excellent opportunity to put all of TiVo's innovation to work in a product distributed by a world class partner. We believe this international deal affords us a significant subscriber growth opportunity."
Virgin Media currently anticipates its first TiVo co-branded product in 2010.
About TiVo Inc.
Founded in 1997, TiVo Inc. (NASDAQ: TIVO) developed the first commercially available digital video recorder (DVR). TiVo offers the TiVo service and TiVo DVRs directly to consumers online at www.tivo.com and through third-party retailers. TiVo also distributes its technology and services through solutions tailored for cable, satellite, and broadcasting companies. Since its founding, TiVo has evolved into the ultimate single solution media center by combining its patented DVR technologies and universal cable box capabilities with the ability to aggregate, search, and deliver millions of pieces of broadband, cable, and broadcast content directly to the television. An economical, one-stop-shop for in-home entertainment, TiVo's intuitive functionality and ease of use puts viewers in control by enabling them to effortlessly navigate the best digital entertainment content available through one box, with one remote, and one user interface, delivering the most dynamic user experience on the market today. TiVo also continues to weave itself into the fabric of the media industry by providing interactive advertising solutions and audience research and measurement ratings services to the television industry. www.tivo.com
TiVo, 'TiVo, TV your way.', Season Pass, WishList, TiVoToGo, Stop||Watch, Power||Watch, and the TiVo Logo are trademarks or registered trademarks of TiVo Inc. or its subsidiaries worldwide. © 2009 TiVo Inc. All rights reserved. All other trademarks are the property of their respective owners.
About Virgin Media
With almost 10 million customers, Virgin Media is the UK's first quad-play provider of broadband, TV, phone and mobile.
The company is one of the largest residential broadband providers in the UK, using a unique fibre optic cable network to deliver next generation ultrafast internet access of up to 50Mb to just over half of all homes. Combined with a high speed ADSL service and mobile broadband products, Virgin Media is able to offer broadband internet access to virtually the entire country.
Virgin Media has the UK's most advanced TV on demand service and is the only TV platform to carry BBC iPlayer. It is the second largest provider of pay TV, was the first to launch a high definition TV service and offers a high-specification, HD-ready V+ personal video recorder.
The company operates the most popular virtual mobile network in the UK which, when launched, was the world's first such mobile phone service. It is also one of the largest fixed-line home phone providers in the country.
Virgin Media also owns Virgin Media Television (VMtv) which runs seven entertainment channels, including Virgin1, LIVING, Bravo and Challenge. VMtv is a 50 per cent joint partner with BBC Worldwide in UKTV, which consists of ten channels including Dave, G.O.L.D., Watch and Alibi.
With operations based entirely in the UK, Virgin Media Inc. is listed on the NASDAQ Stock Market (VMED) and the London Stock Exchange (VMED).
For more information, go to www.virginmedia.com
Forward-Looking Statements
This release contains forward-looking statements within the meaning of the Private Securities Litigation Reform Act of 1995. These statements relate to, among other things, the future availability and timing and the expected features and functionality of the TiVo software, technology, and service to be deployed by Virgin Media to its customers and expected future TiVo subscriber growth from Virgin Media. Forward-looking statements generally can be identified by the use of forward- looking terminology such as, "believe," "expect," "may," "will," "intend," "estimate," "continue," or similar expressions or the negative of those terms or expressions. Such statements involve risks and uncertainties, which could cause actual results to vary materially from those expressed in or indicated by the forward-looking statements. Factors that may cause actual results to differ materially include delays in development, competitive service offerings and lack of market acceptance, as well as the other potential factors described under "Risk Factors" in each company's public reports filed with the Securities and Exchange Commission. Each company cautions you not to place undue reliance on forward-looking statements, which reflect an analysis only and speak only as of the date hereof. Each company disclaims any obligation to update these forward-looking statements.
SOURCE: TiVo Inc.
Web site: http://www.tivo.com/
November 25, 2009 8:06
keep looking »Current Electricity Use (15min)
iPhone/Webkit RSS Reader
Links
- automated home
- Automated It Technology News
- awooga!!!
- LinITX
- My Acer page
- My Asterisk pages
- My Work in progress (old)
- Noble Race Car
- openmoko / neo 1973 wiki
- planet openmoko
- Spadgecock Cumpants