gonium.net » nerdism http://gonium.net/md so much time, so little to do. Sat, 11 Sep 2010 16:42:09 +0000 en hourly 1 http://wordpress.org/?v=3.0.1 Sending Faxes from my Router http://gonium.net/md/2010/09/11/sending-faxes-from-my-router/ http://gonium.net/md/2010/09/11/sending-faxes-from-my-router/#comments Sat, 11 Sep 2010 16:40:41 +0000 md http://gonium.net/md/?p=295

Faxes are an rather old method for communication, but in Germany they have one advantage: as opposed to emails, faxes are legally binding in the same way as letters are. So, from time to time, sending out a fax is useful. In addition, I have a telephone flatrate included in my data plan, so I don’t have to pay the postage for letters any more. The plan: use the USB port on my router to attach a modem and send out faxes using the mgetty package.

For 3 Euro I acquired an old ELSA Microlink 56k USB modem. I did some research, this modem is one of the few ones supported by the Linux usb-cdc kernel drivers. In addition it can be powered from USB only, so I don’t need another power supply. A week after winning an auction on ebay it arrived today.

My router runs OpenWRT. I installed the following packages using the opkg system:

kmod-usb2
kmod-usb-uhci
kmod-usb-net
kmod-usb-core
kmod-usb-acm
mgetty

mgetty contains a program called “sendfax”, which can be used to dial a number and send the data. The latter needs to be in G3 format. Since I write all my letters using LaTeX, I integrated a “fax” target into my Makefile for LaTeX documents. This target reads the PDF output of LaTeX and converts it to G3 using Ghostscript. The essential command is:

gs -dSAFER -dBATCH -dNOPAUSE -sDEVICE=dfaxhigh -sOutputFile=fax.g3.%d -q main.pdf

This creates a bunch of fax.g3.* files, one for each page within the PDF file. Then, I simply copy these files to my router and issue the sendfax command, for example:

sendfax #fax number# fax.g3.1 fax.g3.2

The command dials the fax number and sends the specified g3 files:

root@nibbler:~# sendfax 032121xyzxyz fax.g3.1 fax.g3.2
Trying fax device '/dev/ttyACM0'... OK.
Dialing 032121xyzxyz... OK.
sending 'fax.g3.1'...
sending 'fax.g3.2'...

If an error occurs, the command will fail and tell you about it. The mgetty package also contains various scripts for building a fax spooler, but for my personal usage, I will stick to raw sendfax. Please note that it is also possible to receive faxes, but I did not install these components so far.

No more postage for me. Yay!

Picture: CC-BY-SA-NC vtengr4047, thanks!

]]>
http://gonium.net/md/2010/09/11/sending-faxes-from-my-router/feed/ 0
Meine Daten sind… wo? http://gonium.net/md/2009/10/25/meine-daten-sind-wo/ http://gonium.net/md/2009/10/25/meine-daten-sind-wo/#comments Sun, 25 Oct 2009 09:51:52 +0000 md http://gonium.net/md/?p=170 datacenter

Vor gut einem Monat schrieb ich meine TK-Provider an und verlangte Auskunft über die Daten, welche die Unternehmen über mich speichern. Insbesondere war ich ja gespannt, ob die Provider mir die Daten aus der Vorratsdatenspeicherung zugänglich machen. Je nach Lesart des §19 des Bundesdatenschutzgesetzes könnte ich einen Anspruch darauf haben, auch diese Daten übermittelt zu bekommen. Wobei ich mir da allerdings nicht ganz sicher bin, denn:

(4) Die Auskunftserteilung unterbleibt, soweit
1. die Auskunft die ordnungsgemäße Erfüllung der in der Zuständigkeit der verantwortlichen Stelle liegenden Aufgaben gefährden würde,
2. die Auskunft die öffentliche Sicherheit oder Ordnung gefährden oder sonst dem Wohle des Bundes oder eines Landes Nachteile bereiten würde oder
3. die Daten oder die Tatsache ihrer Speicherung nach einer Rechtsvorschrift oder ihrem Wesen nach, insbesondere wegen der überwiegenden berechtigten Interessen eines Dritten, geheim gehalten werden müssen
und deswegen das Interesse des Betroffenen an der Auskunftserteilung zurücktreten muss.

