My name is Kristoffer Berdal, and I'm too lazy to redo my website/blog at the moment, so this is all you get. Not that I ever wrote anything on the blog anyway, I was too busy procastinating.
In my current day job I work in the Computer Security field. Most of my time elsewhere I spend as a developer of various things. I prefer Go and Python, but I have used a lot of different languages through the years.

The DIY Multimodule: Here is what you need to know

Solder things correctly fool! A few jumpers needs to be bridged for serial output.

Make sure you buy a USBASP programmer. You need to flash the latest firmware! Get a 10-pin and fiddle with it like me, or 6-pin and connect directly.

The default DSM option only enables 4 channels, and we need at least 6 if we want to control arming and flight modes with some switches as well. Choose the correct option (6 for 6 channels@11ms)

Flashing on Linux: avrdude is your dude. Quick and easy :)

I’ve been flying my tiny little Hubsan X4 quad for at least a year, replacing motors, propellers and even the frame as they broke. And that was fine, but I wanted to take the step up to something bigger and better.
A proper big quad costs a lot of money, and also requires a lot of stuff that also costs money. I was trying to keep my costs down, so I decided I would just build a small brushed quad I could use to start out flying FPV, and hopefully avoiding crashing the bigger more expensive ones into the ground too much once I got one. The parts for my bigger quad are mostly here or being shipped here as I write this, so I guess I’ll be documenting the build on that some time soon as well.

There are a lot of small brushed flight controllers out there, I’m not going to list them all since Oscar Liang already has
I chose to get a Micro Scisky board, because it’s based on the STM32 processor, which means it can run Cleanflight/Betaflight. So it’s a good entry point for learning to setup a Cleanflight based system without having a bigger quad. It would also allow me to fly in rate/acro mode, which is what you do on all the proper quads, something that isn’t possible on a hubsan.

The only problem is that the stock TX module in my Turnigy 9X radio is not capable of communicating with the FC, which speaks the DSM2/DSMX-protocol.

I could either buy a Orange DSMX/DSM2 compatible module, or I could find another solution.
I was on the fence about keeping my 9X radio at all, considering buying the popular Taranis X9D that everyone else seems to use. But, that would mean not using a perfectly good radio I already had, and while the 9X has it’s quirks, I have already spent a bunch of money improving it buying a 9XTreme board from SmartieParts, allowing me to run ersky9x, which is much better than the stock firmware.

I was talking about it with someone at the local hackerspace and they suggested I buy a multi module, a TX capable of talking many different protocols and frequencies. You can read more about the module here on GitHub, and here on RCGroups.

You can either build it yourself, or it’s available from Banggood. I ordered mine from BG May 19th, and got it 11 days later. Which is surprisingly fast, it’s shipped all the way from China.

You can find designs for 3D printing a case on Thingiverse, so that it fits nicely into the back of any radio with JR modules. It’s probably possible to purchase these somewhere as well.

This post is really about my experience with this module, and what you need to look out for, I just wanted to give it a bit of a introduction.

After receiving the module I tried binding it with the Hubsan FC, and the Micro Scisky, but neither would bind.
I was trying to bind with the module in PPM mode, because I had heard that the modules banggood ship out had really old firmware, and the firmware in my 9X was too new so they could no longer communicate due to a protocol change.

Banggood sells these with really old firmware !! If you are buying one of these modules, also buy a USBASP programmer, so you can flash the latest firmware!

Unless you already have one, order one at the same time you order the Multi module. You will need it to flash new firmware onto the device. Make sure you either get one with a 6-pin cable, or you can fiddle like me with a 10-pin one and some wires. It’s doable, but with a 6-pin you could just connect it directly. Here is a website with a 6-pin diagram, and here is the same website with a 10-pin diagram. Using those two you can easily see what needs to be connected where. Make sure you get it right, I did it entirely mirrored the first time compared to what I should have done. It took me a while to figure that out.

I have one of these, it doesn’t really matter where you get it from as long as it supports 3.3V

When you are soldering the jumpers together, make sure you do it right and you have a good solder connection

