The lost outpost

Entries tagged as ‘Coding’

Experiments with PHP and MQTT

February 20, 2009 · 5 Comments

Over the past few days I’ve been playing around with combining lightweight messaging and PHP. There are a couple of reasons for this, but the primary one is that I’d like to extend my prototype iPhone CurrentCost monitoring web application to display more up-to-date information about the state of my home energy usage. I’d planned to do this for a while, but recently Mark Taylor created his own version of the iPhone interface (PDF link) and he has got current readings on the front page. Clearly, I have to compete :-)

Actually, in my system, I’d like to do things a different way. The heart of my setup is a Really Small Message Broker. At the moment, data from the CurrentCost meter comes in over the USB connection and is then published in pieces, or on topics, to the RSMB (temperature and energy readings are separate). These published messages are then read by a script which is subscribing to the topics and squirrelling the historical data into an rrdtool database; and also being pushed up to our IBM broker “in the interweb cloud” via an MQTT broker bridge connection.

So in theory, having the up-to-date information in the web UI should be a simple case of grabbing the MQTT publications on each topic and displaying them. The way I’ve coded things (and would prefer to do things), this involves having the ability to subscribe to MQTT publications from PHP.

I’m not at the end of the road yet, but I do have a starting point.

howitworks.png

I’ve got a front-end test page which currently uses Prototype to send an Ajax request to a server-side PHP script (yes, I have had jQuery recommended to me, and I may well look into that instead of Prototype, but this works).

The server-side script uses the Simple Asynchronous Messaging PHP library. SAM is a wrapper which enables a variety of messaging transports to be supported in PHP, such as MQTT, WebSphere MQ or WebSphere Platform Messaging. Just one thing: I found that in order to get the most recent SAM release to work on Ubuntu on my MPC-L, I had to install IBM’s XMS client SupportPac (for some reason, it won’t build without it, even though it is “optional”) and I also had to delete a spurious empty line from the end of /usr/share/php/SAM/php_sam.php to prevent header issues. Other than that, it was all good.

The script is really simple and basically uses all of the defaults to create a connection to my local RSMB over MQTT. The advantage of this being server-side is that I don’t have to open my RSMB to the Internet, the PHP code can connect via localhost. Once that’s done, it creates a subscription on the topic I’ve asked for, and receives the first data that comes along, then echoes it back to the front-end. I could make it auto-updating with Ajax.PeriodicalUpdater too, but there’s no need to put a load on my server.

Wanna see a quick demo? ;-)

I’m quite pleased with the way this is working. There’s some more plumbing to do, and I’ll almost certainly extend the server-side piece to allow two-way communications (publish as well as subscribe) as well as finer-grained control over the options. As a proof-of-concept though, I think this is looking good.

Categories: 24924
Tagged: , , , , , , , , ,

TwtrCtr – Tracking Twitter followers with an iPhone

January 28, 2009 · 3 Comments

twtrctr logo I’ve already mentioned this on Twitter, but so far I haven’t had a chance to write about the culmination of my first “proper” efforts to create a mashup: TwtrCtr.

For those not obsessed with Twitter or their follower numbers, there’s an application you probably haven’t heard of called TwitterCounter. The site provides tools, graphs and APIs for charting the growth of a user’s Twitter followers. It’s interesting, and if you’re slightly obsessive about figures and have a belief that such things “matter”, then you might already spend time checking it and looking at the pretty graphs. It also provides an element of “prediction” based on historical growth trends, and does cool things like allowing users to compare themselves to others and watch the graphs intersect or overlap.

twittercounter website There’s just one issue – although it looks great on the desktop, the site isn’t laid out very well for mobile browsers like Mobile Safari on the iPhone. It also uses a Flash component to display the graph, and since there’s currently no Flash on the iPhone, you get a big blank box in the middle of the screen.

The nice part is that TwitterCounter has a simple REST API which enables a developer to get the raw data about a user’s follower numbers. If you use Twitter clients like Tweetdeck, then you’ll see this in action.

Based on my previous experience of using the iWebkit framework to build an iPhone-optimised web wrapper for the data from my Current Cost meter, I thought it might be interesting to play around with using iWebkit to display the TwitterCounter stats.

iWebkit is a simple HTML framework which provides a set of CSS classes to make your web pages look like native iPhone apps. There are other frameworks out there like iUI and webapp.net, but they depend a lot more on knowledge of AJAX and some more advanced / dynamic coding, whereas iWebkit is all about simplicity – if you know your HTML basics, it is pretty straightforward. As it happens, you can extend it very easily as well – in my case, I combined it with some PHP functions which call out to TwitterCounter and echo the numbers into a table on a web page.