Ich könnte mir vorstellen, dass man mir den Zugang zu diesen Daten unter Berufung auf den Punkt 3. verweigert. Aber nicht so schnell – was ist denn aus meinen Anfragen geworden?

  1. Die Blau Mobilfunk GmbH hat mein Schreiben einfach ignoriert. Ich habe einen Monat später immer noch keinerlei Antwort erhalten. Schlimmer noch, meine Aufforderung, mir keine Werbung mehr zu schicken, wurde ignoriert. Ich schicke morgen noch einmal ein Schreiben hin. Sollte auch dieses ignoriert werden, eskaliere ich das zum Hamburger Datenschutzbeauftragen.
  2. Kabel Deutschland hat innerhalb von fünf Tagen reagiert. Da scheint eine entsprechende Softwareinfrastruktur vorhanden zu sein – die Antwort ist ein Formschreiben, das leider nicht alle meine Fragen behandelt. Insbesondere an wen die Daten weitergegeben wurden und meine Frage nach den Daten aus der Vorratsdatenspeicherung wurden ignoriert. Auch hier hake ich nach.

Alles in allem also eine zwiespältige Erfahrung. Stay tuned.

Photo Credit: Marcin Wichary, “Data processing center, pt. 5″, CC-BY license. Thanks Marcin!

]]>
http://gonium.net/md/2009/10/25/meine-daten-sind-wo/feed/ 1
DCF77 Radio Receiver – Filter Signals http://gonium.net/md/2009/09/16/dcf77-radio-receiver-filter-signals/ http://gonium.net/md/2009/09/16/dcf77-radio-receiver-filter-signals/#comments Wed, 16 Sep 2009 15:36:46 +0000 md http://gonium.net/md/?p=157 Broadcast Tower

I live close to the DCF77 radio transmitter, so my signal was always pretty strong and clear. This is of course not the case for everybody :-) Gwen Roelants did run into problems. He writes:

Although your code works (thanks for that!) it looked like it was very sensitive to how the antenna was positioned.
I found that I did receive a signal every second, but that for the longer signals, I sometimes got a short flash interrupting it, causing the library to add 2 seconds instead of one. Since I got such a flash in almost every minute it could take a very long time before a proper sync was found, and because 2 seconds were counted the time would also drift during the time no new signal could be decoded.
I found a rather simple fix for your code that greatly improved the reliability and time to find a correct signal.

I don’t have an Arduino around so I did not test it, but the proposed changes seem to be reasonable. You can find the changes in the Arduino forums. Thanks, Gwen!

The photo was CCed on flickr by Nathan Gibbs.

]]>
http://gonium.net/md/2009/09/16/dcf77-radio-receiver-filter-signals/feed/ 0
Stille Post via Twitter http://gonium.net/md/2009/08/18/stille-post-via-twitter/ http://gonium.net/md/2009/08/18/stille-post-via-twitter/#comments Tue, 18 Aug 2009 18:57:29 +0000 md http://gonium.net/md/?p=151 Briefkasten reloaded St. Gallen by schillergarcia

Prinzip stille Post: Am Anfang der Menschenkette flüstert man eine Nachricht rein, die Nachricht wird flüsternd weitergeleitet, am Ende kommt Nachrichtensalat heraus. Funktioniert auch via Twitter. Meine initiale Nachricht:

10:24 [@gonium:86] Genau deshalb ist #Zensur eine dämliche Idee: http://tr.im/wANf #piraten #btw09

Das Resultat:

11:34 [@wahl_politicus:2] By @ekelias RT @pantoffelpunk: RT: @bauhausmensch: RT @gonium Genau deshalb
ist http://tr.im/wANf LEUTE, WIR BRAUCHEN DIE #piraten #-btw

