Debugging with Magic

Trying a new blogging approach. Blogging when I have something to say, rather than fretting about making a post every day……

Only a code magician can fix a program by renaming a variable. That’s me.

I’ve just encountered an hilarious (and by hilarious I mean horrible) bug with an upgrade to the ESP8266 compiler. I’ve been building my Connected Little Boxes software for quite a while now and it just works. Today I noticed that I had upgrades to the Espressif SDK in Platform IO. So, like a fool (and I do mean that) I pressed OK to upgrade them.

And suddenly my newly built program broke. It would start running and then spontaneously explode with Exception(29). Which means that my program is twiddling a memory location that is not where it should be.

First step was to recompile the code for the ESP32 processor (my code works on both). That worked fine. OK, so it is not necessarily something stupid that I’ve done. Back to the ESP8266.

It’s hard to debug code running in a separate device, but after a few minutes (I am pretty good at this - although I was slowed down as bit by the way that the bug vanished when I enabled debug mode) I’d isolated it to this statement:

RegistrationProcessDescriptor.status = REGISTRATION_OFF;

It runs during startup and turns off the registration process. But I guess you’d already worked that out because my commenting game is so good. Anyhoo, when this statement runs the device explodes.

OK. Welcome to planet weird. First thought is that RegistrationProcessDescriptor is not pointing to the right place. But it is. Otherwise the call to the exploding function would not have worked. So, second thought is that REGISTRATION_OFF is a silly value. It isn’t. It’s 1004 since you asked. And status is an integer property in case you were wondering, so everything make sense and the code has been working perfectly for ages…..

Of course I’ve fixed it. I’ve renamed the variable RegistrationProcessDescriptor to RegistrationProcess. Something deep in the compiler must be getting upset about long variable names and dropping dodgy code. There were a few clues:

  • It works with a different compiler

  • It worked when I changed the code a bit (by adding debug)

  • The variable name was a bit longer than ones I normally use

I’m not happy that the problem occurred, but I’m pleased I was able to fix it.

Bye bye to the piano

insidepiano.jpg

I said goodbye to over 50 years of my past today. Two men came and took away the piano. Our family got it in the 1960s and I, and my sister did our piano practice on it. Then it found its way into our house and we inflicted piano lessons on our kids too. It has been a fixture in our house every since.

It’s been rather neglected for the past few years though. It was heralded as an interesting instrument when it was launched because it used a novel, weight-saving design to mount the keys. Unfortunately this design also meant that after a while all the plastic key mountings fell to pieces giving the instrument a rather snaggle toothed appearance and making the keys not work properly. Then the felts all got sticky so that notes would play forever so for the last while it has been a nice ornament but not really useful. So we decided to get rid of it and get something more up to date that we might actually play. This was done with a heavy heart, but you have to keep moving forwards in this life.

I asked the man who took it away if it would go to a good home. I had a vision of some kind of retirement home for pianos where they could see out their days with plenty of tunes and whatnot. “Well”, he said “we’ll melt down the frame and turn the case into firelighters”. Oh well…

Ratchet and Clank - A Rift Apart

ratchet and clank.jpg

I’ve just spent nearly seventy quids on a video game. Oof. That ‘s a lot of money. And I haven’t got anything to show for it. Just an entry on a server somewhere in the land of Sony noting the fact that they have just made me a bit poorer. My PS5 is one of the ones that doesn’t have a disk drive. I was very happy to get it back last year when they were very hard to source. I don’t buy many video games. This is the first one I’ve purchased since the first week of ownership. I find that the PlayStation Plus monthly subscription gets me enough new toys to play with. However, I’d been planning to get this game since the console came out.

It is very good. The only jarring note for me was the way that the first screen I saw after downloading (a 45G download in about 12 minutes or so - thanks KC) was one offering me a chance to spend an extra 10 quids on the “deluxe” edition of the game. As if. However, the gameplay, the writing and the effects are very impressive. Movie impressive. They’ve used all the colours in their paint box, plus a few new ones, to make a bright and vibrant environment for you to blast your way through. I’ve not played it for that long, but I know enough to want to play it through to the very end. Then I want to go back through again and spend more time looking at the scenery.

And I seem to remember that when the first PlayStation came out all those years ago some of the games were nudging 60 pounds or so a pop which, allowing for inflation must have been a sizeable chunk of change back in the day.

Project Blogging for Fun

flowersburnby.png

