Wednesday, 16 November 2011

Breaking out of a Frozen SSH Terminal Session

For a long time I have found that if the internet connection is broken during a ssh terminal session that the terminal hangs and the keyboard is un-responsive - CTRL-C, CTRL-D etc. do not do anything.  I have always just cursed and closed the terminal window.

I just found that ~. will break out of the frozen session, giving you access back to the terminal.   ~? gives a list of other escape commands, but I am not sure what I would use those for.

Tuesday, 8 November 2011

Using Android Phone as a Modem

For quite a while I had been able to use my Samsung Galaxy Apollo phone as a modem - I just plugged it into my work laptop (running Windows XP) and it appeared as a modem, which I could use to connect to the internet nicely.

Then I tried (and failed) to update my phone using Samsung Kies and it stopped working.   I remembered as part of trying to get Kies to work I found an obscure code to type on the keypad to switch the phone between 'PDA' mode and 'Modem' mode.   I have just managed to switch it back to modem mode, and this has got my modem working again!

To do this I had to type *#7284# on the phone dialer keypad.  This brought up a menu where I selected the USB option to be 'Modem'

Now plugging it into my computer shows it up as a Samsung Mobile Modem.   I have the phone number set to *99***1#, which seems to work ok.  

I disabled the internal modem in the laptop because sometimes windows tried to dial that one instead, which is not connected to anything.

Sunday, 6 November 2011

Samsung Colour Laser Printer and Ubuntu Linux

Note:  You might find a more recent post more useful.

I have got sufficiently sick of my Epson inkjet printer suffering from clogged print heads, and noticed how cheap colour laser printers have become, so decided to give one a try.

I settled for a Samsung CLP-325W (w=wireless) colour laser printer.   The reason for this is that Samsung provide linux drivers for it, and I had an old Samsung laser printer a few years ago that worked nicely with linux.

To start with, the CD that came with the printer would not mount on my daughter's Ubuntu 11.04 machine - no idea why, so we downloaded the Samsung unified driver for linux from the Samsung UK support web site.

We installed the driver by running install.sh as root, plugged in the printer and it detected ok and seems to work.  We had to select the "Samsung CLP-300 Series (SPL-C)" driver, because the recommended "CLP-325 foomatic...." one only printed black and white.

So far, so good!

The fun came when I tried to set up wireless printing so I could print to it from my laptop without my daughter's computer being switched on.   The first attempt was to repeat what I had done for the other computer, and install the Samsung unified driver on my laptop.  Unfortunately it refused to detect the printer, even when it was plugged into the USB port on the laptop.   I never found out why and tried a different approach.

I plugged the printer into my ethernet network and re-started it.  I found out that to print the diagnostics you hold the 'cancel' button (with the triangle symbol on it) for a few seconds.  This printed  out a network diagnostic page that said the network type was 'dhcp' and the ip address was 192.0.0.192.   This is odd because my router, which would act as dhcp server should give out addresses 192.168.1.*, so I assumed that it was lying about using dhcp and had a static default address.
Re-configured laptop to use the 192.0.0.* subnet and tried looking for the printer - tried a web browser, ping and nmap, and no sign of it.

Had a look at my router's dhcp list, and realised that the printer had been assigned an ip address by the router, which was not the one on the network diagnostics!!!!!
Re-printed the network diagnostics and got the correct ip address - don't know what happened there.

Pointed a web browser at the printer's IP address and got a nice status web page, with a 'login' option at the top right hand corner of the screen (once I had scrolled across because I couldn't see it on my laptop screen for some reason....).   Had to search on the internet for the default login credentials - found out that it is user name -  "admin", password - "sec00000".

Once logged in, I could set up the network to use a static IP address (so I always know where it is, and connect it to my wireless network).

Disconnected the lan cable from the printer, and sure enough, I can see the printer from my laptop.  Used the Samsung printer configuration tool to set it up as a network printer on the laptop and....it works!!!

phew!

Tuesday, 11 October 2011

CodeIgniter / Bonfire

