Category Archives: Uncategorized

ArchLinux on RPi with USD Harddrive

I have found that one of the weakest parts of a Raspberry Pi server or workstation is the SD card: it is slow and it will break sooner rather than later. There may be industrial SD cards or better SD cards, but a good old USB hard drive is just better.

With RPi v3 it shall be possible to boot straight off a USB drive! That sounded great so I got a brand new RPi v3 B+, a USB hard drive, and I installed ArchLinux on the hard drive, just as if it was a memory card. Fail. That did not work (with ArchLinux, Raspbian may be another story).

But there are levels of pain:

  1. All SD-card
  2. SD-card, but /home on USB harddrive
  3. USB harddrive, but /boot on SD-card
  4. All USB harddrive

I decided to try #3.

It turns out that when the RPi boots it runs u-boot (its like the BIOS of RPi, and many other embedded devices). At one point u-boot reads boot.scr (from the first VFAT partition of the SD card). It had the lines:

part uuid ${devtype} ${devnum}:2 uuid

setenv bootargs console=ttyS1,115200 console=tty0 root=PARTUUID=${uuid} rw rootwait smsc95xx.macaddr="${usbethaddr}"

I figured that I could do this instead:

# part uuid ${devtype} ${devnum}:2 uuid

setenv bootargs console=ttyS1,115200 console=tty0 root=/dev/sda2 rw rootwait smsc95xx.macaddr="${usbethaddr}"

However, boot.scr has a checksum so you cant just edit it. But it tells you what to do: run ./mkscr. But it is dependent on mkimage, so the procedure is:

  1. Install uboot tools
    1. ARCH: pacman -S uboot-tools
    2. Ubuntu/Debian: apt-get install u-boot-tools
  2. Edit boot.txt (not boot.scr) to your liking
  3. Run: ./mkscr

Now only /boot is on SD-card. That is quite ok with me. There is very little I/O to boot so the SD-card should survive. If I want to I can make a regular simple backup by simple file copy of /boot to a zip-file or something, and just restore that zip-file to any SD-card.

There seems to be no need to edit anything else (like fstab).

Well, the bad thing is it did not work out 100% as I hoped. The good thing is that this should work with any RPi, not just the RPi v3 that supports USB boot.

Best Train Simulator 2019

I have some personal enthusiasm for trains, and last years part of that has been playing Train Simulator on PC. That is the game that used to be called Railworks and that currently is named Train Simulator 2019. While I have spent much time with it I also have mixed feelings.

In 2019 there are two alternatives to TS2019 that I have tested and that I will write about: Train Sim World and Trainz Railroad Simulator 2019.

My experience with Dovetail Train Simulator (2019)

I got Train Simulator because I wanted to try to drive trains. The game has developed over the years but there are some annoyances.

The game has some quirks and bugs. The physics, engines, wagons, signals, AI and scenario conditions sometimes don’t work in a way you would expect.

The game is also rather unforgiving. One little mistake can ruin a scenario so you can’t even continue. If that was passing a red light, ok. But sometimes I am just a little late, a little early, I connected or disconnected the wrong wagon, I went into the wrong siding or something like that.

The combination of bugs and being unforgiving is rather frustrating. When there is a little inperfection in the game I can perhaps accept the lack of good simulation experience, but if it ruins the scenario completely, it is worse.

The game has a competitive aspect (it is a game) where you drive scenarios and get scores. This is particularly unforgiving. Decouple a wagon and for some reason (bug?) I get “operational error”, being penalised with -750 points (1000 is max), and I have no choice but aborting the scenario. Also, speeding is penalised heavily. This is annoying for two reasons: first the time table is often ridiculously tight, second it is not uncommon that maximum allowed speed changes unexpectedly.

You can read about the outdated graphics of TS2019 and that is true, but it does not ruin my experience. You can read about all the expensive DLC, but that is your choice (I bought some, but most everything on sales). What I find more annoying is that I buy a nice piece of DLC and it comes with very few scenarios. That is where the (Steam) workshop comes in and there are quite many scenarios (of varying quality) do download.

I found that creating scenarios was often more fun than driving myself and I have contributed some 44 scenarios on Steam Workshop. If driving is quirky, creating scenarios is kind of black magic (the problem is I need to test it, and when it fails after 40 minutes, I need to guess whats wrong and drive again for 40 minutes until I know if it works – a horrible development and debugging experience).