It’s been a bit quiet on the blog for the last few weeks. I always said that I blog because I want to force myself to do interesting things so I can write about them. Recently there have been so many interesting things going on that I’ve not had time to write the blog, which is an interesting problem. Or perhaps I’ve persuaded myself that I’m too busy to blog…

That is going to change a bit now though. I’ve decided to experiment with “project blogging”. I’m going to take the thing I’ve just done, which is create some JavaScript code that runs in a web page and can load code into ESP devices, and write it up. I’m doing this retrospectively from diaries that I kept during the development process. If you’re a programmer it might be an interesting read. The posts will appear around the time I did each task. I’ve tidied things up a bit to reduce the number of dead ends and whatnot.

They start around here. If you then click the left hand link at the bottom of the text on each post you can move through them in order. There will be other topics here and there too, and some pictures. You can just see the project posts by using this link.

I’d love to know what you think of it and how I can improve the presentation content. Feel free to comment (he said dangerously).

Connected Little Boxes servo pulse

I’ve added a new feature to the Connected Little Boxes software. You can now ask a servo to move to a certain position, stay their for a specified length of time and then move back to its previous position. This makes it much easier to create devices where you want to open a lock or wave a flag.

{"process":"servo","command":"pulseservopos","value":1,"pulselen":2.5}

The command above will move the servo to the end of its travel (the value 1) and hold it there for 2.5 seconds before returning it to its original position.

Apple TV in less needy shock

Yesterday I got a nice new remote for the Apple TV. Today I noticed another improvement to the Apple TV user experience. The new remote has a prominent power button. You can use this to turn your Apple TV (and anything else connected to it) on and off.

You might think that this should not be news. It is after all what a power button should do. You are correct, but the thing is that in the past the Apple TV has always been a very “needy” device when I’ve used it. Previously, if the Apple TV was turned on and had HDMI control enabled it would to grab the foreground at every opportunity. Even if you didn’t want the Apple experience at that precise moment you seemed to have it thrust upon you.

The new device is much more relaxed. The Apple TV is happy to sit in the background until you wake it up.

Apple TV Remote

apple TV remote#.jpg

I’ve had an Apple TV for a while. I like the Apple TV. I hate the remote that came with it. The very first Apple TV devices had a lovely little silver remote that had just enough buttons to be properly useful. It was very well made and worked a treat. The next Apple TV that I got had this horrible black thing. It looked like it had actually been designed so that you couldn’t tell which way up you are holding it, so that using it involved a lot more messing around than it should. It also had a touch pad that was as useless as it was unnecessary. In short, not good.

Then, a while back, Apple announced a new Apple TV remote. As I use Apple TV a lot, i thought I’d get one. It is annoying to have to spend lumps of cash to get to a situation where you should have been at the start, but the new remote does a good job of making amends. The buttons are nice and clicky, the design makes sense and it works very well. I’m now a less unhappy customer than I was.

The Price of Greed

This post doesn’t reflect well on me. I present it as a salutary tale about greed.

When I started working on the “Connected Little Boxes” I invested in the domain name “cleverlittleboxes.com” as I thought that might work for the name of the product. Then I found out that there actually is a company called Clever Little Boxes which rather scuppered my plans. So I switched to the name “Connected Little Boxes” which is just as meaningful and ties in rather well with our “Connected Humber” project. I spent another six pounds or so on “connectedlittleboxes.com” and went on my merry way.

Last week, via a domain sharing thingy, I got word of an offer for the “cleverlittleboxes.com” domain. The mysterious purchaser was offering 199 dollars for the domain name. Visions of riches swam in front of my eyes. Or at least, enough riches to get a new iPad. So, having done some research on the domain selling site I sent back a counter proposal of around half the price of what I saw as comparable names. This is a long-winded way of saying that I got greedy.

Anyhoo, today I got a rather sniffy response from my mysterious buyer, complaining about my profiteering actions and dropping the offer to a very iPad unfriendly 50 dollars or so. Oh well. I’m going to hang on for the domain for now and see what happens.

Imagine Cup Judging

I’ve got very fond memories of the Microsoft Imagine Cup. At one point I was the captain of one of their competitions, which meant that I got to travel around the place and see awesome work from students. That was a while back. Today I spent a happy afternoon as a judge going through submissions for the junior competition. They were lovely. Some great work and some splendid explanations. The best bit for me though was knowing how much value taking part in these competitions adds to the contestants. I’m really pleased to see that the competition is still out there doing good. If you want to sign up for next year you can do it here.

Connected Little Boxes web flashing now live

flash.png

