Phone upgrade: Motorola G (4G)

I've had my iPhone for quite a few years now. It's an iPhone 3GS and for a long time I have not had a compelling reason to change it. But these days I find myself stuck on iOS 6 when lots of Apps now require iOS 7 or later. So I'm getting left out in the cold. It's time to do something about that.

But on the old iPhone I also can't do things like set up a personal wifi hotspot. I can do connection sharing over bluetooth or by a cable, but I find that type of connection is not well supported on non-Apple devices. So I can't use the internet access from my phone on my Andriod tablet (although it works fine with the iPad).

The old iPhone does seem slower than it used to, so getting a new phone with a faster processor would be good too. And it will also be nice to get a better camera. So I've decided to try out one of these phones: Motorola G (the 4G version).

I like the idea of the SD card slot for extra storage and for the price it seems a very good spec. It's a shame there is no way to connect an HDMI cable, but I can live without that. But I was finding it hard to justify the cost of another Apple phone, when I've been quite satisfied with the Android OS recently. I used to feel that the Apple phones were better quality (both in terms of hardware and software). But things have moved on.

After a few days of use, I am very impressed with the Moto G. The only problem I have found so far is with the Android KitKat OS itself. There is a serious bug with the stock e-mail App which has now gone unfixed for nearly a year. That's pretty bad. I'm surprised to see it classified as Priority: small when the effect is that e-mails are deleted from the server when you have told it not to.

So I cannot use the standard e-mail App, and at the moment I'll use the K-9 App instead. It's a shame, because in previous releases of Android the e-mail App was working fine. Even so, I am pretty happy with my choice of phone. I've even started reading some pages on Android development - although it was mainly out of idle curiosity. But you never know...

Drawing spheres with H2D2

Since I wrote this blog post, I have been looking for a better demo program to show what I can do with my H2D2 programming language. I needed something more interesting than "hello world" ... and which didn't involve drawing the Mandelbrot set.

I started trawling through the Rosetta Code website for inspiration and came across this sphere drawing program in C. I guess it's a simple ray tracing algorithm really. It seemed like a reasonable candidate.

So I set about porting it from C to H2D2, which was an interesting experience. Interesting because H2D2 is not very forgiving when you make mistakes - since I have not (yet) made the compiler error messages very user friendly. So it makes you reason things out very carefully in your head, rather than rely on the compiler to spot problems with your code.

I have managed to get it to work though, and the resulting H2D2 example program shows a few of the language features (like a function call and arrays for example). However, it also highlights a few things I should work on, like creating a syntactic shortcut for assigning values to an array. Anyway, I can now create output like this:

             !!...!!!***Bo               
         ..............!!**Boo           
      ..................!!**BBooe        
    .....................!!**BBooee      
   .......................!!**BBooee     
  ........................!!**BBoooee    
 .........................!!**BBoooeee   
!........................!!***BBoooeeee  
........................!!***BBooooeeee  
!......................!!***BBBoooeeeee  
!....................!!!***BBBoooeeeeeo  
*!.................!!!***BBBBoooeeeeeeo  
B*!!!...........!!!!****BBBooooeeeeeeoB  
 B***!!!!!!!!!!!*****BBBBoooooeeeeeeoo   
  oBB*************BBBBBoooooeeeeeeeoo    
   ooBBBBBBBBBBBBBBooooooeeeeeeeeooB     
    eoooooooooooooooooeeeeeeeeeooo*      
      eeeooooooooeeeeeeeeeeeeooB*        
         eeeeeeeeeeeeeeeeeoooB           
             oeeeeeeooooBB

But to show it in action, I made this recording, which shows it off in realtime in the browser:

Anyway, I am really pleased that it works so well. I can go back to fiddling around with the language now.

Hello World, H2D2 style

Now that my experimental programming language, H2D2, includes the all important server part, I thought that I'd better record an example of the traditional 'Hello World' program:

Although these programs are very trivial, it shows that I can now do H2D2 programming from my browser. It's the server part which compiles the source into bytecode and then executes the program in timeslices. So the actual code is running inside the server and we're just seeing the output in the browser (alongside the source code of course). Since I recorded this in a coffee shop before work this morning, the H2D2 server was running locally inside Xcode on my Mac, for convenience. But I would be able to do the same thing even if the server was running elsewhere, like on my TP-Link router.

Considering that the whole H2D2 language is written in C, I think that's pretty good going. It seems reasonably fast and I don't even think I have the compiler optimisations turned on. Obviously there is a little bit of JavaScript doing the HTTP posts between the browser and the server. But I really do need to write some better code examples, which should be things that don't involve the Mandelbrot set for a change...

