Just wanted to show my $3,50 OLED-display

Not the nicest code, but it works. This is the part to actually send data to the OLED:

fivelines.py:


#!/usr/bin/env python

import sys

from oled.device import ssd1306, sh1106
from oled.render import canvas
from PIL import ImageFont

font = ImageFont.load_default()
device = ssd1306(port=1, address=0x3C)

with canvas(device) as draw:
    x = 2
    top = 0

    font = ImageFont.truetype('/opt/ssd1306/examples/alert.ttf', 12)

    draw.text((x, top+0),    sys.argv[1], font=font, fill=255)
    draw.text((x, top+13),   sys.argv[2], font=font, fill=255)
    draw.text((x, top+26),   sys.argv[3], font=font, fill=255)
    draw.text((x, top+39),   sys.argv[4], font=font, fill=255)
    draw.text((x, top+52),   sys.argv[5], font=font, fill=255)

You can simply output data by executing “./fivelines.py line1 line2 line3 line4 line5” and you will get five lines on the display. I wrote a Bash-script (don’t like Python, it’s easier to collect the data with bash) to call fivelines.py:

oled.pl


#!/bin/bash

aircraftjson=/run/dump1090-mutability/aircraft.json
hexdbdaily=/usr/share/dump1090-mutability/dbicao24/hexdb-`date +%Y%m%d`.txt
icaocount=/usr/share/dump1090-mutability/dbicao24/icaocount.txt
tempjson=/tmp/pretty.json

# Line 1
line1="`date +'%d.%m.%Y - %H:%M:%S'`"

# Line 2
icaocount=`cat $icaocount`
seentoday="`wc -l $hexdbdaily | cut -d ' ' -f 1`" 

# Line 3
cat $aircraftjson | json_pp -f json -t dumper -json_opt pretty > $tempjson

acmes=`cat $tempjson | grep "messages" | wc -l`
accat=`cat $tempjson | grep "category" | wc -l`
acpos=`cat $tempjson | grep "seen_pos" | wc -l`

# Line 4
up=`uptime | sed -E 's/^^,]*up *//; s/, *:digit:]]* users.*//; s/min/minutes/; s/(:digit:]]+):0?(:digit:]]+)/\1 hrs, \2 min/'`

# Line 5
cpu=`top -bn1 | grep "Cpu(s)" |            sed "s/.*, *\([0-9.]*\)%* id.*/\1/" |            awk '{print 100 - $1"%"}'`

/usr/share/dump1090-mutability/dbicao24/fivelines.py "$line1" "$seentoday A/C Today ($icaocount)" "$acmes/$accat/$acpos A/C Now" "Up: $up" "CPU: $cpu"

This is just to get an idea how it works, the stuff for line 2 won’t work on your system.

Of course you can play with number of lines and font-size:

Klaus