I have been progressing an automated way of generating maps from openstreetmap data, allowing layers to be selected, including contours and hill shading etc. (https://github.com/jones139/disrend).

I want a web front end to allow people to generate maps using this renderer.   When I did this for my townguide program I just built a very simple php based web interface.
Ideally I would like things like user authentication though, which would mean writing a lot of code to go with it.
The CodeIgniter framework goes some way to this by providing an interface to sessions etc, but there is still quite a bit of boilerplate code to write to produce the database interface.
The CodeIgniter / Bonfire application seems to solve this by providing:

  1. Roles based authentication.
  2. Modular structure (this was an issue I had with codeigniter - you ended up with code scattered in different places).
  3. A really neat module builder function that produces a basic module with database interface for you to build on.
I am just trying to get the hang of using bonfire now - I have had a few issues with installing modules based on the module builder code - will write up how to do this once I have it working...

Friday, 22 July 2011

Building Debian Packages

I worked out how to make simple debian packages by hand as described in a previous post.
Trying to build other software into packages is still rather difficult...
I found a really good, simple tutorial on how to use the debian tools to do this more easily at:
http://www.debian.org/doc/packaging-manuals/packaging-tutorial/packaging-tutorial.pdf.

Friday, 17 June 2011

Ubuntu packages and repositories

Creating Ubuntu (debian) packages always seems a bit fiddly....At the moment I can do it, so thought I'd better write down quickly how I did it.

Packages

  • Create a directory and put the files you want to install into a directory tree under it (e.g. if you create a directory called [pkgname], files that you want in /usr/local/bin go in [pkgname]/usr/local/bin.
  • Create a directory called [pkgname]/DEBIAN and put a file in it called 'control'.  This can be as simple as:
Package: grahamstestdeb
Version: 001
Architecture: i386
Depends:
Maintainer: Graham Jones (grahamjones139@gmail.com)
Description: Test Debian Package

  • Create a file called 'postinst' in DEBIAN.  This will be executed when the package is installed. This can be
  • #!/bin/sh
  • echo "postinst works!!!!"
  • Create the .deb package by doing
dpkg-deb --build [pkgname]
  •  Copy your new [pkgname].deb file into a new folder called repository.
  • Run 'sudo dpkg-scanpackages . /dev/null | gzip -9c > Packages.gz' in the repostitory directory.
  • Upload the repository directory to your web server:
ncftpput -v -R -u maps3.org.uk -p ftp.maps3.org.uk public_html/apt/ *

  • Add the following to /etc/apt/sources.lst 
deb http://apt.maps3.org.uk / 

  • Run sudo apt-get update
  • Run sudo apt-cache search [pkgname] - should find your package.
  • Run sudo apt-get install [pkgname] - should run your postinst script.
For better instructions see: http://odzangba.wordpress.com/2006/10/13/how-to-build-local-apt-repositories/#comment-7304.

Thursday, 19 May 2011

Rendering OpenStreetMap Data using Carto and Mapnik

Mapnik is often used to render OpenStreetMap (OSM) data.   The map style (line colours and sizes, icons etc.) are defined by a style file.  There is a very detailed one provided with OpenStreetMap's mapnik tools.   Unfortunately that level of detail means that the style definition is very complicated and it is hard to follow how it works.
A tool called carto is available which is a pre-processor that will take a simpler format of style file, and convert it into the mapnik file format.   I have been experimenting with trying to render OSM data using styles written for carto.   I had been hoping to use a nice graphical editor with map preview capability called tilemill, but tilemill does not work with postgresql datasources, which are necessary for OSM rendering.   Instead, I installed tilemill and used the version of carto that is included with it, but did not use the tilemill editor.

Carto Layer Definitions
Rendering data with carto needs you to do two things - define the data you want to plot on your map ('Layers'), and define how you want the data displayed ('Styles').

The datasource definitions go in a .mml file that looks something like this:

{
"_center":{"lat":36.870832154494,"lon":-113.79638671427,"zoom":5},
"_format":"png",
"srs":"+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs",
"Stylesheet":["style2.mss",
"areas2.mss",
"roads2.mss",
"labels2.mss",
"natural2.mss",
"contours2.mss",
"POIs2.mss"],

"Layer":[
  {"id":"coastline",
   "name":"coastline",
   "srs":"+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs +over",
   "class":"",
   "geometry":"polygon",
   "Datasource":{"file":"/home/graham/OSM/data/mapdata/world_boundaries/processed_p.shp","type":"shape"}},

 {"id":"landuse",
  "name":"landuse",
  "srs":"+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs",
  "class":"",
  "geometry":"area",
  "Datasource": {
               "type":"postgis",
      "dbname":"kefalonia",
      "user":"www",
      "password":"1234",
      "host":"localhost",
      "port":"",
      "table":"(select way,landuse,name,\"name:en\" from planet_osm_polygon where landuse is not null) as landuse"
               }
  }
]
}
The first few lines define the projection of the output map, and the stylesheets that are to be used to define how to render the data.   The bulk of the file is layer definitions.   In this example two layers are defined.  One is a shapefile containing the coastlines (the same one that is used by the normal OSM style).   The second layer extracts all areas tagged with 'landuse=xxx'.

We have not told mapnik how to plot the data though - this is done in the style files.  The ones relevant to this example are "style2.mss" and "areas2.mss".  Style2.mss contains:

@land: #e0e0c0;
@water: #C0E0F8;
@waterline: #8CE;
Map {
  background-color:@water;
}
#coastline::outline {
  line-color:@waterline;
  line-width:1.6;
}
#coastline::fill {
  polygon-fill:@land;
  polygon-gamma:0.75;
}
Here the things starting '@' are variables which allow you to define colours etc.  at the top of the file, then use them several times throughout it, making future maintenance easier.   In this example we define the background colour for the map, fill it in blue to represent water.   We then draw a line around the costline, and fill in the land with a separate colour.

The areas2.mss style is slightly more complicated:
#landuse {
   [landuse="residential"]
   {
      polygon-fill: #b0b0b0;
   }
   [landuse="industrial"]
   {
      polygon-fill: #a0a0a0;
   }
   [landuse="forest"]
   {
      polygon-fill: #a0d0a0;
   }
}
In this example the [] expressions are filters, which allows us to define different fill colours depending on the landuse tag.

These are just extracts - the actual styles I am using are getting progressively more and more complicated.   You can see the files, and a modified version of the generate_image.py script provided by OSM, which takes a carto .mml file as input in my svn repository (soon to be copied to github..)

Using these styles, I have updated my kefalonia map to give this:
and this:




These styles are nowhere near as clever as the standard OSM ones.  In particular I have not tried to devine different styles fo rdifferent zoom levels  instead I have two sets of stylesheets for two different zoom levels - I think in the end I will have there - one for a 'country level', another for a 'town level', and a third for higher zoom levels.

There are also a few issues - the line styles do not look as nice as the OSM ones - I do not know why...and there is a problem with the road names where sometimes other roads crossing over each other obliterate the labels.   THe reason is that I draw the road and the label at the same time - it will probably look better if I do the labels after all roads have been drawn.   Will hav eto work out how to do that!