It seems to me it would be very possible to deliver a better Train Simulator game!

On Realism

It is easy to talk about realism. But is it really what we want. My experience…

  • Some routes allow for long eventless sessions. That is the realistic truth about driving a train, but how entertaining is it?
  • A real challenge when driving a train is breaking and planning your breaking. The weight and length of the train matters, as long as other factors. In the real world a train engineer makes calculations about breaking distances. They are not going to be driving a new train, with unknown weight, on a new track on a tight time schedule. Yet in a train simulator this is what we do, because we want (much) variation (it is a somewhat boring game anyways).
  • A real engineer knows the line well, and has special physical documentation about the line available. And he has studied this before. You don’t do that in a train simulator.
  • A real engineer spends much time checking things like breaks and wheels. And there is much waiting.
  • You can have a realistic “regulator”, that you can operate in the locomotive cab. That will look realistic in one way. But a real engineer would not point and look at it with a mouse, he just happens to have his hand there in the first place. User-friendly, where man-machine becomes one, is good simulation to me.
  • Real(istic) timetables are good, but not when it is almost impossible to arrive on time in the simulator.

My point is that I don’t want a realistic simulator. I want a simulator that gives me the feeling I am driving a train. And I want the time I spend with my computer to be more eventful, entertaining and challenging that the average work hour of a train engineer. And also somewhat more forgiving and I want support with things that are easier in the real world.

Train Sim World

Train Sim World is produced by the same company (Dovetail) as Train Simulator 2019. It appears they thought of it as a replacement for Train Simulator 2019, but it also appears that for now the games exist side by side. It is not clear that Train Sim World will ever replace, or even survive, Train Simulator 2019.

The good:

  • It looks (the graphics) better than the alternatives.
  • It may be the most “polished” option (also available for Playstation and Xbox, which gives you a hint).
  • If you get a “package” at discounted price on Steam (EUR25 for 4 routes) it is quite good value.

The bad:

  • It does not look that good; it is still computer graphics with obvious artifacts and problems. Also, the sound is not too convincing and the surroundings are pretty dead.
  • Walking around (in the scenarios) does not appeal to me, and it is not well made enough to add to the realism of the game.
  • Menus are a bit messy.
  • Quite limited number of scenarios, but plenty of “services”, but I think that contributes to (even) less events, action and storytelling.
  • The routes seem small, and very little action or room outside the mainline (like very linear).
  • Occational glitches like “what do I do now”, “what happens next” or “how do I do that”? (driving a service, I was done, told to get off, the train drove away by itself with no visible driver or no comments, and then nothing… had to just quit).
  • It lacks something. Like its not a bit dirty, noisy and rough… but just too smooth and clean.
  • So far, no possibility for user generated content. It is promised, and it will be based on Unreal, so it seems to be very technically demanding. I myself would prefer to be able to make scenarios with a story easily, without changing anything about the route or the other assets at all.
  • Unreal (which is to thank for the better graphics) seems to be a more complex (expensive) development environment, and perhaps this will limit in the future the availability or routes and assets, and make the price high (pure speculation).

I did give Train Sim World a first try, wrote a very negative review, refunded it, but after a few weeks I gave it a new try, and now I have a more balanced opinion about it.

Trainz Railroad Simulator 2019

Years ago I obviously did research and opted for Train Simulator rather than Trainz. Now that I was a bit disappointed with Train Simulator and rather disappointed with Train Sim World I felt I had to give Trainz 2019 a try.

My expectations based on marketing and what I read was:

  • Better graphics than Train Simulator, but perhaps not as good as Train Sim World.
  • More creator-, community- and sharing oriented (which appealed to my preference to making scenarios).
  • It’s a railroad simulator, rather than a train driver simulator.

I must say right away that I am quite disappointed. I ended up paying EUR 70 for Trainz, and EUR 25 for Train Sim World, and that does not reflect the value of what I got.

Download Station

Trainz comes with “its own Steam Workshop, Download Station”. This is the worst part of it. Hundreds of assests, organised alphabetically, with virtually no filtering and no community/feedback/rating function. Unless I completely missed something, this is shit. My use case is that I want to see if someone created a nice 30 min session for one of the premium routes that came with my purchase (and that has no extra dependencies). Trainz seems to live in the world where people download zip-files from ftp-servers and spend the effort of maintaining their virtual asset library like the stock portfolio. I am tempted to make a few sessions myself, and sharing them here, on my blog, but why?

