Morse code is a super simple communication protocol that can be used in all kinds of ways — from secret signals tapped out by hand, to lights, whistles, radio beacons, you name it. It was humanity’s first means of long-distance electronic communication, and appearances in fictional (and sometimes factual) tales of adventure and intrigue have been propping up its vintage mystique ever since.
Like many youngsters, we were intrigued by codes and ciphers, especially Morse. We sent Morse coded letters to our friends, and used flashlights to transmit Morse messages between the shore and our family’s sailboat. Our first Morse telegraph system was made of two hand-wound electromagnets connected by a salvaged telephone wire. An AC transformer powered the magnets, which rattled against strips of scrap metal with an ear-wrenching 60Hz buzz with each dot and dash.
Luckily, our technical skills have improved since then. What would happen, we wondered, if we took the bare-bones simplicity of a physical Morse key and connected it to the internet? When the Raspberry Pi Zero W came along, offering a web-connectable board that would fit in a project box for $10, we decided to find out.
Several prototypes and programming languages later, we had a tidy laser-cut 3″×5″ box with the Pi, buzzer, and one large button. Push the button, and a Golang client on the Pi sends a signal through a WebSocket server, turning on the buzzer in all the other connected telegraphs. The Pi’s configuration lets you set the channel to which your telegraph connects, allowing open channels that anyone can listen and talk on (like amateur radio Morse bands) and private ones for you and your cohorts. Both server and client code are open source, so you can hack and modify at will.
All Systems Golang: Sending Morse over the internet requires a real-time communication protocol — you wouldn’t want to wait for an HTTP request to complete every time you tried to send a dot or dash! Luckily, there is a protocol for that: WebSockets.
We went through several different technology stacks in the quest for a simple client-server WebSocket implementation for the telegraph. These included Node.js, which is equipped with a nice WebSocket library but is complex to implement on the Pi, and Python, which works nicely on the Pi but not so nicely, we found, on the server end.
We settled on Go. Go, or “Golang,” is a relatively new open source programming language originally developed by Google. It combines features of some high-level languages like Python or JavaScript (such as online package management and relatively compact syntax) with features of low-level languages like C++ (static types, compiles to machine code), and then adds some special sauce of its own, like the ability to add threads easily through “goroutines.”