Although I worked with PHP a lot a few years ago, I hadn’t really done much with the language recently. The first thing I did was to create a simple piece of code to call the TwitterCounter API and get back the data for a specific user; and then I displayed it in a web page. Once I’d done that, it was pretty easy to get the whole thing wrapped into two pages of iWebkit template code, and style it all appropriately.

twtrctr mark 1

Revision one of the interface and app ran off my home server, and didn’t look fantastic. My initial thought for a name was “TwitterCounter nano”, but I changed it after realising that it didn’t fit so well as a name on the iPhone home screen :-)

In the screenshot on the left, you’ll also see that the first form I came up with was far from “iPhone native-looking”… the current version of iWebkit didn’t have form CSS classes, so I had to tweak things a little. I also found it was worth digging into the Apple Web Development Guidelines for the iPhone, which gave some hints about how to make some iPhone-specific tweaks like turning off auto-capitalisation for the text entry box (since most usernames are all in lowercase), and how to add a text hint, for example.

twtrctr mark 2 So, the second iteration of the UI looks a lot nicer. It’s also possible to hit the bookmark button in Safari and add the app as a shortcut on the iPhone home screen… (see the icon at the top of the post)… if you do that, and launch TwtrCtr from there, it will act as a full-screen iPhone app with no Safari controls, giving a much more native experience. The user can then navigate by using the controls in the header bar rather than the forward and back buttons provided by the browser.

I added an FAQ page, too, so if you want to know more about the app you can check that out directly on the site. In these days of heightened concern about Twitter security I also thought it would be a good idea to add a note on the front screen to point out that it doesn’t ask for anything more than a username, and it doesn’t log that anywhere, it just passes it on to the TwitterCounter API.

twtrctr display OK, that was a rather long explanation of the evolution of the first page! The important part is actually how the data is displayed. Once you’ve entered a valid Twitter username and hit “Get User Stats”, you get a single-page representation  of the TwitterCounter data for the given user.

The top 2 or three rows are links which will open the user’s profile page, homepage/URL (if one is set… otherwise that row doesn’t display), or display a simple graph / chart which is generated by the Google Chart API. The latter is something high on my list of enhancements, because it looks a little dull at the moment; also, I’m generating the Google Charts URL myself rather than using one of the PHP wrappers to the API, which would probably be a lot simpler.

Don’t look too closely for the rough edges… right now, it doesn’t actually make any effort deal with cases where a user doesn’t exist, or TwitterCounter or Twitter is down…. I know about those small issues :-)

In a nutshell, then – that’s all it is. A mashup which allowed me to explore a bit more iPhone-specific web development, some PHP / REST / XML coding, and a bit of Google Charts stuff as well. I have to say that the TwitterCounter folks (Boris and Arjen in particular) have been brilliant and very helpful and supportive, despite their app having an issue with the Twitter API while I was in the middle of developing this mashup on top of their API! iWebkit is a lot of fun to play with, and very simple as well – I know the developers are working hard to add new features into that framework whilst keeping it simple and aiming it at “non-techies”.

Oh, and incidentally, although the stylesheets make it look like an iPhone app, it should work perfectly well in any desktop or mobile browser – it’s plain old HTML.

I’m not making any claims about how this might develop in the future, but I’ve got a couple of ideas for tweaks that I might make. In the meantime, if you’re an iPhone (or other mobile device) Twitter user, do take a look at http://andypiper.tv/twtrctr and see how it works for you. Let me know what you think, or any ideas for additions you might find useful! Feel free to follow me on Twitter and @ your suggestions and comments to me, too.

Update: TwtrCtr is now linked directly from the TwitterCounter home page! Follow the iPhone link in the page footer! :-)

Categories: 24924
Tagged: , , , , , , , , , , , , , ,

Zero

June 30, 2007 · 3 Comments

When I got back from the WebSphere Services Technical Conference in April, I posted about the level of interest in simplified development, Web Oriented Architecture and Web 2.0.

Yesterday, Project Zero emerged.

We’re talking REST, PHP, Groovy and mashups.

Come and take a look. For full details, read the FAQ and follow the blog. Then, download the code and join the community.

Categories: Uncategorized
Tagged: , , , ,

SLorpedo!

June 17, 2007 · 18 Comments

We just presented our team’s hack for HackDay in London…

An awesome team effort inspired and led by Paul Johnston and Nigel Crawley. A mixed reality naval game from the Supernova team.

Here’s the science part.

