Lightweight Internet communications with the simple Gemini Protocol
Twins
Create Gemini pages to show sensor data or control a Raspberry Pi rover.
The Gemini Protocol [1] is a relatively new Internet communication protocol for accessing remote documents. Unlike an HTML web page that contain layers of style sheets, JavaScript, and HTML tags, a Gemini document is a simple readable document.
Gemini's Gemtext format is easy to learn, requiring about five codes. Children or new coders could easily put together a small documentation server or custom application server without many programming skills.
In this article, I introduce the Gemini protocol with three simple projects. The first project creates a Gemini server and client with just one line of Bash code. In the second project, a Bash script creates a common gateway interface (CGI) page that connects to a sensor to show temperature and humidity data. The third project uses Gemini document links to control Raspberry Pi general purpose input/output (GPIO) pins to drive a rover.
Getting Started
Any text editor can be used to create Gemini documents. The Gemtext format is a little bit like a slimmed down version of the Markdown syntax. The default file extension for a Gemini document is .gmi
.
The example file in Listing 1 (page1.gmi
) shows all of the Gemtext format codes, including headings (three levels), document links, block quotes, lists, and preformatted text. I'll look a little later into the use of preformatted text for ASCII art and output from Bash commands.
Listing 1
Gemini Document
# Heading level 1 (H1) ## Heading level 2 (H2) ### Heading level 3 (H3) => testpage.gmi A link to another page. > This line will show as a block-quote. A list of items * This is the first list item. * This is another list item. ``` Code or ASCII Block _ ___ ___ ___ ___ _____ _ /_\ / __|/ __|_ _|_ _| |_ _|__ __| |_ / _ \\__ \ (__ | | | | | |/ -_|_-< _| /_/ \_\___/\___|___|___| |_|\___/__/\__| ```
A good selection of Gemini client applications are available, such as the Lagrange [2] desktop GUI client that works with both local files and Gemini network links. Figure 1 shows the example file (file://page1.gmi
) accessed locally. Note that differences between the source file and the Gemini presentation are minimal.
Content Type
The content type is used by browsers and applications to determine how to manage the requested file. Typically, the content type is managed by the application server (e.g., a web server will send the "HTTP/1.0 200 OK" status code before sending an HTML file).
For the Gemini protocol, the content type is: "20 text/gemini". Depending on the Gemini server and the file extension of the requested file, the user might have to add the content type manually. (More about this when I look at Bash and CGI servers.)
Simple Bash Gemini Servers and Clients
For basic testing, a one-line Bash statement can be used for either a Gemini server or a client. The Gemini protocol typically uses the Secure Sockets Layer (SSL) and Transport Layer Security (TLS) encryption, so the Bash ncat
utility is needed. (Note: the simpler nc
command does not support SSL.)
The Bash code to serve up the earlier single Gemini page would be:
while true; do { echo -ne "20 text/gemini\r\n"; cat page1.gmi; } | ncat -l -p 1965 --ssl; done
This Bash statement echos the Gemini content type ("20 text/gemini") and lists (cat
) the example file when a request is received. The ncat
utility listens (-l
option) on port 1965 (the default Gemini port) for incoming requests.
The Bash script to connect to a Gemini server is:
echo "gemini://192.168.0.105" | ncat --ssl 192.168.0.105 1965
Gemini clients start by sending "gemini://<requested_ip_address>". This string is echoed to ncat
with SSL enabled (--ssl
) and the Gemini server's IP and port defined. This Bash client statement will output the Gemini page to the screen.
The at
scheduling utility could be used with the Bash client statement to save a Gemini page at a specific time, for example, at 11:20am:
at 1120 $(echo "gemini://192.168.0.105" | ncat --ssl 192.168.0.105 1965 > page1120.gmi) &
One benefit of one-line Bash utilities is that you can easily configure your own custom network applications without the need to load back-end FTP or web servers. The downside of the ncat
utility is that it could be a security issue if it is used improperly.
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Systemd Fixes Bug While Facing New Challenger in GNU Shepherd
The systemd developers have fixed a really nasty bug amid the release of the new GNU Shepherd init system.
-
AlmaLinux 10.0 Beta Released
The AlmaLinux OS Foundation has announced the availability of AlmaLinux 10.0 Beta ("Purple Lion") for all supported devices with significant changes.
-
Gnome 47.2 Now Available
Gnome 47.2 is now available for general use but don't expect much in the way of newness, as this is all about improvements and bug fixes.
-
Latest Cinnamon Desktop Releases with a Bold New Look
Just in time for the holidays, the developer of the Cinnamon desktop has shipped a new release to help spice up your eggnog with new features and a new look.
-
Armbian 24.11 Released with Expanded Hardware Support
If you've been waiting for Armbian to support OrangePi 5 Max and Radxa ROCK 5B+, the wait is over.
-
SUSE Renames Several Products for Better Name Recognition
SUSE has been a very powerful player in the European market, but it knows it must branch out to gain serious traction. Will a name change do the trick?
-
ESET Discovers New Linux Malware
WolfsBane is an all-in-one malware that has hit the Linux operating system and includes a dropper, a launcher, and a backdoor.
-
New Linux Kernel Patch Allows Forcing a CPU Mitigation
Even when CPU mitigations can consume precious CPU cycles, it might not be a bad idea to allow users to enable them, even if your machine isn't vulnerable.
-
Red Hat Enterprise Linux 9.5 Released
Notify your friends, loved ones, and colleagues that the latest version of RHEL is available with plenty of enhancements.
-
Linux Sees Massive Performance Increase from a Single Line of Code
With one line of code, Intel was able to increase the performance of the Linux kernel by 4,000 percent.