Cascadia Code Looks Lovely

cascadia.png

I’m a very old programmer. I can remember when “Courier New” was the monospaced font that everyone was using. Then came “Consolas” which I still really like.

And now we have “Cascadia Code”. I’ve decided that this typeface is one of the reasons that I like Microsoft Terminal so much. It is the default font used by that program. I think it looks really good. There’s a whole family of Cascadia fonts including some very nice “light” monospaced fonts. Well worth a look if you want to spruce up your documentation a bit.

Microsoft Terminal is Awesome

microsoft terminal.png

Of late I’ve been spending quite a lot of my time in Windows PowerShell. One of the things that drives me a bit nuts about it is the horrible choice of colours for errors and whatnot. I’ve quite often found myself having to cut the text out of the window and paste it into Notepad just so I can read it with proper contrast. Colour combinations such as dark red on dark blue don’t work well for me. Perhaps its my age.

Anyhoo, I’ve found a way round this which works really well. It’s called Windows Terminal and you can download it from the Windows App store. It has tabs so you can have multiple shells open in the same window - which is great if you’re talking to several remote systems using ssh. It uses the same colour scheme but for some reason the text looks a lot better. It has awesome profile support that you can fiddle with and customize to your heart’s content. It also lets you use images as the backdrops to your terminal sessions.

Well worth a look.

Horrid little emails

horridemail.png

I’ve been getting these horrid little emails for a while. The one above is from a “quantum astrologer” called Roxanne. According to the message in the email the man in my life has “has done things in his past that are resurging today making him cold and distant...”. Blimey. Maybe what she really wants me to do is click the link at the bottom to “make sure that I don’t receive any emails from us”. Ugh.

Some things can be more fixed than they need to be...

Waking up in a toasty warm house is all very well, but perhaps not at 2:00 am in the morning.

It got so cold last night that the heating decided it needed to heat things up. So it did. In the middle of the night. I’ve now adjusted the night-time trigger levels so that the heating only comes on when it gets properly artic code at night.

Hopefully the next post here won’t be heating related.

Some things need fixing more than once....

A while back I fixed my central heating. And yesterday I did it again. It turns out that having a device that turns on the heating system is good. But having a heating system that actually heats when turned on is even better. The valve that actually lets warm water flow round the house was sticking, resulting in cold toes for Robert. Not a good thing. So now I am a little bit poorer, but a whole lot warmer.

Self destructing setting storage

lids.jpg

It turns out that creating useful embedded devices seems to be around 80% setting storage and management. I’ve created a nice little setting manager that exposes the settings as C structures, stores them in EEPROM and allows settings to be updated via JSON messages or via direct commands. Settings are bound to the process or sensor that needs them and it works well.

I thought it might be nice to be able to make a complete dump of all the settings so that I can configure a device by sending them all once. This mostly worked. The mostly bit was caused by the way that the settings are stored in EEPROM as they are received. Writing to EEPROM takes quite a long time, certainly longer than setting information takes to arrive down the serial port. So my program loses track of the inputs and misses some setting values.

“No problem” I thought. I’ll create a new setting that tells my device not to persist the setting values as they are received. That way I flip this setting and receive all the values at full speed. Then I save all the settings after they have been updated.

I added the code and got it all going. It mostly worked again. This time it would store more settings but still lose the plot towards the end of the setting file. It took me a little while to work out what was happening.

The block of settings I was restoring contained an instruction to turn the setting persistence back on again. So, half way through downloading the settings the program promptly breaks itself…

Using SSL security with ESP32 and ESP8266

bigerror.png

The story so far…..

Robert has been trying to connect an ESP8266 embedded device to an Azure IoT Hub, something he has done many times with no problems. Except it no longer works. Having spent a day failing, perhaps it is time for Robert to have some success. Now read on…..

Yesterday was not a good day. Today was better. To summarise my problem: I want to use my embedded devices with Azure IoT hub so that I can exchange messages with services in the cloud. Azure IoT hub is a “proper service” in that it supports device registration and uses the Secure Sockets Layer (SSL) for connections. I’ve written my code so that it uses the secure WiFi client in the ESP8266 and it has worked before. But yesterday it broke and I couldn’t figure out why. Today I did. Go me.

It turns out that the solution is simple. Add the statement above to set your secure client to insecure mode. But why does this work and what does it do? Does it mean that my connection is no longer secure? Now read on again…..

There are two reasons for using SSL. The first is to make sure that the data that is being transferred securely. I don’t want someone to be able to peek into the packets and pull out passwords and data. The second reason for using SSL is to make sure that the devices is talking to the right host. Without this authentication it would be possible for someone to make a system that pretends to be Microsoft Azure, accept a device connection and then steal all my stuff.