Camera rig The real world part(s) of the hack involved a DV cam feeding Nigel’s G4 iBook with a live feed of some pieces which represented two teams, “crabs” and “sharks” (cut from O’Reilly postcards). The camera rig – managed by Jon Hadley – was a highly technical setup involving gaffer tape and a borrowed tripod – thanks to Twitter! The iBook then used the TUIO protocol to update the coordinates of the game pieces to a web server.

The second RL part of the hack was my MacBook Pro rigged with Quicktime Broadcaster and Darwin Streaming Server, pointing at the game board. This provided a video feed that could be used within Second Life. This was technically challenging to set up due to issues connecting between the laptops on the BTOpenZone network… so someone donated us an Airport hub (again following a Twittered plea for help), and I shared my connection with Jim Purbrick who was then able to tunnel through to Second Life, as well as seeing my Quicktime stream. We experimented with a cheap USB webcam too, but the iSight just worked a lot better (positioning was “interesting” though!)

View from the blimpMeanwhile… in Second Life, the team of Jim Purbrick, Ben Hardill, Chris Mahoney and James Taylor built an amazing setup. We had a floating blimp (on Arcanum, the sim that Linden Lab had donated for the Hack Day event). The blimp contained a table which showed the live video feed of the game being played in real life. Below that, the sim was submerged. During the demo, Babbage Linden showed off the live feed, and then flew under the blimp. When he hit the floating buoy, a group of submarines were rezzed in that corresponded with the movement of the pieces in real life. Oh, and the subs were named after names found via the Yahoo! Answers API.

We didn’t quite have time to sort out the audio, but there were supposed to be some sonar noises as the subs were rezzed. Pretty easy to add, but we got moved around a couple of times prior to the demo, and had to disassemble our rig each time.

Someone managed to capture the blueprint for the hack on camera.

Oh, and as a complete aside – it is interesting to see the distribution of hardware and operating systems at the event. I’d say Macs dominate, Windows are probably second (I’ve only seen one running Vista but there may be more), and there are quite a few people running Linux too. Almost all of the demos and presentations seem to be run from Macs. W00t!

I had a spot on stage earlier in the afternoon as the “glamorous” helper for the MyBlogBunny hack, holding the Nabaztag – thanks Lance :-)

[ edit 19/06 - links and photos added, minor edits ]

[ edit 21/06 - added some more links to interesting Flickr photos ]

Technorati Tags: , , , , , , , , , ,

Categories: Uncategorized
Tagged: , , , ,

Automating WebSphere Message Broker deployment

June 8, 2007 · Leave a Comment

Back to a topic related to my day job (!).

During the past few years I’ve come across a number of instances where customers have wanted to script the build and deployment of WebSphere Message Broker solutions. I’ve actually spoken about this a few times at conferences (an example presentation is available on my Writings page). The most common approach that customers have adopted has been to use Ant to tie in with the rest of their application build processes.

In an earlier developerWorks article, I included an example plugin node that could invoke an Ant task. There should be a build.xml file included with the sample code for this article that could help you to get started. I’ve also helped customers to write their own automated build and deployment processes.

Now, a new developerWorks article from Zhongming Chen, Ida Leung and Dave Spriet covers the use of Ant to drive the mqsicreatebar command for scripting the creation of broker archives. It’s a great article and well worth a look.

This isn’t the end of the story. Often, the overall process will also include checking out of source control, apply version tags, and deploying the BAR file. However, this article introduces the topic and should be a good starting point. You could also use the Configuration Manager Proxy API to control other broker tasks, as Matt Lucas describes in another developerWorks article.

Incidentally, if you want to know more about Ant, I personally really like the book Java Development with Ant by Erik Hatcher and Steve Loughran.

Technorati tags: , , , , ,

Categories: Uncategorized
Tagged: , ,

Oh Plazes, where art thou…

June 5, 2007 · 3 Comments

I had an email this morning announcing that the new Plazes is online, so it looks like all of the features should now be public.

There are just a few things that still bother me – I think if the team could sort these out, they might get a bit more uptake:

  1. Some of us have been kept up-to-date via email. The Plazes blog has been very quiet on the subject of the whole upgrade. I’m grateful for the alpha/beta exposure, but it seems like more awareness could have been built up around the new version by more coordinated use of blogs, email and other media.
  2. The Plazer for Windows and Mac has been re-released, but the Mac one in particular has had some problems. It would be nice if these were open sourced, or a better way of reporting issues existed than the comments in the new Mac group.
  3. The API has changed. I’ve seen inconsistent messages on the blogs or via email that certain parts of the API have been / will be removed before certain dates. The WhereAmI XML-RPC PHP endpoint has certainly been removed, and as a result my little Applescript for ecto is not currently working. The success of Web 2.0 sites is usually a lot to do with their APIs and the ease of use… right now, Plazes could be opening this up a lot more and letting the community play with the new features programmatically. The upcoming Hack Day is a case in point – participants could be making use of APIs offered by Plazes if they were made available.
  4. [added in a later edit] They seem to have stripped out some of the privacy features. Before, I could choose which of my IM accounts or email addresses to reveal publically or to contacts… this option seems to have gone. An unwelcome regression in function.