UPDATE: one of the "better code examples" I mention above can now be seen here.

Linux Voice and Elementary OS

It’s been many years since I’ve regularly read a computer magazine. But I miss those days really, I’ve not got anything against reading computer magazines, but I’ve not seen anything in a long time that catches my interest. But it’s nice to read something and then say to yourself “umm, I’d like to try that out for myself”.

Well, I suppose I do casually read the MSDN Magazine in electronic format, but I’m doing that because it’s part of my work, not because I’m doing it for fun. And I do still read articles on Dr Dobbs.

Anyway, after seeing the Linux Voice magazine mentioned on the Raspberry Pi blog some time ago, I have been reading every issue. This is something that I choose to read for fun, and I continue to look forward to each issue coming out.

But reading this magazine has resulted in me trying out lots of different distros. I have seen that there is a lot more stuff out there that I haven’t tried yet. So my old laptop has taken a bit of a hammering because I keep flattening it and reinstalling something else.

But … for a while, this may have changed. Because I’ve tried Elementary OS. I am very impressed. For me, it hits the right balance between looking really nice, and not hogging all my CPU cycles to achieve it. I can still run it on slightly older hardware and it works fine.

After installing, and without very much hassle, I found myself watching BBC iPlayer in Chromium, listening to music in the Spotify Linux client and writing some notes in the ReText markdown editor. But I was also enjoying the experience. I spend all day switching Operating Systems (every day I use Mac OS, Linux, Windows, iOS and Andriod), but after a few hours on Elementary OS I was thinking to myself “yeah, I reckon I could use this all day”.

So Elementary OS is the first one that I don’t really want to uninstall. I’m comfortable with it. I hope that feeling lasts. I have an old Desktop PC sitting around, I may install it there too.

I love it when a plan comes together

So recently, several of the different things I have been messing about with have come together. This was always in the back of my mind, but I didn't really know how long it was going to take. Recently, I have been working on:

  • building my own webserver (dweb)
  • cross-compiling for Linux on a TP-Link router (with OpenWrt)
  • ...and my own experimental programming language (H2D2)

Now I have bean able to bring all that together, what it means is that I can run H2D2 programs on my little TP-Link router. At the moment, I'm doing it through jQuery Ajax calls. So the programs are sent to the router with an HTTP POST from an ajax request, the router runs the program remotely and then returns the output back to the browser. Nice.

Here is a screenshot showing it all in action:

Woo-hoo... it works! Oh, and apologies for the partial ASCII Mandelbrot, I really can’t help it. The next experiment will probably be to do what H2D2 was actually designed for, namely to run a program partially on the router and then finish off the same program instance on some other platform. Then, I should be able to bounce a single program between the router, a Raspberry Pi and a desktop, which will be a neat trick.

Music by numbers - more notes

I blogged before about building a Raspberry Pi music player by numbers thingy and I said that I’d mention some more details about the software used. I did write up the notes, but then forgot to post it on the blog, so here goes, better late than never…

I had already mentioned the USB Message Board linux driver and the MP3 player that I used. The USB Message Board also requires the libusb-1.0-dev package to be installed, like this:

sudo apt-get install libusb-1.0-0-dev

But before I got that far, I needed an OS … and I wanted a version that wouldn’t corrupt the filesystem on the SD card if I just switched the power off at the mains. I have ended up running something called IPE - Industrial Perennial Environment of which I’m using the R1 edition, which is based on Raspbian. It seems to work a treat: I don’t need to worry about clean shutdowns, the filesystem runs in read-only mode. The R2 version of IPE looks even better, but for the time being I’ve stuck with the Raspbian derived version which is more familiar to me.

It goes without saying, that the webserver I used to provide the web-based API was my own dweb lightweight webserver which seems to have done the job very well.

I also wanted the Raspberry Pi to offer its own WiFi hotspot, for which I followed these instructions. After that I also followed this advice and disabled ifplugd for the wireless lan.

So … putting those things together and with a simple C program, I have:

  • a version of Raspbian which can be powered off without a safe shutdown
  • a Raspberry Pi which operates a WiFi hotspot with a DHCP server
  • an MP3 player which shows the track number on an LED display
  • a web based user interface and API

Normally, I just use Safari on my iPhone to call up a song over WiFi, but I added a numeric keypad as a backup, in case of WiFi interference or other problems. I’m sure that I could really go to town and make a much more complicated wireless MP3 player out of this … but what I have just seems to work perfectly, so at the moment I’m leaving it well alone.

