Giving devices access to your private Git Repositories using SSH

A little while back I wrote a blog post telling folks (and future me) how to set up secure sockets so that you can log into remote devices without passwords and create Visual Studio Code remote sessions. Here’s the follow-up, which tells you how to use your SSL keys to give a device access to your private GitHub repositories.

I like to keep my repositories private until I’ve got them kind of sorted. This makes it tricky if I’m deploying to a newly set up remote Raspberry Pi, since it needs GitHub credentials to access private stuff. The best way to solve this problem is to put a copy of the device SSL key onto your GitHub account. It’s easy to do and works a treat. Start by going to GitHub and opening your personal Settings (the one at the top right, not the settings for a particular repository). Then click SSH and GPG keys.

You can see my keys here. Now click New SSH Key. A dialogue will appear asking for two things: the name for the key and the key itself. I use the machine name as the name. You can find the key in the file id_ed25519.pub in the local .ssh folder of your new machine. This file was created when you did ssh-keygen to set up ssh on the machine. Enter the info and close the dialogue. Once you’ve done this you can use the ssh form of git clone to grab private repositories from GitHub.

git clone git@github.com:CrazyRobMiles/custard-cream-camera.git

You’ll need to put your GitHub username and your repository name into the above command. Note that the https way of referring to repositories won’t work.

GitHub will send you an email to tell you when you’ve set one of these up. It also lets you track the last time the key was used. You can remove keys that you are not using.

Hammer Horror

I thought I’d add some lights and whatnot to my printer server. This means adding header pins to my Pi. I thought I’d use the hammer headers from Pimoroni rather than do soldering. I bought a bunch a while back because they were reduced. They are reduced at the moment too.

The idea is simple enough. Pop the Pi on the jig, insert the headers, pop the cover thing on and then bash it with a hammer until the pins are in. Except that I got a bit too keen and bashed the pins all the way through the board (don’t do this). “Never mind”, I thought. “I’ll just pull the pins back a bit and all will be well”. It wasn’t. I then spent an entire morning trying to work out why my pixels weren’t lighting up before discovering that if the pins go all the way through the board they don’t make proper contact. If you have a go with these make sure that you arrange things so that the pins don’t go very far out of the other side of the Pi.

I got the board to work by soldering all the pins into place. And on the journey to this I discovered lots of fun things about controlling neopixels from Python on a Pi. Pro tip: your code has to run in supervisor mode. It really made me want to go back to using a PICO where it all just works.

Anyhoo, I’ve got my leds working now, which is nice.

Printer fun

I’m writing an article about using a Raspberry Pi as a printer server. I’m using the cheapest Raspberry Pi, the Pi Zero W. It’s a great way of making cheap colour printing available to your household. Above is a picture of a printer printing a picture of a printer printing a picture of a printer. The thing on the right is the Pi powered print server. Two green lights is a good thing.

Ditch your passwords with Secure Sockets

Secure Sockets are super useful. And it is worth knowing how to set them up for use on a Raspberry Pi. I’m just documenting these things here so that I can refer back to this post whenever I need to remember what to do.

The situation is this: You’ve just set up a new Raspberry Pi using the wonderful Raspberry Pi Imager software. You’ve set the machine name, enabled SSL and configured the WiFi so that the Pi will wake up and connect to your network. Next you need to make it easy to connect to. Let’s start with the first part, creating an SSL identity on your new Pi.

You perform this first step on your Pi. You’re going to make a folder to hold keys and a unique key that will identify this device. The first thing you do is connect from the console on your computer (in my case a Windows PC) to your new Pi. If you’ve set the Pi up to use SSL and Password authentication (which is what I do) then you open a command prompt on your PC and type:

ssh printserver.local -l rob

The ssh command above has two arguments. The first is the network address of the machine on the local network. This is the machine name followed by “.local”. I’ve just made a new machine called printserver, so I’m going for printerserver.local. The second argument (after the -l - which is lower case L by the way) is the username that you created on the Pi. If you leave this out the ssh call will use the username from the machine you are using to connect. If you call yourself the same name on everything this will work, but it didn’t for me. I created the pi with the username “rob” because I am an egomaniac. Your name might be different.

