Sticky Scroll Wheel

If you don’t think that the little wheel on your mouse that lets you scroll up and down is important, just try working on a program without it.

It turns out to be rather difficult

My mouse scroll wheel failed today. So I changed the batteries in the mouse, then I moved the radio receiver closer to the mouse. Neither of these worked.

So I just blew hard on the wheel. Result. I’m reminded of the fun I’ve spent debugging over the last couple of days. And I’m also reminded of a saying that seems to work when programming, mending mice or even (and this is a reference to fun had years ago) fixing water leaks.

The fault is never where you think it is.

Dealing with the impossible

I’ve got a new saying that I quite like. It’s probably not original, but that’s true of a lot of stuff that I do.

If what you are observing is impossible it is either not happening, or not impossible.

I’ve found and fixed my impossible bug. Of course it wasn’t where I thought it was, because if it was, I’d have looked there and mended it. The fault wasn’t even in the code doing the job, it was in the code telling me what the system was doing.

I’d missed a break out of a C switch statement (a frighteningly easy thing to do in that language) so that my reporting code was printing out the wrong messages. Which led me to concoct all kinds of fanciful theories about memory corruption and race conditions - rather than simply checking that what I was being told was happening was actually happening.

The important thing about situations like these is that you change the way that you work to reduce the chances of them happening again. So, in future I’ll make sure that I test all the possible outputs of my diagnostic system.

Peter Principle Programming

There’s a famous management concept called “The Peter Principle” which I’ve always liked. It says that people will get promoted to the level of their incompetence. In other words, if a person is good at their job they get promoted. However, they will eventually reach a point where they are no longer good at their job, promotion will cease, and they will be stuck at that level being incompetent for the rest of their career.

I’m sure it didn’t happen to me.

Anyhoo.. I think that I may be turning into a “Peter Principle Programmer” of late. I’ve managed to create some software that has behaviours that I just don’t understand. I’ve got a bug in my latest version of the Air Quality sensor which is exhibiting behaviour that is just not possible.

Actually, having thought about it properly though, I reckon that lots of people start out in this position. One of the nasty things about learning to code is making something and having no idea what it is doing. The trick when writing code is, for me, always about trying to make it as simple as possible to understand, so that when it goes wrong you have a chance of getting your head around what is happening.

Barclays AI Frenzy Event

I’m doing a tiny session in the Barclays AI Frenzy event in February. I’m going to be showing just how easy it is to make a C# AI enabled app, starting with training data and ending up with a working program. I’m not sure how much frenzy I’m going to bring along, but I’ll do my best.

There are going to be lots of other speakers too, along with a chance to talk to a bunch of like-minded folks.

The event is on the 21st of February starting at 17:30 in the afternoon. You can sign up here.

Rob on Brexit

I’ve been agonising about writing this post for ages. On one hand I don’t want people to think that I’m the kind of person for whom the most important thing is a silly satnav idea, but on the other hand I don’t want to say something and then instantly turn half my readers against me. However I really can’t keep silent on this one. I promise that there will just be this one post, and tomorrow I’ll be back onto the daft stuff. So, here goes.

The biggest thing about Brexit for me is that quite a few people I know, admire and respect think it is a good idea. I start a conversation with them about how horrible the whole thing is and half way through they say something like “I wish we could just leave and have done with it”. Which I think is a very bad idea. I’ve rationalised this in two ways. The first is that there are some things about the EU that are very open to criticism. The second is that the UK press, lazy politicians and civil servants have found the EU a very useful thing to blame when things aren’t as good as they should be. And a lot of this mud has stuck.

I end up just going quiet on the matter, because I don’t think that Brexit is something that you should lose friends over, and I’ve not found a way of talking folks round. And it doesn’t, shouldn’t, mustn’t, make me think any less of them, any more than they should think less of me for wanting to stay in the EU.

One solution would for me to be like the chap at the end of the novel “1984”, when he actually learns to love “Big Brother”, the leader of the tyrannical state in which he is unlucky enough to live. Perhaps if I became a true believer it would would all make sense to me and I’d be happy about it, rather than the despair that I find myself in at the moment.

The way I see it, Brexit is only good for three kinds of people:

  1. The rich. It doesn’t matter to them whether the UK is in the EU, out of the EU or a smoking crater in the ground. They’re rich. They can just take their money somewhere else. But if the price of everything in the UK drops, their millions can go that bit further. And with the UK out of the EU they can bend rules and relax standards to allow them to make even more money. Which brings me to speculators….

  2. Speculators. While it is not legal to bet on a horse and then shoot all the other horses in the race, it seems that is is perfectly OK to place bets on the financial markets and then do things that drive them in the direction you want them to go. And if you are cynical enough to build up your brand at the same time you can make it into the Brexit circus.

  3. Brexit circus. This includes nasty businessmen who drive down the economy whilst profiting from this and building their horrid little brands. It also includes TV pundits who do solemn pieces to camera about “the worst political crisis since the corn laws”, having completely forgotten that their lack of due diligence when all these matters first arose has led directly to the problem. And then there are the social networks which don’t just allow falsehoods to fester, but also provide tools to better target the lies, all the time making profits. Ugh.