As the picture says. Solder those two jumpers, so that they look like they do in the picture. I did a bad job here, and noticed after a lot of debugging that one of the jumpers was not connected properly, and that’s one of the reasons why it was not working. This is the relevant section of the README
It’s not hard, just use a small tipped soldering iron (or try with your huge tip, good luck!), and a tiny bit of solder to bridge them. Make sure you do not bridge them sideways, it’s easy if you add too much solder.

Flashing the firmware on Linux? Use avrdude
I just used avrdude here on Debian, it wasn’t complicated and you need no drivers.

This is the relevant section of the README
That’ll do the trick most likely. If you have connected it wrong, you’ll spend a lot of time getting a error message. The warning about the usbasp firmware being out of date can safely be ignored. :-)

After doing all this, I still couldn’t bind with anything. It turns out I had the protocol selector dial 180 degrees wrong. So it wasn’t at 0 like I thought, but at 7 or 8.
Make sure the protocol selector switch is at 0, and not 180 degrees wrong

There was another problem though, even though I had configured one of the switches on the controller to channel 5 (AUX1), the flight controller never saw this.

But looking closer at the DSM2 section of the documentation, I saw that you could change how many channels the module uses with the option setting.
I had not touched that, so it was on the default option 0, which means 4 channels at 22ms frame rate. 4 channels is not enough for A E T R (Aileron, Elevron, Throttle and Rudder) + AUX1 and AUX2. I have mine set to option 6 now, which is 6 channels @ 11ms framerate.

After changing that Cleanflight picked up the AUX channels just fine, and I was able to make one of the switches ARM the quad.

Now it works perfectly, and I am able to fly my Hubsan and the Micro Scisky. I have not done a range test yet, since I mostly fly indoors or right outside the house, but for things like that it’s brilliant!

Rewriting the Gophers invite form in Go

We had been using slackin for a while now to invite people to the Gophers Slack, and while it had been working okay, it had not been optimal.

For those of you who have not seen slackin before, it looks something like this:

If you want to join us on Slack, visit the invite form to get invited!

At the time I started writing this post the invite page was hosted on the Heroku free tier, mostly because I was lazy and there was a nice shiny “Deploy to Heroku”-button in the slackin README.

For the amounts of traffic the website gets, this should not have been be a problem. But slackin is written in Node.js, and somehow it was regularily using 200% of the allowed RAM. I would get lots of emails warning me, and the app would get killed by the OOM-killer.
This was a problem for us, because whenever the form stops working, people can’t get in, and we get emails from them and we end up inviting people manually. Which is exactly the reason why we wanted a invite form in the first place.

In his 2008 blog post ‘Hardware is Cheap, Programmers are Expensive’, Jeff Atwood said

Given the rapid advance of Moore’s Law, when does it make sense to throw hardware at a programming problem? As a general rule, I’d say almost always.
– Jeff Atwood

It’s the typical IT answer. It’s efficient enough, just buy more servers!
We could have upgraded to a beefier dyno with enough memory, but that would not have solved anything if the node application had a memory leak causing it to use more memory. And I am not a fan of Javascript at all.

Since I had wanted to rewrite everything in Go for a long time, I took this as an opportunity to do just that, and here we are!

Most people miss Opportunity because it is dressed in overalls and looks like work.
– Thomas Edison

I spent some time earlier this year integrating ReCaptcha, so I was already semi-familiar with the slackin code base, and I had a good idea of what needed to be done, so I just started writing a backend in Go, figuring I’d steal the entire frontend and that bit would require minimal changes.
It is not a complicated website. All we need is a form, and something that parses that form, and something to validate the recaptcha, and make calls to the Slack API.

As you can see below, the author of slackin chose to generate HTML using node, and not a templating language. I have no idea why he would do such a thing, because it does not look any cleaner at all.
But luckily we do not have to deal with that, since we can grab the generated HTML by visiting the website!
I have just stolen the generated HTML, some javascript client code, and the CSS styling to make it look identical.

We ended up with about 200 lines of Go code. To be fair, this does not replicate all of the features in slackin. I did not bother with the badges or websockets (for live user count updates), simply because we did not really use those.