Den kompletten zeitlichen Ablauf hab ich mal hier dokumentiert:

10:24 [@gonium:86] Genau deshalb ist #Zensur eine dämliche Idee: http://tr.im/wANf #piraten #btw09
10:39 [@Piratobot:3] RT @gonium Genau deshalb ist #Zensur eine dämliche Idee: http://tr.im/wANf
#piraten #btw09
10:39 [@bauhausmensch:2] "blöder Zufall", neh is klar! RT: @Piratobot: RT @gonium Genau deshalb ist
#Zensur eine dämliche Idee: http://tr.im/wANf #piraten #btw09
10:49 [@BitBoutique:1] RT @bauhausmensch "blöder Zufall", neh is klar! RT @gonium Genau deshalb ist
#Zensur eine dämliche Idee: http://tr.im/wANf #piraten
10:59 [@anjakrieger:1] RT @gonium Genau deshalb ist Zensur eine dämliche Idee: http://tr.im/wANf via
@BitBoutique @bauhausmensch
10:59 [@pantoffelpunk:1] RT: @bauhausmensch: RT @gonium Genau deshalb ist http://tr.im/wANf LEUTE,
WIR BRAUCHEN DIE #piraten #btw09 DRINGEND!
11:09 [@ekelias:1] RT @pantoffelpunk: RT: @bauhausmensch: RT @gonium Genau deshalb ist
http://tr.im/wANf LEUTE, WIR BRAUCHEN DIE #piraten #btw09 DRINGEND!
11:09 [@SebJabbusch:1] Genau deshalb ist #Zensur eine dämliche Idee: http://tr.im/wANf #piraten
#btw09 (RT @Piratobot: RT @gonium )
11:14 [@Crazy_Nugman:1] RT: @ekelias: RT @gonium Genau deshalb ist http://tr.im/wANf LEUTE, WIR
BRAUCHEN DIE #piraten #btw09 DRINGEND!
11:19 [@PinkPueppi:1] RT: @Crazy_Nugman: RT: @ekelias: RT @gonium Genau deshalb : http://tr.im/wANf
BRAUCHEN WIR DIE #piraten #btw09 DRINGEND!
11:29 [@Magic_Cauldron:1] RT @gonium Genau deshalb : http://tr.im/wANf BRAUCHEN WIR DIE #piraten
#btw09 DRINGEND!
11:34 [@wahl_politicus:2] By @ekelias RT @pantoffelpunk: RT: @bauhausmensch: RT @gonium Genau deshalb
ist http://tr.im/wANf LEUTE, WIR BRAUCHEN DIE #piraten #-btw

Der Piratobot ist ein bot, der #piraten-Nachrichten retweetet – nette Idee. Was folgern wir daraus? Original und Kopie sind in der digitalen Welt doch nicht immer identisch ;-)

Das Bild oben stammt von schillergarcia (CC-BY via flickr)

]]>
http://gonium.net/md/2009/08/18/stille-post-via-twitter/feed/ 0
USBTemp: Continuous Temperature Monitoring http://gonium.net/md/2009/01/03/usbtemp-continuous-temperature-monitoring/ http://gonium.net/md/2009/01/03/usbtemp-continuous-temperature-monitoring/#comments Sat, 03 Jan 2009 18:21:09 +0000 md http://gonium.net/md/?p=124 Kaiserlautern, Germany

Its this time of the year: I have time for a small project. This year I have built an USB-powered thermometer. Basically, you just plug it into an USB port. Then you can query the module via a small commandline tool. I wanted to be able to use my NSLU for creating temperature graphs. The image above is the temperature in Kaiserslautern, Germany – updated every 15 minutes.

The code and the schematic are open-source, licensed under the terms of the GPL. The code is available at the Mikrowerk code repository:

USBTemp start page at Mikrowerk

On these pages you can read more about the actual device and the software. This post describes how to use USBtemp to record temperature information continuously. Im am using my trusty NSLU running Debian as a host – any other Linux/Mac machine will work the same way. The NSLU is a NAS device. It is small and doesn’t consume too much power (about 20 W).