I still think Plazes is a cool site, but there’s so much more they could be doing to build their own momentum.

Technorati tags: , , , , ,

Categories: Uncategorized
Tagged: , , , ,

WSTC – all Jazzed up

April 30, 2007 · Leave a Comment

For the final morning of the conference, I attended a talk on Jazz by Scott Rich. It was another talk with a live demo – very cool to see the technology actually running.

Jazz is an extensible and scalable collaboration platform for the development cycle. It has a client/server architecture and runs on either an open source stack of Tomcat + Derby + Jabber, or an IBM one (potentially others I suppose, but that’s sheer speculation).

Several announcements were made around the middle of last year, and the Jazz site is out there in the open. There was some information about it at the RSDC talks last year. You’ll find analysts talking about it already.

The demo was extremely neat. Again, this is building REST, RSS/Atom, a rich web UI (as well as the Eclipse one) into the platform. I can’t say too much at this stage, but it would be worth getting involved in the Jazz community site if you want to know more.

Do I sound excited about it? It looked great. I can’t wait to see this start to appear in the open.

Technorati Tags: , , , , , , ,

Categories: Uncategorized
Tagged: , , , , ,

WSTC – Rational Application Developer 7

April 26, 2007 · Leave a Comment

I didn’t get the chance to sit through this introductory talk in full, but I did jot a few notes down. I haven’t been able to use RAD v7 yet - these notes are probably not news to most people, but they were of interest to me.

Due to various improvements, RAD 7 has better size and performance characteristics than 6. It is based on Eclipse 3.2.1 running on JDK 5.

The Web Diagram view has been completely redesigned and enhanced.

Ajax is supported inasmuch as the JSF components have Ajax behaviours and do not force page reloads. Graphical portlet development is supported.

The XML Schema editor by default attempts to restrict choices to guide users towards best practices in creating schema definitions – the advanced view exposes all schema functions.

Categories: Uncategorized
Tagged: , , ,

Plazes: ecto Applescript, Dashboard widget

March 21, 2007 · 8 Comments

Regular readers will already know that I’m a big fan of Plazes. It is a service which, I think, deserves to have taken off more quickly.

The default Plazer application already integrates nicely with iChat, and will set my status to my current location. You can also get Applescripts that will enable other applications to do the same, for example Adium.

Last night, in a fit of interest, I hacked together my first ever Applescript. I recently read an article that described Applescript as “a hidden jewel in Apple’s crown”, and I have to say I was impressed. The blogging client I’m using, ecto, is scriptable – although I didn’t have anything to work from until I realised that the disk image had come with a bunch of example scripts, which I hastily installed for reference.

Making an XML-RPC call in Applescript is remarkably easy, and it was really simple to get hold of my current location – I used the Adium/Plazes script as an example, but the overall simplicity of the call really impressed me. After that, it was a straightforward matter of using an existing script that added text to the current draft to drop the location details into the post, and voila. The end of this post should demonstrate the capability.

I’ve uploaded the Applescript here.

  1. Open the script in a text editor.
  2. You will need to edit the script to put your Plazes username and password at the top. It will not work if you don’t do this.
  3. If you wish to change the text that the script adds to a post, alter the contents of the _text variable about three quarters of the way down (be careful though).
  4. Once you’ve made the changes, paste the script into the Script Editor and save it as Plazes.scpt, with a file format of script. The Script Editor should syntax highlight it all once it has been successfully saved as a script. Quit the Script Editor afterwards.
  5. Move the script to ~/Library/Application Support/ecto/Scripts.
  6. In ecto, choose Scripts->Plazes from the menu, and your location should appear in your current draft.

There’s one slightly frustrating feature of ecto – it apparently refuses to recognise the font-size style on the <p> tag and replaces it with lots of <span>s, and also replaces 10px with 10pt – not quite sure why that is yet.