Anyone else is going to have to suffer through this whole affair, while the good name of the British is dragged through the mire. I never thought I’d be ashamed to be from this part of the world. I thought that folks out there would always celebrate our honesty, openness and natural tendency to try to do the right thing.

I can’t seen an end to this in the short term. I know that eventually we will be back in the EU at some point because nothing else will be found to work. But there is going to be a lot more pointless pain and upset until then. Oh well. At least I feel a bit better for having written something about it.

I rather like "The Orville"

Every now and then I wish that they still made programs like “Star Trek the Next Generation”. Well, it turns out that they do. Or at least there is one. It’s called “The Orville” and I reckon that it is worth seeking out. I got the entire series one on Apple iTunes for a knock down price and I rate it as good value. The scenario and the hokey nature of the plots are straight from the Captain Jean Luke Picard stable, but they’ve been given a nice contemporary edge with some smart dialog and neat bits of whimsy. And the characters are all essentially nice people who you end up caring about.

If you like your Sci-Fi to include machines that can make a nice cup of tea, and where things are done with good intentions, then you should seek it out.

Music to arrive to

I’ve been thinking about satnav systems and music players and I’ve decided that what would be really wonderful is a system which linked your navigation and your car music system together so that the currently playing track ends just as you turn into your drive at home.

This might be a bit tricky to arrange, but in theory the satnav knows when you’re going to arrive and could tell the music player to pick appropriate length tracks as you approach your destination.

I’m suggesting this because on the rare occasions when it happens to me I think it’s awesome. I’ve even been known to speed up or slow down slightly to make sure that it happens.

Building the Monitair Configuration Interface

I’ve got the web based configuration for the Monitair working quite well now, but it is a bit of a faff to use. You have to connect to the WiFi access point served by the Monitair device and then navigate to the web page it is hosting.

If you have got the device connected to your PC, perhaps to download the software, it would be nice if you could configure the settings via the serial interface. Well, you can now. I’m using the same data source as is used to generate the web page, and I’ve added some useful commands as well. Now you can set any of the values in a device straight after programming it, which is rather nice.

Building the Monitair Configuration Page

The new configuration web page for the Monitair sensor is taking shape. Above you can see the “home page” that the sensor displays during setup. Rather than having one enormous page of settings we now have links to sub-pages which contain different setting categories. The page is generated from a data structure so that it is very easy to add new settings.

These are the simple settings for the device. You can leave everything else at the default values and the sensor will just work on the Connected Humber MQTT broker. The only things you really need are WiFi connection details and the MQTT password. If you happen to know your location details you can put them into the form so that the sensor readings can be displayed on the map. When you click Update the settings are written into EEPROM on the device. You can use the advanced configuration pages to select things like the hardware pins that various peripheral devices are connected to. I’m rather enjoying writing this…

Cottingham Parish Council

After an awesome hardware meetup at c4di tonight Robin and I went on to a meeting of Cottingham Parish Council. We were there to talk about Air Quality, something we are quite passionate about - what with us having done quite a lot of breathing over the years.

As it happened they were discussing an air quality issue just before we were introduced, which gave us a lovely context in which to describe the work of the Connected Humber Group on designing, making and deploying sensors around the area.

Everyone was very interested and I it looks like we’ll be working together in the future on this, which is lovely.

Satnav Upgrade Fun

Whenever we drive to our favourite cinema in Beverley the journey used to take us over a number of ploughed fields. At least that is what the car navigation system thought, what with the road having been added comparatively recently.

So today I thought I’d fix that and spent a little while downloading 22 Gigabytes from the BMW servers, unpacking it onto a micro SD card and then upgrading the internal maps in the car.

I’m pleased to be able to report that all that data seems to have done the trick, and map wise things are a bit more up to date.

Christmas Code Crack Answer

I’m feeling a bit guilty about this (in so far as I ever feel guilty about anything). A while back I asked both of my readers the meaning of this cryptic message:

Yes, that is Z9 by the way. And Y5. I find the sequence fascinating. And I use it every year when I build our Christmas tree. It’s the installation order of the individually marked “branches” that clip onto the central core. If I get the order wrong the tree gets bigger as it gets higher, which is not a look that I like. I’ve no idea why the numbers are the way they are, or the mysterious need to go off into different letters and numbers in the middle of the sequence. But now it is on the blog at least I’ll not lose it for a while.