My NSLU home server

The USBTemp device is attached to the second USB port of the NSLU. Using the host software I can easily query the sensors of the device:

$ ./usbtemp sensors
2 sensor(s) found, querying
sensor 0: ID 9F17A5010800 type: (DS18S20)
sensor 1: ID B46865010800 type: (DS18S20)

The first sensor is soldered on the USBTemp board itself – it monitors the temperature in my office. The second sensor is attached to my balcony:

Outside sensor

Actually the sensor is hidden in the white box to protect it from rain. The sensor is the second in the list above, so I can query it using the command

/usbtemp temp B46865010800
searching sensor with id B46865010800 - using sensor handle 1
reading sensor 1 (°C): +1.1875

In combination with RRDTool it is easy to create timeline graphs. The USBTemp package contains scripts that help you to do this. First, you have to edit the settings in etc/config.sh:


# This file contains the configuration. Adjust it to meet your needs.
SENSOR1_ID="9F17A5010800"
SENSOR2_ID="B46865010800"
TEMP_DATABASE="$HOME/usbtemp/temperatures.rrd"
GRAPH_DIRECTORY="$HOME/usbtemp/temp-graphs"

Then you must define the USB_HOME environment variable to point to your USBTemp installation directory, e.g. (for bash)

export USBTEMP_HOME=/home/md/Projects/usbtemp/trunk

As soon as you like the settings you can use bin/generate-db.sh to create the RRDTool database. Please review the script if you want to adjust some settings. I use the cron daemon to query the sensors periodically (every five minutes) and update the plots every 15 minutes. This is the crontab:

# Linux cron can handle environment variables
# set usbtemp path
USBTEMP_HOME=/home/md/Projects/usbtemp/trunk

# m h dom mon dow command
*/5 * * * * $USBTEMP_HOME/bin/log-temperature.sh > /dev/null 2>&1
*/15 * * * * $USBTEMP_HOME/bin/plot-temperature.sh > /dev/null 2>&1

I use another little script to upload the graphs of the external sensor to my webserver. For my personal use, I also generate graphs of my office temperature – but I don’t publish these :-)

Here are the currently available temperature plots.

]]>
http://gonium.net/md/2009/01/03/usbtemp-continuous-temperature-monitoring/feed/ 4
Installing Hoefler Text in LaTeX http://gonium.net/md/2008/11/23/installing-hoefler-text-in-latex/ http://gonium.net/md/2008/11/23/installing-hoefler-text-in-latex/#comments Sun, 23 Nov 2008 10:08:27 +0000 md http://gonium.net/md/?p=113 The Hoefler Text Ampersand

Not that straightforward, actually. Apple includes the Hoefler Text font in Mac OS X – its a really nice and readable professional font. Here’s what I did:

(1) You need to obtain the font in the opentype format (otf). Be careful: for me, the TTF version didn’t work. The Postscript type 1 version worked great.
(2) Use otftotfm -a to convert and install the files:

otftotfm -a -e texnansx HoeflerText-Regular.otf -fkern -fliga LY1--HoeflerText-Regular

This installs the regular form in the .texlive subdirectory of your home directory. Do this for all the font shapes you want to use. In the last step you need to create a .fd file:

\DeclareFontFamily{LY1}{HoeflerText}{}\DeclareFontShape{LY1}{HoeflerText}{m}{n}%
{ < -> LY1--HoeflerText-Regular }{}
\DeclareFontShape{LY1}{HoeflerText}{m}{it}{ < -> LY1--HoeflerText-Italic }{}
\DeclareFontShape{LY1}{HoeflerText}{m}{sl}{ < -> LY1--HoeflerText-Bold }{}
\DeclareFontShape{LY1}{HoeflerText}{b}{n}{ < -> LY1--HoeflerText-Bold }{}\DeclareFontShape{LY1}{HoeflerText}{b}{it}%
{ < -> LY1--HoeflerText-BoldItalic }{}