After you have entered this command you will be asked to confirm that you want to add this machine in your local key store on your PC. You do, so say yes. Next you will be asked for the password for the user on the Pi (in my case the password for rob) and then you will be logged in as a terminal user on the machine.

Now you want to give your new machine a unique identity in the world and set up a key storage location. Issue the command below:

ssh-keygen

You will be asked a series of questions. Just press return after each of them. Now you have a key storage on your device, along with an SSH key for that device. Now you switch back to the terminal on your PC. What you are going to do now is copy the key from your PC onto your new Pi. This is good because it means you’ll be able to open an SSL ternal session without entering a password. It’s also good because any programs that want to use SSL (for example Visual Studio Code remote terminal) will be able to work seamlessly.

cat ~/.ssh/id_ed25519.pub | ssh rob@printserver.local 'mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys'

This is one long command. For the record, cat is a command to copy files, I sent mine using the username rob and to the device printserver. You will probably need to change your command. This pre-supposes that you already have keys on your computer to send. You can use the command ssh-keygen on your computer to set that up first if you need to.

If you have done everything right you should be able to login using the ssh command we saw at the top of the post and not be asked for a password. Which is nice.

Custardcream.cam

I quite like dew-lumen-shell

The Custard Cream Camera is backed by the Custard Cream server, which you can find at: https://custardcream.cam/ The camera has a “publish” command that sends pictures to the server for the whole world wide internet to scrape.

You find pictures by their unique three word address or you can just view random shots. The really interesting thing about this server is that it is running on my desk. I’m using a Raspberry Pi 5 to host everything. It’s connected via a Cloudflared connection which does all the clever mapping between the domain name (custardcream.cam) and the node.js application that hosts the site.

It really is very easy (and surprisingly cheap) to get a web presence using a tiny computer you might already own and a little bit of configuration.

Naked Selphy Fun

I’ve mentioned the Canon Selphy CP400 before. Although that time I got the name wrong. Its a really nice little dye sublimation printer which works a treat. And the paper and the ink are nice and cheap too. As part of my portable Pi Camera project I thought I’d get one to make a portable printer that works with the camera. I had a bit of fun getting the Selphy to work with the Pi but eventually I figured it out. You have to re-compile the Gutenberg suite to knock it back one version because the latest one breaks the paper size recognition. But I expect you already know that.

Anyhoo, I found a printer being sold for a fiver. In the original box. So I made the purchase, paid 6 pounds for postage (mutter mutter) and the printer arrived today. Turns out that “in original box” is not the same as “working”. Who knew? I got out my original one to make sure that all the drivers were in place and, sure enough, the five pound printer was getting stuck half way through a print.

I wandered downstairs for a disconsolate coffee and then, since I had not much to lose, I went back up to the office and took the lid off the printer to see if there were any wires dangling loose or bits of paper in the way. It looked OK so I tried to print again. And it worked. Yay! I popped the lid back on and it kept working.

So I went downstairs for a celebratory coffee and then returned to the office to tidy up. And I discovered that I’d taken the lid off the wrong printer, and I’d been testing the one that wasn’t broken. Can you see a pattern forming here from film fun on Monday? I’d be a bit concerned about incipient mental decay if I didn’t know that I’ve been doing this kind of stupid thing for the last sixty years.

Anyhoo, I took the lid off the broken printer and it worked fine. But only with the lid off. At this point I was too annoyed with the universe to do much more. So I put the new printer back in its box (it seems to like it there). The good news is that the plan is to move the printer into a custom case with a battery pack and whether it has a lid on it doesn’t make any difference to that application.

In all seriousness, these are cracking little printers and beautifully made (as you can see above). The only thing missing really is Wi-Fi. But you could add that by just attaching a Pi.

AI Images

I’ve got this Raspberry Pi connected to an e-ink frame. I’ve written a little program that generates random text prompts from a set of keywords. The text gets fed into a copy of Stable Diffusion and every few hours a new picture appears. It’s quite fun. Today I added a little web server to the app so that I can view past pictures. None of them are very good, but I find them fascinating.

New issue of Raspberry Pi Magazine out

