Archives For Raspberry Pi

When the Raspberry Pi foundation announced the release of the new Raspberry Pi 3 Model B+, I ordered two from element 14 ( They were the only vendors at the time who had them in stock for the standard price of $35. When I received them I discovered that when they say the 3B+ needs 5V/2.5A, they really mean 2.5A, not 2.4A like I’d been using before. So I went back online and order a pair of new power supplies, along with two Samsung PRO Plus microSDHC 32GB cards. I also discovered via the dreaded red flashing power LED (four flashes) that the older Samsung EVO+ 32GB microSDHC cards would not boot the 3B+ fully. I don’t know why as they work just fine on every other earlier Raspberry Pi I own, up to and including the prior 3 Model B. Interestingly I didn’t have boot issues with any of the SanDisks I was using, just that particular card brand and model.

I also ran into an issue updating all my Arch Linux ARM Raspberry Pi systems. They all failed to update (pacman -Suy), and they all failed when attempting to get the catalog from the community repository. A bit of checking on the official Arch wikis turned up nothing. This isn’t the first time I’ve faced this update failure and been forced to reinstall Arch as a consequence. This time, rather than reinstall Arch, I decided to switch completely to the “official” Raspberry Pi distribution, Raspbian.

Raspbian has undergone considerable polish over the last 12 months, to the point where I can easily live within the Raspbian graphical desktop. The desktop has a very nice file browser, terminal, and the Chromium browser is now up-to-date with equivalents across all operating systems. I installed Raspbian by pulling down the image file and using Etcher, all of this on my Ubuntu 16.04 notebook. It’s extremely easy to load-and-go with both Raspbian and Etcher. Before I wiped and reloaded, I made full backups of the older /home/alarm home directories to pick up all my earlier work, then copied them back to the pi account home directory via a separate folder.

With Raspbian everything seems to be working just fine. I was even able to start this post on the older Raspberry Pi 3 Model B using Chromium, although I finished the post on my Mac. I had to transfer a photo I took using my iPhone via Google Drive, and I could have done it on the Pi, but I’m a Mac addict, and I wanted to run something undisturbed on the Pi.

One test I ran was using the tools I wrote in Python for the Sense HAT. I won’t go into the details of how I got the Arch Linux ARM set up to work, but I will say that Raspbian was already set up out-of-the-box to run my Python code unmodified with the Sense HAT plugged into the board, and without installing and/or configuring any other Raspbian packages. I look forward to moving my C++ based Pi code over.

One other observation: The 3B+ runs warm, much warmer than any other Raspberry Pi. I’ve done nothing to tweak the operating frequency of the board. My advice is to buy the heat sink kit for the Raspberry Pi and attach it to the board.

micro wiki written in go

January 21, 2018

It’s been quite a while since I last blogged about writing in Google’s Go. The language itself has evolved considerably over that period of time, but my skills in it have basically stood still. Go, however, has not, especially its use around today’s contemporary software environments, such as containers. It’s also available as a regular installable package on Arch ARM for the Raspberry Pi 2/3.

I’ve been investigating network programming on the Raspberry Pi, looking for a minimalist set of tools that can provide robust connectivity and functionality. One of the tools I’ve been looking for is a web server or wiki. Turns out that there’s a Go tutorial that leads the reader through the steps necessary to create a minimal wiki. It’s located here: Writing Web Applications.

Once I finished the tutorial I followed through with the suggested simple tasks at the bottom of the tutorial. One of them was the ability to add WiKi markup to create tags within the body of any page I created. I followed Help:Wikitext for syntax and to see how regular Wiki handles markup. I implemented very little: links, headers, single unordered lists, italic and bold text. I felt that was enough to get started, and it’s enough to drop onto a Raspberry Pi as a bare executable. There are a few more key features I’d like to add, such as table support, but that’s for another round of coding. Now, I’m taking a break while I go off and do other tasks.

Here’s the code.

// Personal Wiki Sandbox.
// Original Copyright 2010 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package main

import (

import s "strings"
var pr = fmt.Println

const dataDir = "data/"
const dataType = ".txt"
const templateDir = "templates/"

type Page struct {
	Title       string
	Body        []byte
	DisplayBody template.HTML

func (page *Page) save() error {
	os.Mkdir(dataDir, 0775)
	filename := dataDir + page.Title + dataType
	return ioutil.WriteFile(filename, page.Body, 0600)

func loadPage(title string) (*Page, error) {
	filename := dataDir + title + dataType
	body, err := ioutil.ReadFile(filename)
	if err != nil {
		return nil, err
	return &Page{Title: title, Body: body}, nil

// I'm a regular expression neophyte. If you can figure out what I'm doing and can offer a better way of writing
// any of them, then I'm ready to learn.
var linkRegexp =   regexp.MustCompile( "\\[\\[([\\w ]+)\\]\\]" )
var headingOne =   regexp.MustCompile( "^=(.*)=$" )
var headingTwo =   regexp.MustCompile( "^==(.*)==$" )
var headingThree = regexp.MustCompile( "^===(.*)===$" )
var headingFour =  regexp.MustCompile( "^====(.*)====$" )
var headingFive =  regexp.MustCompile( "^=====(.*)=====$" )
var headingSix =   regexp.MustCompile( "^======(.*)======$" )
var boldText =     regexp.MustCompile( "'''(.*?)'''" )
var italicText =   regexp.MustCompile( "''(.*?)''" )

func expandHeading(line string) string {
    result := line

    if headingSix.MatchString(line) {
        result = "<h6>" + s.TrimSpace(s.Trim(line, "=")) + "</h6>\n"
    } else if headingFive.MatchString(line) {
        result = "<h5>" + s.TrimSpace(s.Trim(line, "=")) + "</h5>\n"
    } else if headingFour.MatchString(line) {
        result = "<h4>" + s.TrimSpace(s.Trim(line, "=")) + "</h4>\n"
    } else if headingThree.MatchString(line) {
        result = "<h3>" + s.TrimSpace(s.Trim(line, "=")) + "</h3>\n"
    } else if headingTwo.MatchString(line) {
        result = "<h2 style=\"margin-bottom: 0.25em; border-bottom: 1px solid #808080;\">" +
            s.TrimSpace(s.Trim(line, "=")) + "</h2>\n"
    } else if headingOne.MatchString(line) {
        result = "<h1 style=\"margin-bottom: 0.25em; border-bottom: 2px solid #808080;\">" +
            s.TrimSpace(s.Trim(line, "=")) + "</h1>\n"

    return result

func viewHandler(writer http.ResponseWriter, request *http.Request, title string) {
	page, err := loadPage(title)

	// If the page doesn't exist, then redirect to the editing function and create the page.
	if err != nil {
		http.Redirect(writer, request, "/edit/"+title, http.StatusFound)

	// Start page processing.
	// Break on the new line (\n) because that's common to both Windows/DOS and Unix and Unix-like editors.
	// We'll strip off any carriage returns (\r) as white space.
	lines := s.Split(string(page.Body), "\n")

	var buildingUnorderedList bool
	// expandedBody is where all the displayable text with HTML decorations will be collected.
	var expandedBody []string

	for _, oneline := range lines {
		// Strip all leading and trailing white space, including carriage returns (\r).
		// This will help later when we join all the strings back together using the HTML break token
		// followed by a new line (\n).
		newLine := s.TrimSpace(oneline)

        // Bold and italicize any marked text. Try to handle the mixing of both.
        newLine = boldText.ReplaceAllStringFunc(
            func(str string ) string {
                matched := boldText.FindStringSubmatch(str)
                return "<b>" + matched[1] + "</b>"

        newLine = italicText.ReplaceAllStringFunc(
            func(str string ) string {
                matched := italicText.FindStringSubmatch(str)
                return "<i>" + matched[1] + "</i>"

        // Create links from [[PageName]] pattern.
        // Note that we can accept a link with spaces. I substitute the '_' for a space. I could, perhaps,
        // use the %20 called for in the standards, but I decided underscores were better.
        newLine = linkRegexp.ReplaceAllStringFunc(
            func(str string) string {
                matched := linkRegexp.FindStringSubmatch(str)
                return "<a href=\"/view/" + s.Replace(matched[1], " ", "_", -1) + "\">" + matched[1] + "</a>"

        // newLine = expandHeading(newLine)

		// Look for unordered lists. If we find an unordered list notation, then start building that list.
		if s.HasPrefix(newLine, "*") {
			nl2 := s.TrimSpace(s.SplitAfterN(newLine, "*", 2)[1])

			if !buildingUnorderedList {
				buildingUnorderedList = true
				expandedBody = append(expandedBody, "<ul>\n")

			expandedBody = append(expandedBody, "<li>"+nl2+"</li>\n")
		} else if buildingUnorderedList {
            buildingUnorderedList = false
            expandedBody = append(expandedBody, "</ul>\n")

		// Look for headings and the rest of the document.
		if s.HasPrefix( newLine, "=" ) && s.HasSuffix( newLine, "=" ) {
            expandedBody = append(expandedBody, expandHeading(newLine))

        expandedBody = append(expandedBody, newLine+"<br />\n")

	// Rejoin all the lines we created with the initial split using he HTML break followed by a new line.
	page.DisplayBody = template.HTML([]byte(s.Join(expandedBody, "")))
	renderTemplate(writer, "view", page)

func editHandler(writer http.ResponseWriter, request *http.Request, title string) {
	p, err := loadPage(title)
	if err != nil {
		p = &Page{Title: title}
	renderTemplate(writer, "edit", p)

func saveHandler(writer http.ResponseWriter, request *http.Request, title string) {
	body := request.FormValue("body")
	p := &Page{Title: title, Body: []byte(body)}
	err :=
	if err != nil {
		http.Error(writer, err.Error(), http.StatusInternalServerError)
	http.Redirect(writer, request, "/view/"+title, http.StatusFound)

var templates = template.Must(
	template.ParseFiles(templateDir+"edit.html", templateDir+"view.html"))

func renderTemplate(writer http.ResponseWriter, tmpl string, p *Page) {
	err := templates.ExecuteTemplate(writer, tmpl+".html", p)
	if err != nil {
		http.Error(writer, err.Error(), http.StatusInternalServerError)

func rootHandler(writer http.ResponseWriter, request *http.Request) {
	http.Redirect(writer, request, "/view/FrontPage", http.StatusFound)

var validPath = regexp.MustCompile("^/(edit|save|view)/([\\w ]+)$")

func makeHandler(fn func(http.ResponseWriter, *http.Request, string)) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		m := validPath.FindStringSubmatch(r.URL.Path)
		if m == nil {
			http.NotFound(w, r)
		fn(w, r, m[2])

func main() {
	http.HandleFunc("/", rootHandler)
	http.HandleFunc("/view/", makeHandler(viewHandler))
	http.HandleFunc("/edit/", makeHandler(editHandler))
	http.HandleFunc("/save/", makeHandler(saveHandler))

	http.ListenAndServe(":8080", nil)

Here’s a typical markup page.

= Main Page =

This is the front page. Basic testing of all the capabilities that can be added to a page of text with minimal Wiki markup support.

= Heading 1 With ''Bloody === Equals'' In The Middle =
== Heading 2 ==
=== Heading 3 ===
==== Heading 4 ====
===== Heading 5 =====
====== Heading 6 ======

Example testing of links.

[[TestName1]] [[foobar]]
[[Test Name 3]]

* one ''italic'' bulleted list entry with a link: [[ANewPage]]
* two '''bold''' bulleted list entry
Example of testing '''bold text multiple''' times in the '''same''' sentence.
Example of testing ''italic '''text''' multiple'' times in the ''same'' sentence.
This is ''' ''Italic and Bold text together.'' '''

And here’s what it looks like rendered in Chrome on a Macbook Pro.


  1. Handles links with [[ and ]] notation. Also handles spaces within a page link.
  2. Handles italic and bold text, and combinations of the two.
  3. Handles headings, from h1 to h6.

Blank lines and lines that aren’t headings and part of an unordered list have a single HTML break appended to them. Other than that it’s just a way to organize text. I’m even writing a stripped down version that won’t allow you to edit any of the pages, for embedded read-only rendering.