Sofa So Bad

The sofa in our living room has a few problems. Mostly these are caused by the fact that I always seem to sit in the same place when watching the telly. What can I say, it’s the perfect seat for pictures and sound.

However, my “tv sweet spot” is now 2 inches lower than the cushion next to it. We had some folks over at Christmas and when they were sat next to me they seemed to tower over me. I’m not used to people towering over me. It feels wrong somehow.

So today I’ve started the process of fixing the problem. The solution I’ve going for is what I’m going to call “cushion pinhole surgery”. I’m going to open up a seam in the low cushion, add a bunch more stuffing and then either sew the hole back up again (posh solution) or stick some duct tape over it (lazy solution).

So, today I’ve ordered a big bag of foam pieces. Soon I should be sitting pretty again.

Debugging with Rob

OK. Today I’m going to find out why my program is crashing. I’m going to do this in an “experimental” way. I’m going to put up a hypothesis (a theory about why something happens) and then try to test it. Before I do that though, perhaps I’d better describe the problem. I apologise if some of this explanation is a bit technical:

The program runs for a while and then stops.

The length of time the program runs varies, and I can’t tell what happens at the point of failure because it is inside a device. And I can’t take a look inside the program because those tools aren’t available to me.

So, let’s try my first hypothesis:

Hypothesis 1: “The program flashes the neopixel leds at the same time as it receives data from the air quality sensor. Perhaps the code that controls the lights is affecting the code that gets the data.

Test:

  • Increased speed of pixel update.

  • Loaded up the serial interface with data.

  • Increased rate of MQTT update to once per second

Results

Display update slowed right down (as we might expect) but no crash

On this basis I’ll conclude that this hypothesis is not valid. So let’s try another:

Hypothesis 2: Serial data reception is interfering with the WiFi transmission. When the device has got a complete reading from the air quality sensor it sends a message over WiFi to the server.

Test:

  • Turned off the Pixel updates

  • Loaded up the serial interface with data

  • Added code to confirm successful network message sent

Result:

When the serial data is being transmitted the data transfer is slower because the serial interface steals cycles from the processor. Eventually the transfer collapses and the Publish method starts to return false. Shortly after that the whole system falls over.

Further Test:

restored the pixels and loaded up the serial port

Result:

When the serial port is loaded the performance collapses before.

So, it is not a good idea to use the network connection while you are receiving data from the serial port.

This is because I’m using a software simulation of the hardware that normally receives serial data. This simulation has specific timing constraints that means that it needs to “lock out” other processes when it runs. And it seems that this is causing the problem. Under normal circumstances the node only sends a network message every six minutes or so, and the chances of interference are small. But when I’m doing “proper” testing - sending lots of messages and receiving loads of data - I notice the problem.

The solution is to re-work the code so that the two things don’t occur at the same time. Which means I get to write more code. Which I quite like.

You might like to know (if you’ve read this far) that the notes above actually came from my diary. I always write these things up each day. The idea is that if I get a similar problem in the future I’ll have something to go back to. If you don’t write a diary/log when you do this kind of thing you’re really missing out on a trick.

Peter Principle Programming

I seem to have the ability to write programs that are just that bit more complicated than I can get to work. I think this is an extension of “The Peter Principle”, which states that in an organisation any given person will be promoted to their “level of incompetence”. In other words, you stop being promoted when you get to the level where you can’t do the job.

I’m working on the code for the Air Quality sensor and I’m running up against the worst ever kind of fault. The one that occurs so rarely that you can’t easily cause it to happen. And if you add code to find out what is going on the problem vanishes. There are usually two possible reasons for this:

  • it is a timing bug, which occurs when a given set of events occur in a particular sequence

  • it is a memory corruption bug, where a process damages the contents of a value in memory which is picked up subsequently and causes the program to fail

I’ve done all the sensible things to try and isolate the problem. I’ve moved things around in memory to see if the fault changes. I’ve changed the order of code elements to see if that causes different things to happen. As of now, I can’t find out what is going on. Oh well, there’s always tomorrow.

Comedy Eye Test

I had to go for an eye test. I really wanted to do this as a comedy routine, but my nerve failed:

Doctor: ‘Have your eyes ever been checked?’
Me: ‘No. They’ve always been blue.’
Doctor: ‘I don’t find that very funny.’
Me: ‘Well, I do know lots of cornea jokes….’

Anyhoo, all was well. They are not going to have to shoot any lasers at my exploding eyeballs, which has got to be a good thing.

Big thanks to all the folks at the Eye Clinic in Hull who were professional, efficient and totally awesome.