There’s a new issue of Raspberry Pi magazine out. It’s got some really nice articles. And a couple that I wrote. My favourite so far is the one that describes how to install and run Stable Diffusion on a Raspberry Pi 5 with 1G of memory (or even a Raspberry Pi Zero. The good news is that it works. The bad news is that it takes several hours to create the image.

I don’t see that as a problem though. At the moment I’m trying to get it working on a Raspberry Pi attached to an e-ink display. I think it might be rather cool to have randomly generated art popping up every now and then.

Raspberry Pi 500+ First Look

Nicely packed

It was fate. On Wednesday I discovered that I’d earned some some more royalty payments. On Thursday I discovered that Raspberry Pi had released a new keyboard computer, Raspberry Pi 500+. So, one thing led to another (keyboard lighting joke there) and so yesterday it arrived. It’s very nice.

Size comparison

It is slightly larger and a lot heavier than the Raspberry Pi 500. It has proper clicky keys which are backlit If you don’t like the keycaps (and I do) you can swap them out for different ones. You are even given a key puller to remove the existing ones. You can get replacements (but make sure you buy low-profile keycaps or they might not work when you press them). You also get a tool to make it easier to take the computer apart, although bearing in mind it has 16G of RAM and a 256Gb built in solid-state disk I’m not sure why you’d want to get inside.

Use FN + F3 to step through other colours

The backlights work very well. Hold down Fn and press F4 and you can step through a set of different presets. Hold down Fn and press F3 and you can step through colour options for the presets.

There’s even an animated rainbow effect that looks awesome but might be a bit over the top.

Setting up the 500+ is a breeze because the internal hard disk has the Raspberry Pi operating system already loaded onto it. Just turn on the power and work through the very well organised setup. If you fancy something different you can always plug in a MicroSD card to boot from instead.

The machine has the same core components as a Raspberry Pi 5 with 16G of RAM and a 256G hard disk. There is no internal clock battery (boo) but you can buy one and plug it in. There’s no extra cooling, but it doesn’t seem to need it. There is a little internal extra in the form of a PICO which looks after the keyboard mapping and light display.

You can get direct access to the keyboard from Python. There’s a program which you can install and use to configure the keyboard from the command line. You can find instructions here. If you want to get your hands properly dirty you can write programs that interact directly with the keyboard lights. You can find all the source you need here. I’m looking forward to spending more time with the machine and making my own programs that use the coloured keys.

The Raspberry Pi 500+ is a lot more expensive than the Pi 500, at around twice the price. For that you get oodles of memory, an SSD, clicky keys and key lighting. I really like typing on the new keyboard. If you plan on spending a lot of your time typing you might find it is worth it for that alone. I wish the 500+ had a bit more personality though. It is just a minimal keyboard with sockets on the back. Of course you can add your own personality with keycaps and colours, but a strip along the bottom proclaiming its origins wouldn’t have come amiss. But I’m glad I got one and I’m looking forward to spending more time with it.

Making "The Exchange" - an AI you an ring up

Perhaps when I’ve built it I can ask it why it doesn’t work…

I hate it when things in a project go too well. It usually means that things are due to go not very well in a short while. I’ve got my Large Language Model running on a Pi 5 and I thought I’d use this to create “The Exchange”. This will work with “The Red Telephone”. The idea is that you pick up the receiver on your telephone and dial a “3”. A robotic voice asks you to state your business. You give your question and then put the receiver down. After a decent interval “The Exchange” rings back with the answer.

To make this work the phone needs to capture audio input from the phone, use speech to text to get the question text and send this to the Large Language Model Pi 5. The Pi 5 will respond with the answer and I can use the text to speech in the red phone to deliver the answer. Sounds simple enough.

I’ve found this lovely library which can run on the Raspberry Pi Zero in the phone and convert speech to text. It’s a bit slow, but I don’t care about that because I can record the question and then use speech to text on recorded sound file after the user has rung off. So the next thing I need to do is find something I can use to record audio into the Pi. Up pops https://www.npmjs.com/package/node-record-lpcm16 and that works a treat too. At this point my spidey sense is tingling a bit because things are going too well.

So I start to build the program. I write the code that tells the user to state their question and then records their response. It’s bound to work because I’ve tested it. But of course it doesn’t. The speech playback (using eSpeak) works a treat but the audio recorder fails because it can’t find the input device. Everything works fine individually. The only time it fails is when I ask it to do what I want it to do. I get this a lot when writing software.

I do have a fix though. If I run the whole application as a super-user it works. I’ve no idea what the speech generator is doing with the sound device, but giving the sound recorder awesome system powers seems to enable it to find a sound input device and make a recording.

I’ve spent a bit more time investigating the problem. I’ve added a timeout after the speech output finishes to give it time to release resources. I’ve tried different device names rather than the default one. But nothing works.

It’s not a huge problem if the application has to run as supervisor I suppose (although I’m not a fan of this approach). And I consider “Because it works that way” a perfectly reasonable answer to the question “Why have you done it that way?”. So I’m going to pop the question on the back burner for now and carry on.

Start your node.js applications when your Raspberry Pi boots

Spring is coming…

If you’ve got an application (perhaps one that lives inside a red telephone) which you want to run when your machine boots there is a really good way to do this. You turn your application into a service. You can make your application start when the Pi boots and you can also start and stop the application from the command line.

We can use the systemd to this for us. This orchestrates the startup and management of services. To use it with a Node.js application, we create a systemd service unit file.

Start your editor of choice and create a file named redserver.service (if you’re controlling a red telephone - otherwise use a more meaningful name) within the /etc/systemd/system/ directory. This file defines a service for systemd to manage.

[Unit]
Description=Red Phone Server/home/rob/RaspberryPi-DialTelephone
After=network.target

[Service]
ExecStart=/usr/bin/node /home/rob/RaspberryPi-DialTelephone/redserver.js
WorkingDirectory=/home/rob/RaspberryPi-DialTelephone
Restart=on-failure
User=rob

[Install]
WantedBy=multi-user.target

Note that the file sets the working directory for the application and specifies the command that starts the service. You can now enable and start your service with the following commands:

sudo systemctl enable redserver
sudo systemctl start redserver

The service will now run each time the Pi boots. You can use systemctl to stop the service. This is useful if you want to debug the service - things don’t normally go well if you have two copies of the thing running…

sudo systemctl stop redserver

If you want to restart the service you just start it again.

sudo systemctl start myapp

If you ever want to disable the service completely and stop it running when the system boots you can use this:

sudo systemctl disable myapp

I’ve found this very useful. So useful that I’ve made a blog post so that I can find it again later…

Running a Large Language Model on a Raspberry Pi 5

I never said it was perfect

I found this article which describes how you can get a something a bit like ChatGPT running on a Raspberry Pi. You need the latest Raspberry Pi 5, and it also needs the largest one with 8Gb of memory but it does work. It’s a bit slow and not very accurate, but it is fun to chat with. I think it is very useful to show slightly broken versions of the technology to folks so that they start to understand their limitations.

I’m now very tempted to make an “exchange” for the Red Phone which runs this engine and rings you back with answers to questions.

Robot Power Adapter

Very useful if you kept buying 12v power adapters instead of 5V power adapters….

One of our students showed me a useful gadget today. You can plug a 12 supply into it and get out 5v, 3.3v and the 12v going in. The two onboard regulators aren’t good for particularly high currents at around 800ma each, but this is a terribly useful controller if you are building a robot and want 12 for the motors and then the other voltages for your onboard devices.

Pimoroni Pi MMe base

Fun times..

The Raspberry Pi 5 is a seriously powerful beast. I’ve been very impressed by the way I can run even demanding graphical applications at reasonable speed. Today I thought I’d speed it up even more by adding a “proper” hard disk to it. I got hold of an MMe base from Pimoroni and popped a 256G solid state disk in it. The total cost was less than a video game. The base was easy to fit and setup. the hardest bit was feeding the funky ribbon cable into the connectors on the Pi and the base. Once they were connected I screwed the base onto the Pi and fired it up. My Pi was already running from an SSD memory card so I used Raspberry Pi Imager to put an operating system on the new disk, swapped the boot order using raspi-config and we were off. The difference in speed for loading applications is amazing. The system boots in around the same time it takes my PC to wake up from sleep.

If you are after a speedup for your Pi which will turn it into a much more viable desktop replacement you should take a look at this.