Put this in ~/.texlive2008/texmf-var/tex/latex/HoeflerText/LY1HoeflerText.fd. Again, make sure that all font shapes you want to use are included.

In your Latex document, put

\usepackage[LY1]{fontenc}
\renewcommand{\rmdefault}{HoeflerText}

to use the font.

The picture above was CCed on flickr by liikennevalo, thanks!

]]>
http://gonium.net/md/2008/11/23/installing-hoefler-text-in-latex/feed/ 0
Code Kata: Project Euler #7, Finding Primes http://gonium.net/md/2008/09/08/code-kata-project-euler-7-finding-primes/ http://gonium.net/md/2008/09/08/code-kata-project-euler-7-finding-primes/#comments Mon, 08 Sep 2008 08:08:52 +0000 md http://gonium.net/md/?p=100

I resumed my code katas – this time, I’m using Erlang to solve the problem:

By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.
What is the 10001st prime number?

It seems to be clever to have a prime number generator for Project Euler anyway. My implementation is based on the Sieve of Erathosthenes and uses the Prime Number Theorem for an estimate on the size of the sieve. The code is pretty easy:

[viewcode]src=pe7.erl [/viewcode]


HTML code generated by vim-color-improved v.0.4.0.Download this code: pe7.erl

In the erathosthenes function, a list comprehension is used to purge all multiplies of the current Index value. My first attempt didn’t include the Index variable – I simply decreased the boundary. The disadvantage of this method is that it keeps the list of primes bigger over the runtime: Instead of removing the multiples of 2 at the very beginning, they get removed as the last multiples. The size of PurgedNumbers stays bigger, which leads to a runtime of 6.7 seconds. When I use the Index variable, the multiples of 2 get removed first which avoids copying them all the way. The runtime decreases to 1.2 seconds (on my Mac Mini).

Since all variables in Erlang are bound only once, I don’t know how to optimize this further. In C, I would use a bit array to further reduce the memory footprint. But: the Erlang code is much easier to read and write. I think Erlang is just not made for low memory bandwidth requirements :-)

The picture above is an representation of the Ulam spiral, CCed on flickr by no_typographic_man.

]]>
http://gonium.net/md/2008/09/08/code-kata-project-euler-7-finding-primes/feed/ 0
FreeRTOS for ATMega644 http://gonium.net/md/2008/08/10/freertos_for_atmega644/ http://gonium.net/md/2008/08/10/freertos_for_atmega644/#comments Sun, 10 Aug 2008 16:19:26 +0000 md http://gonium.net/md/?p=89 six-legged chip bug

FreeRTOS is an open-source realtime operating system for microcontrollers. The ATMega644 of ATMEL provides 64KB of flash program memory in a DIY-friendly 40-pin PDIP package. Read on for how to combine both to my new software development platform.

FreeRTOS provides a nice RTOS for embedded systems and is readily available for various platforms. One timer of the hardware is used to implement multitasking features. A library provides routines for creating tasks and synchronization. Unfortunately, FreeRTOS is currently only ported to the ATMega323 – so I created a basic port to the ATMega644 and stripped all unnecessary features.

Typically, the FreeRTOS demo shows how to implement various threads and let them access the hardware. While it is educating to read the code, it is too bloated to serve as a template for new developments. In addition, I prefer Peter Fleury’s UART library for serial outputs. So, I removed all threads and included the library. To make sure that two threads cannot write to the same UART at the same time, I introduced a mutex per UART to synchronize the output on a per-string basis. Please note that there is no Mutex to synchronize read access. The main program starts two tasks which print “foo” and “bar” to the serial line, respectively. I kept the task surveilance mechanism as implemented in the original FreeRTOS demo (this might become handy ;-))

Here is a peek at the main.c file:

[viewcode]src=freertos-atmega644-main.c [/viewcode]


HTML code generated by vim-color-improved v.0.4.0.Download this code: freertos-atmega644-main.c