Graphics

There is something idyllic, picturesque, beautiful and friendly about Trainz that is missing in Train Simulator and Train Sim World. There are gorgeous screenshots from Trainz out there. But when it comes to actual game performance on my actual computer (a NUC Hades Canyon) Trainz is the worst. I have been spending not so little time optimizing my graphics settings (and there are many settings to play with).

Quality

To my disappointment the routes come with quite few sessions. The beatiful route from Edinburg to Aberdeen (perhaps just to Dundee) has two sessions: a passenger service with the same Deltic locomotive going both ways. These two scenarios both take 1h30min each to drive. And the one I did try did not work in CAB (realistic) drive mode, because for some reason the Deltic can not pull those wagons with any speed whatsoever. Isn’t it reasonable to expect when a new EUR 70 release is made after 7 years, that the sessions are tested at least once, and working?

Then there was another beautiful session on the Cornish mainline where a 2MT steam locomotive pulls ~25 freight wagons and it just can’t make it up the grades. I asked in the forum and I had managed to get further than most people, but the suggestion was to just try another locomotive (edit the session). Why release a session with the wrong locomotive in the first place?

If driving steam locomotives in realistic mode can be a challenge in Train Simulator (often a frustrating one), in Trainz it feels… not realistic. Perhaps I need more practice, but it is very… unsmooth.

Other things

There is no support for a Gamepad (although I found a little software called AntiMicro) which works decently well for my purposes.

I really miss the look-out-throw-the-side-window camera view.

I appreciate that I can see the status of the next signal in the HUD.

When I have completed a session it does not remember (marked as completed) so I made my own list

A good thing about Trainz is that it is more forgiving than Train Simulator. I ran out of boiler pressure, but then I could switch to simple driving mode and at least complete the session.

I get the feeling that for people who already own and love the old Trainz this is an upgrade. But for a new player it is a rough experience.

Conclusion and recommendation

Unfortunately I think none of the games I have written about live up to the expections you should allow yourself to have in 2019. And I am not aware of a better game in the genre.

Clearly this genre appeals to enthusiasts who want to make their own assets and modify the game, and clearly Train Simulator and Trainz are based on old technology that have not aged too well (and people are reluctant to abandon their assets). Train Sim World, being based on Unreal, has not been able to deliver a workshop- or sharing-experience at all, yet.

If you are curious about how it is to drive a train, get Train Sim World (and an Xbox controller if you get it on PC, I know nothing about the Playstation/Xbox experience). Sit comfortably, turn up the volume, have some coffee (or whatever you drink) and do your best to enjoy the experience. Spend time with the tutorials and dont get too frustrated if you get stuck.

If you want to have your own digital train layout, and play with it (dispatch and control multiple trains), get Trainz, and make sure to have a powerful enough computer.

If you think that Steam workshop is a nice idea where you can share scenarios (and other assets) and communicate with other people about them get Train Simulator 2019. Cost/price aside, there are very many routes (and extra locomotives) available for Train Simulator 2019.

Train Simulator 2019 now supports 64-bit mode. Technically its not… hot… but it is being improved. Train Sim World looks better, but it is not that much better. Honestly, folks who make a living reviewing computer games say: “TS2019 looks so old, but TSW is built on Unreal like all the other cool games, much better.” But for your total train simulation experience, the difference is… marginal.

I would not be too surprised if the Train Sim World Editor never happens. If it is released I would not be surprised if it is too complex and a critical portion of contributors and enthusiasts never switch. The advice to enthusiasts to “Download the UE4 Editor from Epic and start learning”, I am sceptical about it. I doubt I will contribute scenarios if I have to get into a real 3D studio to place some trains and make some timetables/rules.

I would hope that Trainz gets a real workshop experience where you can easily share assets in a social way and where you don’t need to worry too much about dependencies. And I would hope that Trainz manages to polish their game, test it properly, and provide a solid graphics experience.


Trainz Log

I decided to try Trainz (now that 2019 is out) and I think it is useful to keep track of my progress, so I will do it here.

Gamepad

I prefer to drive my train with a gamepad. I found a little free software called AntiMicro which allowed me to map my Xbox gamepad to relevant Trainz keys. It was easy and I recommend it.