Taking notes in markdown syntax

Recently, I have taken to writing a lot of notes in markdown syntax. When doing this on Andriod, I have had a lot of success with Writeily. I recently used it to take notes for three days straight and it worked brilliantly! I have naturally used markdown-type syntax for many years, so it is no trouble for me to take notes in this way. I find that when using a tablet to take notes, it’s much easier to use this type of syntax rather than try to highlight bits of text with my finger and select formatting options. That’s just too fiddly, and I end up losing concentration.

I am planning on using Pandoc to convert the resulting text file into something else. So, if I wanted to convert my markdown notes (contained in a .txt file) into a word document, I would be using a command like this:

pandoc -f markdown_github test.txt -t docx -o test.docx

...which should leave me with a nicely formatted Word file. Doing that, I should be able to take notes without needing to go back over them and re-format them later. I also find that it's easier to remain consistent this way. All the headings look the same, etc. I reckon it’s a pretty cool way to take notes, and if you’re a programmer, and used to following a particular syntax, you won’t find it hard to do.

A pretty neat idea

I've bought myself a new watch, one of these Casio MP-PCGM1-6 ones:

I've decided that I'm one of those people who really does think that the digital watch is a pretty neat idea.

But you need to be careful. The first one I ordered was from one of the Amazon shops and when it arrived I was pretty sure it was a fake. It was very poor quality, the plastic was rubbish and the printing on the dial didn't look right. It just arrived in a jiffy bag with no other packaging. But I was able to get a refund. This time, I ordered from a jeweller, and there's no doubt this is the real deal. It also came in a proper Casio box. Don't settle for a poor quality digital watch...

Running dweb on OpenWrt

To take OpenWrt for a test drive, I have been messing about with one of these TP-Link WR740N routers. It gives me a small low-power Linux box, which I’m sure I will find many uses for. When you consider that this £30 router comes in a consumer style plastic case with a power supply and even an ethernet cable, you realise that it’s a pretty good deal. It can’t do all the things that a Raspberry Pi can do, but it still has potential. And I also found this link which shows I’m not the only one.

So after getting the cross compiler set up (which I did using a Debian machine running inside VirtualBox) and getting some simple C programs running (flashing the LEDs), I decided to try something a little more interesting.

Despite the fact that OpenWrt seems well catered for in the web server department (it can run uHTTPd which supports SSL and even embedded Lua scripts), I still wanted to try my own web server code, out of curiosity, and just because I can.

So I decided to cross compile my own web server, called dweb for OpenWrt and try it out. I’m pleased to say that it worked without any modification. The only thing that I needed to do was install the POSIX thread library onto the router, using this command:

opkg install libpthread

…and after doing that I could run dweb. My simple web based API example which uses jQuery ajax to post values worked perfectly.

So now I can write code in C and expose it as a web-based API from my router. The problem is, I don’t really know why I’d want to do that. But in any case I can. At the moment it’s a solution looking for a problem. But it’s been fun.

What I wanted to achieve with dweb was to write a small webserver in portable C code and without needing external dependencies. I suppose that using the POSIX thread library would be considered a dependency, but the dweb source code allows you to turn that off.

So hopefully, this means that dweb will run on one of these VoCore one inch Linux machines which would be pretty cool. I am thinking of what I could do with a tiny webserver running an API which exposes the GPIO pins over http. Perhaps I’ll build that home sensor network I’ve been wanting ;-)

OpenWrt Linux on a TP-Link WR740N router

Recently, I have been watching this crowdfunded coin-sized Linux machine with some interest. I also noticed that it runs OpenWrt... which is a version of Linux that's designed to run on routers. So I thought that it would be worth some further investigation. I tried to find the easiest way of running OpenWrt at home, and ended up paying £30 for one of these TP-Link TL-WR740N machines (I bought mine at my local branch of Maplin).

It’s not bad actually, for the money you get the power adaptor and even an ethernet cable included – so you're ready to go. This router will accept the OpenWrt firmware straight from its web interface, so you just fetch the correct bin file from here and upload it to the router in the normal way. Personally I’m using this firmware and my device is a v4.27.

After the firmware has flashed and the router has rebooted you can telnet in and access OpenWrt for the first time. It was very simple indeed. For detailed information look here. Basically I’ve followed the "OEM easy installation". It doesn’t get much easier.

Of course, I want to write C programs for it now, so I’ll be setting up a cross-compiler. I think I’m going to use this page as a guide because it looks like one of the best sets of instructions out there.

So maybe I’ll end up fiddling with one of those VoCore coin sized computers eventually... It looks very tempting.