The first part of the problem is solved by encryption. The systems each end of the connection use keys to encrypt and decrypt the data so that anyone watching it go past would just see gibberish.

The second part of the security, making sure my host is really Azure, is solved by certificates which are issued by certification authorities. Microsoft have a certificate for Azure and my my device can verify this. However, to make this work I have to make a copy of the public part of the certificate and store it in my device, which is not something I’ve bothered with in the past. It turns out that I’m not really concerned about someone spoofing Microsoft Azure just to see my data. There is always a balance to be struck between security and convenience, and this is where I draw the line. It may be the wrong place to draw it, but I’m OK with it so far.

This means that my devices don’t have local certificate copies. Up until recently (and with the ESP32 device) the lack of local validation doesn’t cause a problem. But something in the Arduino libraries has apparently changed (or I’m using a different library now). Anyhoo, to make it work now you have to tell the WiFiClientSecure instance created to manage the connection that you are using insecure mode. This doesn’t mean that your data is now being sent insecurely. What it means is that the device is not verifying the server any more. And then it works.

Azure IoT Hub for Free

orchids.png

Everything I achieved today I achieved before 9:30. It was all downhill after that. But I did achieve quite a bit. I’m making a bunch of connected devices and I want to use MQTT to link them together. I could set up my own MQTT broker on a local Raspberry Pi but that would only work around my house and I want these to work around the world. My weapon of choice for these things is Azure IoT hub which lets you connect remote devices to a central server (the clue is in the name).

It turns out that you can set up a Microsoft Azure account for free and then create an IoT hub which is also free and allows for up to 8,000 messages per day. I’m not sure how many messages I’ll need, but I’m hoping that will be enough for now.

Having created my free IoT hub the next thing I wanted to do was connect my devices to this. I’ve done it before and it worked just fine. I did it today and it didn’t. This was the cue to spend most of the day (or at least the portion up to the point where I gave up) trying t figure out why. Unsuccessfully. Wah.

It's the hope that kills you...

Today I saw the ultimate in error messages. I wasn’t doing anything particularly adventurous, just trying to play a video file. However, the error really scared me. I wish I’d taken a picture of it. The error said:

This video cannot be played. Please try again later. 

Such evil in 9 words. The video file was eminently playable, this device just couldn’t play that particular format. One of the things about computers that I like the most is the way that given the same inputs a computer will produce the same outputs. The error flies in the face of this, raising the possibility that next time you run the program it will work. I’m wondering if this is a reference to the possibility that in the future a later version of the program will be able to do it. Or that the program might learn how to do it? Or that in a parallel universe it actually does work. Who knows?

Most football fans will tell you that for a supporter it’s the hope that kills you. Hoping against all the evidence that this season will be “the one” even though you have a feeling in deep in the pit of your stomach that actually it won’t be. Perhaps this is a new trend by software developers to encourage users to keep coming back and trying again….

New MacBook Air First Impressions

Don’t try and download the PC migration tool from the Apple site. I got this.

Don’t try and download the PC migration tool from the Apple site. I got this.

It is always a bit of a worry when a new device becomes available just after I’ve got paid for some writing. That has just happened with the new MacBook Air. I was thinking of getting a new tablet and this would work out at around the same price once I’d bought a keyboard and everything else you seen to need. I also fancy having a go with GarageBand. I’ve only bought the cheapest MacBook because everything seems to be based on the same processor, the Apple M1 device.

I’m intrigued by the possibilities presented by the new processor. Many years ago I had one of the first ever tablet PCs powered by a Tramsneta Crusoe chip. The idea was that clever circuitry would “morph” the intel instructions into Transmeta ones as the program loads so that a simple low-powered RISC chip could be used in a portable computer.

The idea might have been a good one but the reality was horrible. You could actually watch (and wait for) on screen buttons going in and out when you clicked them. Programs took ages to “wind up” when you opened them and the whole thing was very painful to use.

No such problems with the MacBook Air. It fairly whizzes along. I’ve got Microsoft Office running and even though the Mac is using the Rosetta2 application to convert the Word code from Intel to Arm there’s no perceptible lag and the everything so far is very snappy. I’ve installed Visual Studio Code and that works a treat too.

The only problem that I’ve found is that an issue with “Big Sur” - the new Apple operating system - seems to have broken deployment to ESP devices. The espytool.py program that builds images and sends them to devices fails because the Python pyserial library doesn't work properly. There is a sort of fix, you can find it here, but it is a bit of a pain. The good news is that the build process goes quickly up to the point where it explodes.