Graphics

My computer is a NUC Hades Canyon. It has an Intel Core i7 CPU, AMD Radeon RX Vega M GPU, 16GB or RAM and 512GB SSD. This computer can not at all play Trainz 2019 in “Ultra”, instead I have to tune down the performance settings quite much. I have found (and I may change opinion when I have experimented more) that I want to run Trainz in full resolution (1920×1080) and I think the lowest anti aliasing (2x) makes most sense. I allow myself to use “Clutter + Turf FX” and High details. Different routes are supposed to be demanding on the GPU.

Cornish Mainline and Branches

A trip to Falmouth: Completed with 2 stars.
Freight Delivery: This session is tricky and I started a thread on the Trainz forum. I dont think the 2MT is capable of pulling 23 wagons all the way, I got completely stuck after 7 miles in a 2%+ grade. I modified the session and used a 4200 tank locomotive instead but I got two new problems: 1) AI trains going in the other direction all stand still, 2) When I have finally arrived the session never ends (or continues). Perhaps I broke something when I modified it.
Helston freight run: Completed with 5 stars.
Helston passenger run: Completed with 4 stars.
Mainline passenger service: Completed with 1 star (!), on time, gorgeous!
St Ives passenger run: Completed with 5 stars.

ECML Edinburgh – Dundee

09-10 Dundee – Kings Cross: Completed with 5 starts (but can’t drive in realistic CAB mode)

Sebino Lake

Maintenance Service: Completed with 5 stars (in DCC, can’t get the train rolling in Cab mode)

Lambda Functions considered Harmful

Decades ago engineers wrote computer programs in ways that modern programmers scorn at. We learn that functions were long, global variables were used frequently and changed everywhere, variable naming was poor and gotos jumped across the program in ways that were impossible to understand. It was all harmful.

Elsewhere matematicians were improving on Lisp and functional programming was developed: pure, stateless, provable code focusing on what to do rather than how to do it. Functions became first class citizens and they could even be anonymous lambda functions.

Despite the apparent conflict between object oriented, functional and imperative programming there are some universally good things:

  • Functions that are not too long
  • Functions that do one thing well
  • Functions that have no side effects
  • Functions that can be tested, and that also are tested
  • Functions that can be reused, perhaps even being general
  • Functions and variables that are clearly named

So, how are we doing?

Comparing different styles
I read code and I talk to people who have different opinions about what is good and bad code. I decided to implement the same thing following different principles and discuss the different options. I particularly want to explore different ways to do functional programming.

My language of choice is JavaScript because it allows different styles, it requires quite little code to be written, and many people should be able to read it.

My artificial problem is that I have two arrays of N numbers. One number from each array can be added in NxN different ways. How many of these are prime? That is, for N=2, if I have [10,15] and [2,5] i get [12,15,17,20] of which one number (17) is prime. In all code below I decide if a number is prime in the same simple way.

Old imperative style (imperative)
The old imperative style would use variables and loops. If I had goto in JavaScript I would use goto instead of setting a variable (p) before I break out of the inner loop. This code allows for nothing to be tested nor reused, although the function itself is testable, reusable and pure (for practical purposes and correct input, just as all the other examples).

  const primecount = (a1,a2) => {
    let i, j;
    let d, n, p;
    let retval = 0;


    for ( i=0 ; i<a1.length ; i++ ) {
      for ( j=0 ; j<a2.length ; j++ ) {
        n = a1[i] + a2[j];
        p = 1;
        for ( d=2 ; d*d<=n ; d++ ) {
          if ( 0 === n % d ) {
            p = 0;
            break;
          }
        }
        retval += p;
      }
    }
    return retval;
  }

Functional style with lambda-functions (lambda)
The functional programming equivalent would look like the below code. I have focused on avoiding declaring variables (which would lead to a mutable state) and rather using the higher order function reduce to iterate over the two lists. This code also allows for no parts to be tested or reused. In a few lines of code there are three unnamed functions, none of them trivial.

  const primecount = (a1,a2) => {
    return a1.reduce((sum1,a1val) => {
      return sum1 + a2.reduce((sum2,a2val) => {
        return sum2 + ((n) => {
          for ( let d=2 ; d*d<=n ; d++ ) if ( 0 === n % d ) return 0;
          return 1;
        })(a1val+a2val);
      }, 0);
    }, 0);
  };