You can get the whole package (GPL licensed) from the download page. Have fun! Kudos for the CC’ed chip bug picture go to oskay.

]]>
http://gonium.net/md/2008/08/10/freertos_for_atmega644/feed/ 1
Generating random numbers from any distribution http://gonium.net/md/2008/07/29/generating-random-numbers-from-any-distribution/ http://gonium.net/md/2008/07/29/generating-random-numbers-from-any-distribution/#comments Tue, 29 Jul 2008 09:22:52 +0000 md http://gonium.net/md/?p=85

At work I needed to generate random numbers following a combination of two gaussian distributions – which gave me some headache until someone pointed me to using a Monte Carlo approach. Here’s how.

Typically, any programming language provides some way to generate uniformly distributed random numbers, typically in the interval [0,1]. A histogram of the values looks like this:

However, I needed random numbers following the joint distribution of two gaussian distributions. The histogram should look like this:

It turns out that it is rather simple to generate random numbers from an given probability density function (PDF) f(x). The only restriction is that there exists another density function g(x) such that c*g(x) majorizes the density function f(x):

c*g(x) >= f(x) for all x.

The steps are rather simple – to generate a random variate x with density f(x):

  1. Generate x with PDF g(x)
  2. Generate y uniform on [0, cg(x)]
  3. If y <= f(x), then output x and return – otherwise repeat from step 1.

Please note that this approach is applicable to many PDFs, but it can be rather slow, depending on the “hit rate”. The algorithm is simple: You generate two uniform random numbers, x and y. Then, you check if y < f(x) – if true, add x to your collection of random numbers. Otherwise, discard it. Repeat the steps until you have enough random numbers. This method is also called Rejection Sampling and was first described by John von Neumann. Other techniques include Inverse Transformation, Composition and Convolution.

I highly recommend reading Chapters 28 and 29 of Rai Jain’s “The Art of Computer Systems Performance Analysis” which outline techniques for generating random numbers of several distributions.

My ruby implementation consists of a MC wrapper and blocks compute the random variate. Currently, I can create gaussian distributions, exponential distributions and a combination of two gaussian distributions. The toolbox also contains a method to scale the range of the random numbers using a linear transformation approach.

[viewcode]src=statistics.rb [/viewcode]


HTML code generated by vim-color-improved v.0.4.0.Download this code: statistics.rb

The title picture was CCed by Saffana, thanks!

]]>
http://gonium.net/md/2008/07/29/generating-random-numbers-from-any-distribution/feed/ 0
Code Kata: Project Euler #4, Finding Palindromes http://gonium.net/md/2008/04/19/code-kata-project-euler-4-finding-palindromes/ http://gonium.net/md/2008/04/19/code-kata-project-euler-4-finding-palindromes/#comments Sat, 19 Apr 2008 17:57:51 +0000 md http://gonium.net/md/?p=83 This weekend, I solved problem 4 of Project Euler:
A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99. Find the largest palindrome made from the product of two 3-digit numbers.
I designed a routine that checks whether a given number is a palindrome. This routine is then used inside two loops iterating from 999 downto 0. The first hit is the largest palindrome. The core functionality is here: bool Problem4::isPalindrome(long number) { bool retval = false; std::vector digits; while (number > 0) { long lastdigit = number % 10; digits.push_back(lastdigit); number = number / 10; } reverse(digits.begin(), digits.end()); std::vector::iterator front = digits.begin(); std::vector::iterator back = –digits.end(); retval = false; while (! (front >= back)) { if ((*front) == (*back)) { retval = true; // move iterators to the next digits front++; back–; } else { // cannot be a palindrome, back out retval = false; break; } } return retval; } This implementation reverses the vector. By using the front and back operators in the other direction, this could be left out. But it serves its purpose for now. You can get the full sourcecode from the download page. Please note that the code in the tarball calculates *all* palindromes smaller than 1000000. The picture was CCed on flickr by TisseurDeToile -[mangerait bien un petit chat]-.]]>
http://gonium.net/md/2008/04/19/code-kata-project-euler-4-finding-palindromes/feed/ 0