Well, that was fun. One thing I’ve always said about tricky projects is sometimes you have to “go and live there” to solve the problem. Well, that’s where I’ve been for the last month or so. I’ve been grappling with the JavaScript serial interface and the espytool with the aim of creating a website that can directly flash my Connected Little Boxes software onto a brand new ESP8266 or ESP32 device.

And I’ve finally gone and done it. If you want to put my software onto one of your devices (I’ve tested it with Wemos D1 Mini and Wemos 1 ESP32) you can go here, plug your device into your PC or laptop and then flash my software into it. For this to work you have to be using a Google Chrome or Microsoft Edge browser.

I’ve also created a simple terminal (called Simpleterm) that you can use to configure a Connected Little Box from your browser. You can find Simpleterm here. You can use Simpleterm to talk to any device that uses a serial port.

The Connected Little Boxes website will be further developed over the next few weeks to add more projects. I’d love to know what you think. And it’s nice to be back in the blog…

Thrustmaster TCA Officer Pack Airbus Edition

airbusjoystick.jpg

I first ordered the Thrustmaster TCA Officer Pack Airbus Edition last year, when the idea of flying away from everything was even more attractive than it is right now. I’d taken the precaution of ordering in good time, which I thought was a great idea, particularly when I saw the price of joysticks go through the roof. Unfortunately, the people selling me my joystick were also watching these prices. Their claims about my order status became more and more outlandish, at one point the order was marked as despatched, but then they cancelled it completely.

So that was that for a while. But, ever persistent, a few weeks ago I noticed that Scan computers were claiming to have them in stock. I thought I’d test these claims, and today the joystick arrived. Just in time for our Monday evening flying session.

It is very nice. Not the real thing of course, but good enough for me. It works beautifully with Microsoft Flight Simulator. The joystick response is very smooth and there is plenty of movement in the throttle. It even has nifty reverse thrust settings which you can use to stop your Airbus from plummeting off the end of runways that turn out to be a lot shorter than you expected.

I never had many plans for my long term future, but one of the one that I was pretty sure would come to pass is that I would always be playing with silly plastic toys. And so it has turned out.

Installing Roli Connect software on a Mac

I’m liking my Roli Lumi keyboard. It came with some rather nice programs. The Roli Studio Player program links the keyboard to lots of interesting sounds and provides some really nice control options. The Roli Studio Drums application lets you play drums (the clues is in the name).

The programs work on both PC and Mac, or at least they are supposed to. However, they failed to install properly on my MacBook Air. The installation sort of worked, but firing up the applications produced a message that a part of the system was not running. This was annoying because I could actually see the missing component in the filestore. It got even more annoying when number one son turned up with his Mac, installed the software and it worked first time. Wah.

I still feel a bit at sea when I’m trying to understand MacOS. It works OK, but I don’t know it as well as Windows. And, forgive me for saying this, MacOS seems a lot more primitive than Windows 10. Particularly when installing software. There is no well defined way of putting programs onto your system and, equally importantly, getting them off it again. Windows apps have a nice set of installation processes that also contain an uninstall component. Mac apps are installed by dragging them somewhere and then hoping that they will sort themselves out when they run. And if you want to properly remove a Mac app it seems that you have to trawl through lots of folders deleting files that might or might not be part of the installation.

Anyhoo, I digress. The Roli software didn’t work for me, but it seems to work fine for most everyone else. The Roli support people were excellent, but they were a bit hamstrung by the fact that their software worked for them too. In the end number one son fixed it, which was nice. He managed to run the program from the command line, so that he could watch what happened. And he saw this:

[08:47:58.864] [error] { code: 'EACCES',
errno: -13,
message: 'EACCES: permission denied, open \'/Users/robertmiles/Library/LaunchAgents/.com.roli.roliblocksserver.plist.a1040590be279758\'',
name: 'Error',


More importantly, he also knew what it meant. The install process is trying to drop some code into the LaunchAgents folder. This is where MacOS applications put things that they want to have launched at some point in the future. The problem was that on my machine the folder didn’t exist. What the Roli installer should have done is create the LaunchAgents folder and continue, but it didn’t. It fell over leaving things in a mess. This is a horrible bug to spot, in that if you happen to have installed other software on your machine that has created this folder the Roli software will install and run just fine. But if you are me, it breaks.

All we had to do was make a LaunchAgents folder and run the install again. If you are having problems with your Roli installation on your Mac you might want to make the folder. You can work out from the path above where on your system it needs to be put.