Imperative style with separate test function (imperative_alt)
The imperative code can be improved by breaking out the prime test function. The advantage is clearly that the prime function can be modified in a more clean way, and it can be tested and reused. Also note that the usefulness of goto disappeared because return fulfills the same task.

  const is_prime = (n) => {
    for ( let d=2 ; d*d<=n ; d++ ) if ( 0 === n % d ) return 0;
    return 1;
  };

  const primecount = (a1,a2) => {
    let retval = 0;
    for ( let i=0 ; i<a1.length ; i++ )
      for ( let j=0 ; j<a2.length ; j++ )
        retval += is_prime(a1[i] + a2[j]);
    return retval;
  };

  const test = () => {
    if ( 1 !== is_prime(19) ) throw new Error('is_prime(19) failed');
  };

Functional style with lambda and separate test function (lambda_alt)
In the same way, the reduce+lambda-code can be improved by breaking out the prime test function. That function, but nothing else, is now testable and reausable.

  const is_prime = (n) => {
    for ( let d=2 ; d*d<=n ; d++ ) if ( 0 === n % d ) return 0;
    return 1;
  };

  const primecount = (a1,a2) => {
    return a1.reduce((sum1,a1val) => {
      return sum1 + a2.reduce((sum2,a2val) => {
        return sum2 + is_prime(a1val+a2val);
      }, 0);
    }, 0);
  };

  const test = () => {
    if ( 1 !== is_prime(19) ) throw new Error('is_prime(19) failed');
  };

I think I can do better than any of the four above examples.

Functional style with reduce and named functions (reducer)
I don’t need to feed anonymous functions to reduce: I can give it named, testable and reusable functions instead. Now a challenge with reduce is that it is not very intuitive. filter can be used with any has* or is* function that you may already have. map can be used with any x_to_y function or some get_x_from_y getter or reader function that are also often useful. sort requires a cmpAB function. But reduce? I decided to name the below functions that are used with reduce reducer_*. It works quite nice. The first one reducer_count_primes simply counts primes in a list. That is (re)useful, testable all in itself. The next function reducer_count_primes_for_offset is less likely to be generally reused (with offset=1 it considers 12+1 to be prime, but 17+1 is not), but it makes sense and it can be tested. Doing the same trick one more time with reducer_count_primes_for_offset_array and we are done. These functions may not be reused. But they can be tested and that is often a great advantage during development. You can build up your program part by part and every step is a little more potent but still completely pure and testable (I remember this from my Haskell course long ago). This is how to solve hard problems using test driven development and to have all tests in place when you are done.

  const is_prime = (n) => {
    for ( let d=2 ; d*d<=n ; d++ ) if ( 0 === n % d ) return 0;
    return 1;
  };

  const reducer_count_primes = (s,n) => {
    return s + is_prime(n);
  };

  const reducer_count_primes_for_offset = (o) => {
    return (s,n) => { return reducer_count_primes(s,o+n); };
  };

  const reducer_count_primes_for_offset_array = (a) => {
    return (s,b) => { return s + a.reduce(reducer_count_primes_for_offset(b), 0); };
  };

  const primecount = (a1,a2) => {
    return a1.reduce(reducer_count_primes_for_offset_array(a2), 0);
  };

  const test = () => {
    if ( 1 !== [12,13,14].reduce(reducer_count_primes, 0) )
      throw new Error('reducer_count_primes failed');
    if ( 1 !== [9,10,11].reduce(reducer_count_primes_for_offset(3), 0) )
      throw new Error('reducer_count_primes_for_offset failed');
    if ( 2 !== [2,5].reduce(reducer_count_primes_for_offset_array([8,15]),0) )
      throw new Error('reducer_count_primes_for_offset_array failed');
  };

Using recursion (recursive)
Personally I like recursion. I think it is easier to use than reduce, and it is great for acync code. The bad thing with recursion is that your stack will eventually get full (if you dont know what I mean, try my code – available below) for recursion depths that are far from unrealistic.  My problem can be solved in the same step by step test driven way using recursion.

  const is_prime = (n) => {
    for ( let d=2 ; d*d<=n ; d++ ) if ( 0 === n % d ) return 0;
    return 1;
  };

  const primes_for_offset = (a,o,i=0) => {
    if ( i === a.length )
      return 0;
    else
      return is_prime(a[i]+o) + primes_for_offset(a,o,i+1);
  }

  const primes_for_offsets = (a,oa,i=0) => {
    if ( i === oa.length )
      return 0;
    else
      return primes_for_offset(a,oa[i]) + primes_for_offsets(a,oa,i+1);
  }

  const primecount = (a1,a2) => {
    return primes_for_offsets(a1,a2);
  };

  const test = () => {
    if ( 2 !== primes_for_offset([15,16,17],2) )
      throw new Error('primes_with_offset failed');
  };

Custom Higher Order Function (custom_higher_order)
Clearly reduce is not a perfect fit for my problem since I need to nest it. What if I had a reduce-like function that produced the sum of all NxN possible pairs from two arrays, given a custom value function? Well that would be quite great and it is not particularly hard either. In my opinion this is a very functional approach (despite its implemented with for-loops). All the functions written are independently reusable in a way not seen in the other examples. The problem with higher order functions is that they are pretty abstract, so they are hard to name, and they need to be general enough to ever be reused for practical purposes. Nevertheless, if I see it right away, I can do it. But I don’t spend time inventing generic stuff instead of solving the actual problem at hand.

  const is_prime = (n) => {
    for ( let d=2 ; d*d<=n ; d++ ) if ( 0 === n % d ) return 0;
    return 1;
  };

  const combination_is_prime = (a,b) => {
    return is_prime(a+b);
  };

  const sum_of_combinations = (a1,a2,f) => {
    let retval = 0;
    for ( let i=0 ; i<a1.length ; i++ )
      for ( let j=0 ; j<a2.length ; j++ )
        retval += f(a1[i],a2[j]);
    return retval;
  };

  const primecount = (a1,a2) => {
    return sum_of_combinations(a1,a2,combination_is_prime);
  };

  const test = () => {
    if ( 1 !== is_prime(19) )
      throw new Error('is_prime(19) failed');
    if ( 0 !== combination_is_prime(5,7) )
       throw new Error('combination_is_prime(5,7) failed');
    if ( 1 !== sum_of_combinations([5,7],[7,9],(a,b)=> { return a===b; }) )
       throw new Error('sum_of_combinations failed');
  };

Lambda Functions considered harmful?
Just as there are many bad and some good applications for goto, there are both good and bad uses for lambdas.

I actually dont know if you – the reader – agrees with me that the second example (lambda) offers no real improvement to the first example (imperative). On the contrary, it is arguably a more complex thing conceptually to nest anonymous functions than to nest for loops. I may have done the lambda-example wrong, but there is much code out there, written in that style.

I think the beauty of functional programming is the testable and reusable aspects, among other things. Long, or even nested, lambda functions offer no improvement over old spaghetti code there.

All the code and performance
You can download my code and run it using any recent version of Node.js:

$ node functional-styles-1.js 1000

The argument (1000) is N, and if you double N execution time shall quadruple. I did some benchmarks and your results my vary depending on plenty of things. The below figures are just one run for N=3000, but nesting reduce clearly comes at a cost. As always, if what you do inside reduce is quite expensive the overhead is negligable. But using reduce (or any of the built in higher order functions) for the innermost and tightest loop is wasteful.

 834 ms  : imperative
874 ms  : custom_higher_order
890 ms  : recursive
896 ms  : imperative_alt
1015 ms  : reducer
1018 ms  : lambda_alt
1109 ms  : lambda

Other findings on this topic
Functional Programming Sucks


Fix broken Marshall Stanmore

First I want to be clear, this post is about fixing a broken Marshall Stanmore speaker by turning it into an active loudspeaker. It is not about repairing it to its original functionality.

My Marshall Stanmore died after about two years of little use. One day it simply did not turn on. Completely dead. It seems to be a common fate of those loudspeakers and there seems to be no easy fix. I opened up the loudspeaker and quite quickly decided that I would not be able to repair it.

I felt very certain that the loudspeaker elements themselves were not broken. The loudspeaker looks and sounds quite good and it is against my nature to just throw such a thing away. So I started looking for ways to make a working active loudspeaker of it (allowing to use it with an iPhone or as a computer speaker). Since I thought this was a fun project I was willing to put some time and effort into it. But a brand new Marshall Stanmore is 200 Euros so the fix had to be significantly cheaper than that.

2.1
The Stanmore is a 2.1-loudspeaker. It has two tweeters and one woofer. The cutoff frequency is 2500Hz meaning that the tweeters are responsible for higher than 2500Hz frequencies and the woofer for the lower frequencies. There are different ways to properly produce 2.1 audio from a 2.0 signal. If I remember correctly the tweeters are rated at 2x20W and the woofer at 40W. I don’t know the impendance (Ohm).

The thing not to do
It is not a good idea to just simply connect L+R and connect it to the woofer. Regardless whether you do this before or after the amplifier you will drive current into components that are only supposed to produce a signal and this can destroy your equipment (your smartphone or computer pre-amp, or your amplifier).

Cutoff filters
There are special cutoff filters to split a signal into a lower and a higher part. I looked into this first, but it seemed a bit to advanced (expensive and complicated) for my project, and the problem with mixing L+R remains.

2.1 Amplifiers
There are 2.1 amplifiers to buy. The problem is that they are designed for use with a subwoofer (very low frequencies), not our 2500Hz woofer. This may or may not be a problem.

Mono
If I had a mono amplifier (that accepts stereo input and produce mono output) I could connect all the three loudspeakers to the same output. Since the distance between the tweeters is less than 25cm I don’t think the lack of stereo-tweeters will matter. However, it was not very easy to find suitable mono amplifiers (or “bridged amplifiers” that can be used as a mono amplifier).

Two-trick-solution
In the end I decided to go for a simple solution based on two parts.

First, pre-amp, it is very easy to convert stereo to mono. The only thing needed is two resistors (470 Ohm, or something close to that).

Second, a 2.0 amplifier can drive the tweeters on one channel and the woofer on the other (that is 40W on each channel).

Cleaning out the Stanmore
I removed (unscrewed) the back of my Stanmore. When I was done with it, the only thing that remained (and in place) was:

  • The box itself (except the back of it).
  • The three loudspeaker elements, and as long cables as possible.
  • The top golden colored control panel (because removing it would not make anything pretty) and the board attached to it (because it was hard to remove).
  • The cable (black+white+red) from the 3.5mm connection on top of the loudspeaker.
  • The 4 red cables from the on/off-switch.

What I also needed
This is a list of other components I used

Assembly
I neatly connected everything in a way that it fits nicely inside the Stanmore.

  • DC-power to two red cables connected to Stanmore power switch
  • The other two red cable to Jtron board (make sure to no reverse!)
  • One Jtron channel connected to yellow+black of woofer
  • One Jtron channel connected to red/blue+black of tweeters
  • Black of 3.5mm connector to Jtron input (middle)
  • Red/white of 3.5mm connector connected via two 470 Ohm resistors
  • From between the resistors, connect to Jtron input (left and right)

This is what I got:

As you can see the Jtron is pretty small.

For now my laptop DC supply is outside the Stanmore and there is just a little hole in the back for the cable.

Operating
The power switch on top is operational and I connect my audio source to the 3.5mm connection on top. The Jtron knobs work as expected (there is no balance).

About the Jtron
The Jtron was very good price and I thought 2x50W was kind of optimal for me. Also, it is a digital amplifier with high power efficiency (little excess heat). There are obviously many other options.

Serial vs Parallell
I connected my tweeters in parallell. I suppose they could have been used in series instead. Perhaps serial would have been more safe: impendence would be 4x higher, which would be less demanding on the Jtron.

Review
Well, I shall not review my own work. To be honest I have not fixed a new back plane yet and I think not having it in place is far from optimal for audio quality. Despite that, the Stanmore sounds very decent. It plays loud enough for me (perhaps louder than before). You probably want to experiment with bass/treble until satisfied. The way I use it (with an iPhone) I will set preset volume to loud, and mostly use the iPhone to control volume.

What I have lost compared to the original Stanmore is RCA-input, bluetooth and volume/treble/bass on top of the unit. I can live with it.




SonarQube 6.5 – Mac OS X – Installation problems

It seems SonarQube 6.5 does not work with JDK 9. Java 8 upgrade 144 works fine.

There is no automated way to uninstall JDK 9 properly, but you can have different Java side by side. This is how to pick Java version.

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home

After that you can run

sonar.sh start

as usual.

Can not log in to SonarQube 6.5 on Mac OS X with default password
With JDK 9 authentication with default user/pass admin/admin fails. It turns out the error HTTP code is 500, not 401, which made me suspicious.

Syncthing: breaking upgrades

Syncthing is usually very easy to upgrade: it upgrades itself silently or via apt-get. Problem is, when it changes version (lastly from 0.12 to 0.13) it is not compatible anymore. It is not a big problem since it is easy to upgrade, but you kind of have to upgrade your entire Syncthing cluster at the same time, otherwise you get an undesired fork.

This was the quite confusing error message i got on the newly updated system that failed to connect to non upgraded systems:

[THC2C] 19:17:52 INFO: Failed to exchange Hello messages with <ID> (<ADDRESS>): EOF

So, be mindful when upgrading syncthing so you dont get a non breaking upgrade when you dont have time to upgrade everything.

Syncthing on Android

I installed Syncthing a few weeks ago. Now I found it was time to connect my Android mobile to it. Installing Syncthing via Google Play was easy. Configuring it, not that easy. The amount of useful error messages… close to zero.

I found:

  1. When I manually write the address to my other syncthing unit (like my NAS), only IP address works (with :port after it). Writing a domain name fails.
  2. When sharing a folder, I can not share a folder on the SD card: I get something like “Error (100%)”. To me, this is a pity, because I could put a big SD card (32-64GB) and have synchronised music there… but it seems not possible.

Update 2015-11-14: Upgraded to new syncthing version (0.12.2). Syncthing (for Android) now does not start properly. It just keeps “Loading”. No error message. No way to interact with it.

Lighttpd, Debian and CGI

I installed lighttpd in Debian (Jessie), and I wanted CGI to work.

The Welcome/Placeholder page has some information, and part of it is:
CGI scripts are looked for in /usr/lib/cgi-bin, which is where Debian packages will place their scripts. You can enable cgi module by using command “lighty-enable-mod cgi”.

This appears to just not be true. CGI-programs worked perfectly when placed /var/www/html/cgi-bin, but not in /usr/lib/cgi-bin (or /var/www/cgi-bin). This is with default configuration.

Upgrading ownCloud 7.0.4 to 8.1.1

I am running ownCloud on a Debian machine with Mysql and I have been a little behind with upgrading it. Today I upgraded from 7.0.4 to 8.1.1 following the standard instructions. A few more notes on my environment:

  1. I don’t use encryption for files
  2. I don’t use https/ssl (I am behind an openvpn server)
  3. I did the upgrade in one step (7.0.4 to 8.1.1, not via intermediate versions)

It basically went fine. When I ran:

$ sudo -u www-data php occ upgrade
ownCloud or one of the apps require upgrade - only a limited number of commands are available
Checked database schema update
Checked database schema update for apps
Updated database
Disabled 3rd-party app: calendar
Disabled 3rd-party app: contacts
Disabled 3rd-party app: documents
Updating  ...
Updated  to 0.7
Updating  ...
Updated  to 0.6
Updating  ...
Updated  to 1.1.10
Updating  ...
Updated  to 2.0.1
Updating  ...
Updated  to 0.6.2
Updating  ...
Updated  to 0.6.3
Updating  ...
Updated  to 0.6.0
Update 3rd-party app: calendar
Exception: App does not provide an info.xml file
Update failed
Maintenance mode is kept active

I am a little surprised, because I don’t remember calendar, contacts and documents being 3rd party apps before (?). Anyway, the server did not come up, so I ran the command again:

$ sudo -u www-data php occ upgrade
ownCloud or one of the apps require upgrade - only a limited number of commands are available
Turned on maintenance mode
Checked database schema update
Checked database schema update for apps
Updated database
Update successful
Turned off maintenance mode

Now it worked. Logged in, no traces of the three 3rd-party apps. Whatever, I use ownCloud for the files.

Performance after upgrade
ownCloud is not particularly fast. I did a very quick and unscientific performance check: before upgrading I uploaded a folder (17 files, 4.1 MB) to ownCloud: it took 30 seconds (for the desktop client to complete syncing). After the upgrade the same folder took 19 seconds to sync. This proves nothing of course, but at least it seems promising.

Ubuntu Client
My Ubuntu client used ownCloud vs 1.7. It does not work with 8.1.1. Installing ownCloud client from external repository worked fine. Same thing for Debian, obviously.