I’ve moved my Microsoft ecosystem onto the new platform. OneDrive is showing me all my usual files and I’ll put Edge on next so that I’ve got the best browsing experience. It will be interesting to see how the battery life goes. What with this and the lovely Microsoft Surface Pro X which also uses an ARM processor, not to mention the impressive looking desktop cpus from AMD, these must be worrying times for Intel.

New Garage Door

We have a new garage door. Hold the front page.

Only minutes after I’d told number one wife that the previous door (which was the same age as the house - i.e. very old indeed) was absolutely fine I went outside to fetch something from the garage and one of the door support wires snapped. The effect was most impressive. The door jumped out of my hands and slammed shut. It was as if the thing was possessed. I’m pleased I wasn’t underneath it when it failed.

The new door can be opened and closed without the aid of a broom handle and lots of swearing. Which is a definite improvement.

Detecting different ESP devices in Arduino Code

This is one of these “Rob writes a blog post about something so that he can find it later when he forgets how to do it” moments. I’m writing some code using the Arduino platform that I’d like to run on both the ESP32 and the ESP8266. They both run C++ and have a lot in common. But some things are just different. For example they have different commands to ask a device for its unique ID is getFuseMac for the ESP32 and getChipId for the ESP8266.

Fortunately we can use the magic of conditional compilation to make our C++ code always do the right thing. The code below shows how it works.

#if defined(ARDUINO_ARCH_ESP32)
#define PROC_ID (unsigned int)ESP.getEfuseMac()
#endif

#if defined(ARDUINO_ARCH_ESP8266)
#define PROC_ID (unsigned int)ESP.getChipId()
#endif

The symbols ARDUINO_ARCH_ESP32 and ARDUINO_ARCHESP8266 are defined if the program is being built for the respective device. The C++ above defines a PROC_ID symbol that can be used in my code to get the right version.

FreeCad Simulator is now on GitHub

FakeFreeCad.png

I’ve made this horrible hack to make it easier to debug my Python macros that run inside FreeCad and design little boxes. It means that I can use all the lovely debugging features of Visual Studio Code to find out why my code don’t work. The hack takes the form of a few simple Python objects that fake part of the FreeCad ones and allows your macros to run in any Python environment you fancy.

If you like the idea of writing Python code that produces physical artefacts you might want to take a look at it. You can find it on GitHub here.

Star Trek: Discovery Season 3 is Awesome

discovery3.png

The first two seasons of Star Trek: Discovery were pretty good. But the third is just brilliant. It seems to be a return to a lot of the original Star Trek tropes. Rather than convoluted and long winded stories leading up to a grand finale that is a bit hard to get your head around we have a bunch of people dropped into a nasty situation and then going about doing the right thing.

Each episode so far has ended with the amount of good in the universe increasing slightly. There’s still time for a grand story arc to shuffle in and take centre stage, but for now I’m really enjoying well told free standing episodes that leave you smiling at the end. I really hope it continues this way.

Heating Fun

This is bad. No matter how well printed the labels are.

This is bad. No matter how well printed the labels are.

Did you know that if you place two Honeywell EvoHome BDR91 remote valve controllers within 300mm of each other they don’t work properly?

Neither did I. Until I woke up in a cold house and had to do some digging. Apparently the radio connections in the two devices interfere with each other. Or so the very helpful tech support person told me. I’ve moved them a nice long way apart and look forwards to continued warm toes.

Use OTADrive to remotely update your ESP devices

I’m making a bunch of devices that I’ve decided to call “clever little boxes”. I’ve taken the important first step and bought the domain name. Now I have to make everything else. I’ve decided that the best place to start is with the deployment. You might think that this is crazy, but actually it is the most important phase of your development. If I’m not able to easily update the devices in the field and manage their deployment I won’t have a product, just a demo. Also, modern product development is a continuous process. You don’t make something and ship it. You make version 1.0 and then create version 2.0 based on the feedback you get.

To help me with this I’ve started using otadrive. Once you have created an account you can store firmware images on the site and then your remote devices can download and install new firmware images from them. You’re given an access key and a web based interface for uploading firmware and managing the devices that need to be kept up to date.

You get a tiny bit of Arduino code you can drop into your device to check for new versions. It works a treat. The only snag in my mind is that the site doesn’t seem to have a business model. At no point in the process of configuring and deploying versions have I been asked for any payment. This worries me for two reasons:

  • I might suddenly be hit with an enormous price list which makes the whole thing unviable.

  • The site might vanish overnight taking with it my entire network of devices.

I’m not that concerned just at the moment though. And if things get tough I can look at this on GitHub which might be where I end up putting everything.