I saw that we did get a lot of traffic to the websocket URL when I deployed this new codebase, so it is possible someone has a badge for our Slack visible somewhere that is not working.

Here are some graphs that show memory usage and response times of both versions. It’s not entirely a fair comparison, since the Go version does not implement any of the websocket functionality, but I’m fairly sure we could still use less memory than Node does ;-)

First we can compare the memory usage between the Node and Go versions:

Node Memory Usage

Go Memory Usage

As you can see, the Go version uses about 200MB less RAM. It’s a bit hard to see in the graph there without a scale.

Next we compare the response time:

Node Response Time

Go Response Time

Go uses less memory and is quicker to respond to requests.
Additionally, it makes the developer happier he does not have to deal with node.js. :-)

The Go version also uses the expvar package to give us nice metrics that can be graphed by anyone. Read about using the expvar package here and here

I have mine pushed into a InfluxDB instance using Telegraf.
Looking at the data in Grafana I can get nice graphs like this, for any timespan:

The only big question that remains is why the Node app was using so much memory.
I gave it more memory and let it sit without any traffic for a few days, and it still managed to use up all the available memory.

When I have time I am going to figure out why, but that will come as an update post later.

The Go Community Slack is a nice place!

Creating a website/blog in Go

April 21, 20163 minute read (819 words)

It’s actually not that hard

All you need is net/http, and Go’s built in templating, html/template, and a few other packages to make things nicer.

This website is a decent example. I had a entirely static website, but I wanted to be able to write posts in markdown.
There are a lot of static site generators that work just fine, like Hugo, or Jekyll, but I wanted to be able to play with Go an various things like React.
I can’t do that with an entirely static website, and while I could probably get it working with one of the generators and some Cross-Origin Resource Sharing headers, I decided I would just write my own.

Yes, I know. One more! But it’s my website, so whatever.

This is a really simple website.

main.go is about 40 lines long, and the web package is about 200 lines long, including a bunch of helpers that could have been their own package.

This is really a example of how elegant a web application in Go can be. I’m sure there is room for improvements, but reading this code it’s fairly easy to comprehend what it does, provided you know what a router is.

I am using the httprouter package here, because I wanted to try it out, but the net/http mux is usually good enough for most things, you just need a bit more boilerplate code.

Middleware

httpLogger is an example of HTTP Middleware in Go. It uses the log package to print a line per request, and outputs this per request>

And that is all it does. You could easily write middleware to handle authentication, or set a custom HTTP Header, or do whatever you wish.
Alex Edwards has written an excellent guide about this on his blog.

Handlers

The web package holds the web handlers (for lack of a better name), there are only two. One renders the index page, and the other renders a single post.

And that’s it really! There is not much more to show. There is some magic that watches the posts folder and reloads the posts if there is any changes, but that is not yet working because of an unknown bug in fsnotify.

I will publish the code once it’s in it’s final form. Maybe someone else can use it to create a site of their own, and it’s not entirely a waste of time :-)

It seems OSX has screwed up my drive! And a while back I managed to kill the logic board in my Macbook Pro, so both USB ports are dead, which means I can’t connect the disk back to unmount it properly.

I have tried mounting the drive on Windows, but Windows just tells me I need to format the drive. This has been a problem for a few months, since I did not want to reformat the drive as I have things on it want to keep.
A few days ago my new ZyXeL NAS arrived, and I needed the drive to begin transfering files. So I began searching for a solution again, and this time I was lucky! It turns out the problem on Linux is with the FUSE exfat driver.

Sadly FUSE has been the only way of mounting exfat drives on Linux for a very long time, but not any more! Someone brilliant started porting the native exfat/vfs kernel driver from Android 3.0 to normal Linux systems. The kernel driver is called exfat-nofuse, and it works brilliantly. This also seems to ignore the bad unmounting from OSX, allowing me to mount the drive and get my files out!

Make sure to uninstall the exfat-fuse related packages you have installed, or it won’t work.

TL;DR: Remove the exfat related packages for FUSE, install exfat-nofuse, and you should be able to mount your disk again.