Moving on from ecto, another interesting Plazes tool I’ve found is a Dashboard widget that displays a Google Map of your current location, and lets you find your contacts online. It is a bit rough around the edges, but I’ve been playing around with Apple’s new Dashcode tool and have tried making tweaks… I’ve dropped the author a line and hopefully he’ll want to resurrect it.

Posted whilst at White Leaf House [ plazes.com ]

Technorati Tags: , , , , , , , , , , ,

Categories: Uncategorized
Tagged: , , , ,

XSLT book, mark 2

January 11, 2007 · Leave a Comment

One of my minor claims to fame is that you can find my name in the acknowledgements of the first edition of Doug Tidwell’s book on XSLT, as published by O’Reilly.

I attended some of Doug’s excellent sessions at the WebSphere conference in Las Vegas waaaay back in 2001 (actually a number of months before I joined IBM). I subsequently emailed him a couple of times, and ended up being invited to be a technical reviewer of the manuscript. It’s a great reference book, and has some excellent examples. I’d also say that Doug’s writing style makes it very easy to follow.

Since I subscribe to Doug’s developerWorks blog, I noticed that a second edition is due out, now updated for XSLT 2.0 and XPath 2.0. You can pre-order it already (Amazon UK | Amazon US). I’m sure this is going to be a worthy follow-up. If you work with XML technologies, go put it on your wish list.

Disclaimer: I have nothing to do with the new edition. I wouldn’t claim to know much about XSLT 2.0. Learn from someone who does :-)

Categories: Uncategorized
Tagged: , ,

Second Life news updates

January 8, 2007 · Leave a Comment

Two noteworthy Second Life newsitems, today.

Firstly, IBM and Sears are partnering on a new build on the IBM island complex. The idea is to allow customers to explore the Sears product range in a more immersive environment than is currently possible with an online store. Mike Rowe gave an interview about the Sears build to 3pointD, and it is worth reading.

Secondly… a little snippet… the Second Life client has been released as an open source project! This is extremely cool. Hopefully it puts an end to the need to play around with libsecondlife – it will be interesting to see how that project goes forward now. Actually I’d only just posted about libSL to eightbar, when Roo posted the news about the full client – which kind of negates my post…

Lots of coverage, including Reuters actually referring readers to eightbar; and IBM’s Irving Wladawsky-Berger being quoted by Fortune.

Things I’d like to see:

I’m really looking forward to seeing how this all develops.

Technorati tags: , , , , , , ,

Categories: Uncategorized
Tagged: , , ,

Debugging a Windows dump file

January 8, 2007 · 3 Comments

It has been a while since I did any significant development for the Windows platform, either using the Win32 API or any of the tools. Once upon a time (about six years ago) I used to port utilities from HP-UX to Windows, and write Windows installers. These days, whenever I have to look at any Windows code, I tend to gingerly prod at it using Bloodshed Dev C++, or the SharpDevelop IDE.

Recently I was trying to work out why the Mugshot client was crashing, and needed to look at the debugging tools available. Disclaimer – I’m no expert here, this post just represents “some stuff I’ve learned lately”.

When an application crashes on Windows XP, sometimes you get an error along the lines of “there was a problem with xxx and it needs to close”. Something like this:

If you click for more information, you can then get more technical details:

Unfortunately, you can’t cut-and-paste the contents of the details window into a text file.

When the error dialog is on the screen – before you close it – if you look in C:\Documents and Settings\<your user>\Local Settings\Temp you should find two files – a xxxx_appcompat.txt file (which will be named in the Error Report Contents window… 9982_appcompat.txt in the example above), and a yyyyyyy.dmp file. I don’t know what the pattern is for naming these – the numbers seem to differ, and I can’t see that they have any relation to e.g. the PID, so I assume they are random. The two files seem to get deleted when you close the dialog, so if you want to try to get more debug information, copy and paste them somewhere else.

The appcompat file contains some information about the libraries that were loaded to support the running process. The .dmp file seems to be similar to a core file on UNIX – a dump of the process.

There are several ways to look at the dump file:

  • dumpchk: this is available by default in Windows XP. If you run dumpchk <dmp-file>, it will print out some more information about the loaded modules and threads. Basic, but may be useful.
  • windbg: this is available as part of the free Debugging Tools for Windows package from Microsoft. It is a graphical tool that you can use to open the .dmp file. If there is any useful information in the dump, you can enter .excr in the debugger and it will take you to the exception; !analyze -show will show you the error; and lm will list out the loaded modules.
  • kd: this is the command-line equivalent of windbg. Run it with -z <dmp-file> to get into the debugger.

That’s a really brief summary. Check out the MS Knowledge Base article on debugging for more details.

Categories: Uncategorized
Tagged: