Automatic photo sorting with Gps location lookup

Last Updated or created 2023-08-07

We take a lot of pictures, with our Nikon camera and our mobile phones.

(Apparently in 2019 5544 pictures)

Some stats

757 20190803 - on a single day (Holiday)

Average pictures per month
locate "/2019/" | egrep -i "photoalbum|gsm" | egrep -i "mp4$|jpg$" | grep -Eo '2[[:digit:]]{3}[[:digit:]]{2}[[:digit:]]{2}' | cut -c-6 |sort | uniq -c | sort -n | awk '{ sum += $1; n++ } END { if (n > 0) print sum / n; }'
461

Besides android pictures being automatically uploaded to our nextcloud, I’m using some apps and scripts to get pictures and movies stored on my fileserver. (bash scripts/andftp)

For sorting those media files, i made a sorting script.
(Today I added a location sorting addition using GPS information stored in the exif information.

  • jpg and jpeg (add your own extentions)
  • mp4 and mov (for mobile and nikon)
  • Sorts by camera model/year/date/location
  • tries to extract date from filename when not found in exifinfo
  • Sorts whatsapp media
  • Sorts Raw

INSTALLING

pip3 install reverse_geocoder
You need python3, exiftool, exiftime and mediainfo

copy below python script in ~/bin/reverse2.py

( need more info? change last print entry admin1/admin2)
[{‘lat’: ‘-39.45556’, ‘lon’: ‘173.85833’, ‘name’: ‘Opunake’, ‘admin1’: ‘Taranaki’, ‘admin2’: ‘South Taranaki District’, ‘cc’: ‘NZ’}]

import reverse_geocoder as rg
import sys

lat=sys.argv[1]
lon=sys.argv[2]

coordinates = (lat,lon)

results = rg.search(coordinates) # default mode = 2


#print (results)

for entry in results:
    print(entry['name'] + "(" +  entry['cc'] + ")")

And a bash script /usr/local/bin/exifsort.sh

#!/bin/bash
#set -x

reversepath=/home/henri/projects/reversegeo/reverse2.py

#RAW
rawcnt=`ls | grep -i  nef$ | wc -l`
if [ "$rawcnt" = "0" ] ; then
echo "no raw"
else
mkdir raw 2>/dev/null
ls | grep -i nef$ | while read ; do mv $REPLY raw ; done
fi


ls | egrep -i "jpg$|jpeg" | while read ; do 
 	location=""	
	getmodel=$(exiftool "$REPLY" |grep "Make " | awk '{ print $3 }')
	if [ "$getmodel" != "" ] ; then 
		getmodel=$getmodel/
	fi
	echo "$REPLY" | grep WA0 >/dev/null && getmodel=whatsapp/

	gpsinfo=$(exiftool -c "%+.6f" "$REPLY" |grep "GPS Position" | cut -d":" -f2 | tr -d ' ' | sed s/,/\ /g)
	if [ "$gpsinfo" != "" ] ; then 
		location=$(python3 $reversepath $gpsinfo | grep -vi load | sed s/\(NL\)//g)
	fi
	dater=$(exiftime "$REPLY" 2>/dev/null | egrep "Created|Digitized" | sed s/Digitized/Created/g | tail -1  | cut -c 16-19,21,22,24,25)
	if [ "$dater" = "" ] ; then 
#		echo "Trying from filename"
		dater=$(echo $REPLY | grep -Eo '2[[:digit:]]{3}-[[:digit:]]{2}-[[:digit:]]{2}')

		if [ "$dater" = "" ] ; then 
#			echo "Trying from filename - maybe without dashes"
			dater=$(echo $REPLY | grep -Eo '2[[:digit:]]{3}[[:digit:]]{2}[[:digit:]]{2}')

		fi
	fi
	if [ "$dater" != "" ] ; then 
		year=$(echo $dater | cut -c-4)
		mkdir -p "${getmodel}$year/${dater}/$location"
		mv "$REPLY" "${getmodel}${year}/${dater}/$location"
	else
		mkdir -p "${getmodel}unknowndate/$location"
		mv "$REPLY" "${getmodel}unknowndate/$location"
      	fi
done

ls | egrep -i "mov$|mp4$" | while read ; do 
	
 	location=""	
	getmodel=$(exiftool "$REPLY" |grep "Make " | awk '{ print $3 }')
	if [ "$getmodel" != "" ] ; then 
		getmodel=$getmodel/
	fi

	echo "$REPLY" | grep WA0 >/dev/null && getmodel=whatsapp/
	gpsinfo=$(exiftool -c "%+.6f" "$REPLY" |grep "GPS Position" | cut -d":" -f2 | tr -d ' ' | sed s/,/\ /g)
	if [ "$gpsinfo" != "" ] ; then 
		location=$(python3 $reversepath $gpsinfo | grep -vi load | sed s/\(NL\)//g)
	fi
	dater=$(mediainfo "$REPLY" | grep Encode | tail -1 | cut -f2- -d:  | cut -f3 -d" " | sed s/-//g)
	if [ "$dater" = "" ] ; then 
#		echo "Trying from filename"
		dater=$(echo $REPLY | grep -Eo '2[[:digit:]]{3}-[[:digit:]]{2}-[[:digit:]]{2}')

		if [ "$dater" = "" ] ; then 
#			echo "Trying from filename - maybe without dashes"
			dater=$(echo $REPLY | grep -Eo '2[[:digit:]]{3}[[:digit:]]{2}[[:digit:]]{2}')

		fi
	fi
	if [ "$dater" != "" ] ; then 
		year=$(echo $dater | cut -c-4)
		mkdir -p "${getmodel}$year/${dater}/$location"
		mv "$REPLY" "${getmodel}${year}/${dater}/$location"
	else
		mkdir -p "${getmodel}unknowndate/$location"
		mv "$REPLY" "${getmodel}unknowndate/$location"
      	fi
done

Example running in a directory with mixed media

# Raw images get moved into a RAW directory
no raw

# Samsung phone detected with date and GPS location
mkdir -p samsung/20220717/Hilversum
mv 20220717_133453.jpg samsung/20220717/Hilversum

# OnePlus phone
mkdir -p OnePlus/20021208/Voorburg
mv IMG_20190109_091825.jpg OnePlus/20021208/Voorburg

# Realme (Added country when not NL)
mkdir -p realme/20220607/Isle of Islay(GB)
mv IMG20220607213630.jpg realme/20220607/Isle of Islay(GB)

# Whatsapp has no date embedded so it gets it from filename
Trying from filename
Trying from filename - maybe without dashes
mkdir -p whatsapp/20221021/
mv IMG-20221021-WA0000.jpg whatsapp/20221021/

# Nikon without GPS
mkdir -p NIKON/20220613/
mv DSC_1423.MOV NIKON/20220613/

# Whatsapp video without exif
mkdir -p whatsapp/20170528/
mv VID-20170528-WA0006.mp4 whatsapp/20170528/

# No camera name detected in exif from mobile movie
mkdir -p 20190114/Maarssen
mv VID_20190114_142455.mp4 20190114/Maarssen

# Location in mp4
mkdir -p 20220607/Lamlash(GB)
mv VID20220607155044.mp4 20220607/Lamlash(GB)

Result

./NIKON/2022/20220613/DSC_1423.MOV
./NIKON/2022/20220610/750_1101.JPG
./realme/2022/20220818/Hilversum/IMG20220818203825.jpg
./realme/2022/20220607/Isle of Islay(GB)/IMG20220607213630.jpg
./2019/20190114/Maarssen/VID_20190114_142455.mp4
./whatsapp/2017/20170528/VID-20170528-WA0006.mp4
./whatsapp/2022/20221021/IMG-20221021-WA0000.jpg
./2022/20220607/Lamlash(GB)/VID20220607155044.mp4
./2022/20220516/Hilversum/VID20220516125913.mp4
./OnePlus/2002/20021208/Voorburg/IMG_20190109_091825.jpg
./samsung/2022/20220717/Hilversum/20220717_133453.jpg

You could automate this using incrond
apt-get install incron
add your user to /etc/incron.allow
incrontab -e
add

/fileserver/mediain/ IN_CREATE /usr/local/bin/sortmymedia.sh
Coping a file in the directory, auto sort and move to correct location

sortmymedia.sh

#!/bin/bash
cd /home/user/media
/usr/local/bin/exifsort.sh

Disk troubles or missing old skool hardware?

Last Updated or created 2022-12-12

I bought a XT Laser/3 a while ago.
And i wanted to get my old programs running on it again.

One of the disk i found was a 5.25 inch boot disk which should contain a boot demo i’ve made in the past with Edk.
But it is the secondary drive in this system. Those old machines lack a bios you can change.
And change A: for B: for example.
Some machines had a program which could alter boot settings. (not this one)
So i was playing with jumpers and dipswitches on the motherboard.
( Drive select / Termination / drive before or after the twist in the flatcable. )

Dipswitches on the motherboard

Wellll leave the boot order for now, i needed to get software on the machine using floppy’s.
I could not find empty HD disks (1.44MB which i wanted to use)
So i took a DD disk and a drill ..

(Image from the internet)

I bought an external usb floppy drive.

Now i have everything to get my programs on the msdos machine.

EXCEPT ….

Diskette didn’t work in the drives.
So i bought new old stock diskettes online.

Now i have everything

WRONG again

Formatted 1.44 disk in USBfloppy drive .. OK
Read in 3.5 drive on the MSDOS machine .. NOT OK
Check drive in MSDOS machine .. is 1.44MB .. OK
… check floppy controller in MSDOS machine .. NOT OKAY
(720kb is 300kbits per second and 1.44 HD 500kbits per second)
So i’m limited to 720kb due to the controller ..


Can the USB Floppy drive read/write 720kb disks .. NO!
( A cheap series made with drives only supporting HD disks )

Alternatives? .. Serial maybe, there is Norton Commander on the MSDOS machine so i could use “link”

Do i still have a USB-RS232 sub-d cable ? YES!
Nullmodem cable? NO
Make a null modem cable .. i’ve made those before .. BUT no sub-d connectors.

I’ve been throwing away too much in the past.

Now i have to buy those things again:

VGA – 8bit ISA – have 2 now
Floppy drive – have one for 1.44
8bit soundblaster compatible – TODO
Nullmodem – well i’ve bought connectors for those

Tunebook generator

Last Updated or created 2023-07-18

2023-01-11 Updated the script! More functions

I’m using below scripts to generate tunebooks.
These books I can print OR view on a tablet using my DIY bluetooth page turner. ( see other post )

I often work on tunes, add notes, text or write other versions.
So i needed a fast and simple way to re-generate a tunebook. ( hence the date on the title page and in the name, so i know whats the most recent version )
Now i have a separate tunebook for each instrument, with the same looks

What does this script?

  • Generates a title page using Latex
  • Generates a tune index, with page numbers ( works with multipage tunes )
  • Adds bookmarks to the tunes, so you can use the bookmark link in your reader.
  • Merges all pdf’s into one.
  • Sets title/author
  • Generic setup for multiple tunebooks
  • Generates ABC pdf and includes these

Todo: embed page numbers on every page?

BASH script:

#!/bin/bash
#sudo apt-get install texlive-latex-extra

### REMOVE OLD BOOKMARKS
ls *pdf | while read; do
rm -f "/tmp/$$.pdf"
cp "$REPLY" /tmp/$$.pdf
pdftk A=/tmp/$$.pdf cat A1-end output "$REPLY"
done


### GENERATE ABC 
if [ -d abc ] ; then
ls abc/*abc | while read abc ; do  abcm2ps -x -O - "$abc" | ps2pdf  -sPAPERSIZE=a4 - "$(echo  $abc | cut -f2 -d/ | sed 's/abc/pdf/g')" ;done
fi


nrpdf=$(ls *\.pdf | grep -vi index.pdf | grep -vi title.pdf | grep -v ^00  | wc -l)
echo "Tune PDFs in directory : $nrpdf"
pages=$(( $nrpdf / 126 ))
pages=$(( $pages + 1 ))
echo "Needed index pages : $pages"

# Extra pages : Number 002-999
extrapages=$( ls *pdf | egrep  ^00 | wc -l)
echo "Extra pages : $extrapages"

nr=$((  $extrapages  ))
echo "Total pages for tunes : $nr"
echo "create column page as text"
nr=$(( $nr +1 ))
echo $nr
ls *\.pdf | grep -vi index.pdf | grep -vi title.pdf | grep -v ^00 | sort | while read ; do 
echo "$nr $REPLY" 
next=$(exiftool "$REPLY" | awk -F": " '/Page Count/{print $2}')
nr=$(( $nr + $next ))
done | cut -f1,3- -d" " | cut -f1 -d. | sed s/\ a$//g | sed s/\ b$//g | pr -2 -t > /tmp/col
echo "Create Index pdf"
vim /tmp/col -c "set printfont=courier:h12"  -c":let &printheader = \" \""   -c "hardcopy > 001aIndex.ps | q"; ps2pdf 001aIndex.ps 

echo "Create title page pdf"
pdflatex "000 title.tex" 1>/dev/null

tempPDF=`mktemp`

echo -n "Add bookmarks : "
ls *\.pdf | grep -vi index.pdf | grep -vi title.pdf | grep -v ^00 | sort | while read i ; do
    bookmarkTitle=$( echo $i | cut -f2- -d" " | rev | cut -f2- -d. | rev)
    bookmarkInfo="BookmarkBegin\nBookmarkTitle: $bookmarkTitle\nBookmarkLevel: 1\nBookmarkPageNumber: 1"
    pdftk "$i" update_info_utf8 <(echo -en $bookmarkInfo) output $tempPDF >/dev/null
    mv $tempPDF "$i"
    echo -n "."
done
echo ""
set +x
#ls *\.pdf | grep ^[A-Z] | sort > /tmp/pdflist
name=$(pwd | rev | cut -f2 -d/ | rev)
echo $name
pdftk *pdf cat output "../${name}_$(date +%Y%m%d).pdf"
exiftool -Author="Henri Aanstoot" -Title="$name" "../${name}_$(date +%Y%m%d).pdf"

Needed tex file (named “000 title.tex”)

\documentclass[11pt]{report}
\usepackage[T1]{fontenc}
\usepackage{anyfontsize}
\usepackage[a4paper, total={6in, 8in}]{geometry}

\usepackage[T1]{fontenc}
\usepackage{tgbonum}

\newlength{\drop}

\begin{document}
  \begin{titlepage}
    \drop=0.1\textheight
    \centering
    \vspace*{\baselineskip}
    \rule{\textwidth}{1.6pt}\vspace*{-\baselineskip}\vspace*{2pt}
    \rule{\textwidth}{0.4pt}\\[\baselineskip]
    {\fontsize{50}{60}\selectfont Irish Tunes Test Tunebook}
    \rule{\textwidth}{0.4pt}\vspace*{-\baselineskip}\vspace{3.2pt}
    \rule{\textwidth}{1.6pt}\\[\baselineskip]
    \scshape
	{\large Tunebook}\par
    \vspace*{2\baselineskip}
    {\itshape Henri - Exampletunes\par}
    \vfill
    {\scshape generated:} \\
    \today
  \end{titlepage}
\end{document}

File naming:

000 title
001 index
002 – 099 xyz (extra pages, not in index)
100 – 999 Tunes (sorting)

000 title.pdf
001aIndex.pdf
002 tuneinfo.pdf
100 The Battle of Aughrim.pdf
101 I was born for sports.pdf
105 Cerlew Jig.pdf
110 Chanters Song.pdf
115 Gander at the Pratie Hole.pdf
120 honeymoon.pdf
125 Kitty Goes a-Milking.pdf
130 Terribus.pdf

Output from the script

 ./generatebook
Tune PDFs in directory : 8
Needed index pages : 1
Extra pages : 1
Total pages for tunes : 3
create column page as text
Create Index pdf
Create title page pdf
Add bookmarks : ........

Needed software:

pdftk, pdflatex, vim, exiftool, texlive-fonts-recommended

Avond van de filmmuziek

Last Updated or created 2023-07-18

After 3 times being cancelled due to Covid, it finally happened.

We got to get to the “Evening of the film music”

We held on to our tickets, as apparently 90% of the people!

We love film music, but it is a treat when there is a live orchestra.
(And special effects .. like a stuntman hanging from the roof, fire (not like Rammstein haha), and big displays)

If you get the chance .. go!
Wicked good musicians and singers.
Tania Kross was amazing!

Previous concerts we went to: Jeff Wayne’s War of the Worlds. The star wars suite, and an evening with Hans ZImmer.

  • Richard Strauss – “Also Sprach Zarathustra”
  • The Cinematic Orchestra – “Arrival of the Birds” from Theory of Everything
  • John Williams – “Hedwig’s Theme” from Harry Potter and the Sorcerer’s Stone
  • Ennio Morricone – The Good, the Bad and the Ugly
    • Main title
    • The Ecstasy of Gold
  • Ennio Morricone – Once Upon a Time in the West 
    • Man with a Harmonica
    • Once Upon a Time in the West
  • Hans Zimmer – “Maestro” from The Holiday
  • Thomas Newman – “The Night Window” from 1917
  • Ludovico Einaudi – “Oltremare” from Nomadland
  • Ludovico Einaudi – “Fly” from Intouchables
  • John Williams – “Duel of the Fates” from Star Wars:The Phantom Menace
  • John Williams –  “Main Title” from Star Wars: A New Hope

Intermission

  • Lalo Schifrin and Lorne Balfe – “Fallout” from Mission: Impossible – Fallout
  • Alexandre Desplat – “The Shape of Water” from The Shape of Water
  • Alan Silvestri – “Portals” from Avengers: Endgame
  • Hans Zimmer, Elton John and Lebo M – The Lion King
    • Circle of Life
    • King of the Pride Rock
  • Don Davis and Juno Reactor – “Navras” from The Matrix Revolutions
  • Jerry Goldsmith – Theme from Basic Instinct
  • 60 Years of James Bond
    • James Bond Theme
    • “No Time To Die” from No Time To Die
    • “Skyfall” from Skyfall
    • “A View to a Kill” from A View to a Kill
    • “Goldfinger” from Goldfinger
    • “Live and Let Die” from Live and Let Die
  • John Williams – “The Raiders March” from Raiders of the Lost Ark (encore)

Domoticz + NodeRed + HomeAssistant MQTT

Last Updated or created 2024-01-22

UPDATE 20240122 : below

I’ve got my RFXCOM connected to my Domoticz, and not connected to my HA.

RFXCOM 433 Mhz

To have the changes of my IOT devices being known to HomeAssistant I wanted to use mqtt.

Domoticz writes the mqtt topic (payload) like this
(topic: domoticz/out)

{
	"Battery" : 100,
	"LastUpdate" : "2022-11-17 18:21:59",
	"RSSI" : 6,
	"description" : "",
	"dtype" : "Temp + Humidity",
	"hwid" : "4",
	"id" : "230E",
	"idx" : 8461,
	"name" : "Living Temp/Hum",
	"nvalue" : 0,
	"stype" : "Cresta, TFA TS34C",
	"svalue1" : "20.0",
	"svalue2" : "60",
	"svalue3" : "1",
	"unit" : 1
}

So you can’t see which device it is by the topic name, the idx is in the json (8461)

To get this device ( a temperature sensor) into HA using mqtt i rewrote the mqtt topic using NodeRed

Temperature Humidity Sensor

NodeRed flow

[
    {
        "id": "836cc419ddb2ca2b",
        "type": "mqtt in",
        "z": "cfb00976f06591d6",
        "name": "",
        "topic": "domoticz/out/#",
        "qos": "2",
        "datatype": "auto-detect",
        "broker": "8c74c5f6.9a7a48",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 200,
        "y": 140,
        "wires": [
            [
                "dbe628e18027a287"
            ]
        ]
    },
    {
        "id": "a6cb517fd1cc9987",
        "type": "mqtt out",
        "z": "cfb00976f06591d6",
        "name": "",
        "topic": "",
        "qos": "",
        "retain": "",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "8c74c5f6.9a7a48",
        "x": 870,
        "y": 140,
        "wires": []
    },
    {
        "id": "dbe628e18027a287",
        "type": "function",
        "z": "cfb00976f06591d6",
        "name": "MQTT REWRITE",
        "func": "var varidx = msg.payload.idx;\nmsg.topic = \"home/\"+varidx+\"/payload\";\nreturn msg;\n",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 570,
        "y": 140,
        "wires": [
            [
                "a6cb517fd1cc9987"
            ]
        ]
    },
    {
        "id": "8c74c5f6.9a7a48",
        "type": "mqtt-broker",
        "name": "MQTTSERVERIP",
        "broker": "MQTTSERVERIP",
        "port": "1883",
        "clientid": "",
        "usetls": false,
        "compatmode": true,
        "keepalive": "15",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "closeTopic": "",
        "closePayload": "",
        "willTopic": "",
        "willQos": "0",
        "willPayload": ""
    }
]

The function node code ( rewrites the mqtt topic)

var varidx = msg.payload.idx;
msg.topic = "home/"+varidx+"/payload";
return msg;

Now we have a idx separated payload “home/IDX/payload”
(The other entries svalue/nvalue are from testing.

Adding the MQTT entries to HomeAssistant configuration.conf

mqtt:
 sensor:
  - name: "LivingTemperature"
    state_topic: "home/8461/payload"
    unit_of_measurement: "°C"
    value_template: "{{ value_json.svalue1 }}"
  - name: "LivingHumidity"
    state_topic: "home/8461/payload"
    unit_of_measurement: "%"
    value_template: "{{ value_json.svalue2 }}"

Now i can add the card to the dashboard.

This should now be a generic mqtt translator

A quick update:

Adding a motion sensor:

Home Assistant
  - name: "LivingMotion"
    state_topic: "home/45/payload"
    value_template: "{{ value_json.nvalue }}"

Add sensors to be reset to the switch node

[
    {
        "id": "836cc419ddb2ca2b",
        "type": "mqtt in",
        "z": "cfb00976f06591d6",
        "name": "",
        "topic": "domoticz/out/#",
        "qos": "2",
        "datatype": "auto-detect",
        "broker": "8c74c5f6.9a7a48",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 200,
        "y": 140,
        "wires": [
            [
                "dbe628e18027a287",
                "768bb6e4b6731436"
            ]
        ]
    },
    {
        "id": "a6cb517fd1cc9987",
        "type": "mqtt out",
        "z": "cfb00976f06591d6",
        "name": "",
        "topic": "",
        "qos": "",
        "retain": "",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "8c74c5f6.9a7a48",
        "x": 870,
        "y": 140,
        "wires": []
    },
    {
        "id": "dbe628e18027a287",
        "type": "function",
        "z": "cfb00976f06591d6",
        "name": "MQTT REWRITE",
        "func": "var varidx = msg.payload.idx;\nmsg.topic = \"home/\"+varidx+\"/payload\";\nreturn msg;\n",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 570,
        "y": 140,
        "wires": [
            [
                "a6cb517fd1cc9987"
            ]
        ]
    },
    {
        "id": "768bb6e4b6731436",
        "type": "switch",
        "z": "cfb00976f06591d6",
        "name": "",
        "property": "payload.idx",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "45",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 1,
        "x": 330,
        "y": 260,
        "wires": [
            [
                "e46fed76a596a719"
            ]
        ]
    },
    {
        "id": "e46fed76a596a719",
        "type": "delay",
        "z": "cfb00976f06591d6",
        "name": "",
        "pauseType": "delay",
        "timeout": "5",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "allowrate": false,
        "outputs": 1,
        "x": 500,
        "y": 260,
        "wires": [
            [
                "3f7eeffc8d066de3"
            ]
        ]
    },
    {
        "id": "3f7eeffc8d066de3",
        "type": "function",
        "z": "cfb00976f06591d6",
        "name": "nvalue 0",
        "func": "msg.payload.nvalue = 0;\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 700,
        "y": 260,
        "wires": [
            [
                "dbe628e18027a287"
            ]
        ]
    },
    {
        "id": "8c74c5f6.9a7a48",
        "type": "mqtt-broker",
        "name": "MQTTIP",
        "broker": "MQTTIP",
        "port": "1883",
        "clientid": "",
        "usetls": false,
        "compatmode": true,
        "keepalive": "15",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "closeTopic": "",
        "closePayload": "",
        "willTopic": "",
        "willQos": "0",
        "willPayload": ""
    }
]

UPDATE 20240122

I’m using domoticz as a 433->mqtt bridge, and some virtual devices i can toggle with curl (bash scripts)

I needed to make a custom 433 door sensor in Home Assistant with toggles to OFF after a few seconds. (There is NO off signal in this cheap sensor i’m using)

I’m changing the payload complete, to have a payload which matches the device class for door: (state with on/off)
It was nvalue = 0/1

(Whenever the IDX changes, I only have to update this Nodered part)
HA won’t notice the change.

var nvalue = msg.payload.nvalue;
msg.payload = {};
if(nvalue == 1)
{
msg.payload.state = "ON";
return msg;
} 

AND after 5 seconds

msg.payload = {};
msg.payload.state = "OFF";
return msg;

Node-RED Deploy
Export nodes
Export
[
    {
        "id": "d8a1af40d14307a9",
        "type": "mqtt in",
        "z": "a8ec6104.cb08c",
        "name": "",
        "topic": "home/35/payload",
        "qos": "2",
        "datatype": "auto-detect",
        "broker": "8c74c5f6.9a7a48",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 220,
        "y": 720,
        "wires": [
            [
                "ac3f66d770bb8f56"
            ]
        ]
    },
    {
        "id": "31cb1ca9e4060710",
        "type": "delay",
        "z": "a8ec6104.cb08c",
        "name": "",
        "pauseType": "delay",
        "timeout": "5",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "allowrate": false,
        "outputs": 1,
        "x": 660,
        "y": 760,
        "wires": [
            [
                "dbf50e2146f5e631"
            ]
        ]
    },
    {
        "id": "96d60ca0976c555c",
        "type": "mqtt out",
        "z": "a8ec6104.cb08c",
        "name": "",
        "topic": "home/frontdoor/payload",
        "qos": "",
        "retain": "",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "8c74c5f6.9a7a48",
        "x": 1010,
        "y": 720,
        "wires": []
    },
    {
        "id": "ac3f66d770bb8f56",
        "type": "function",
        "z": "a8ec6104.cb08c",
        "name": "If open",
        "func": "var nvalue = msg.payload.nvalue;\nmsg.payload = {};\nif(nvalue == 1)\n{\nmsg.payload.state = \"ON\";\nreturn msg;\n} \n",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 490,
        "y": 720,
        "wires": [
            [
                "31cb1ca9e4060710",
                "96d60ca0976c555c"
            ]
        ]
    },
    {
        "id": "dbf50e2146f5e631",
        "type": "function",
        "z": "a8ec6104.cb08c",
        "name": "Send Close",
        "func": "msg.payload = {};\nmsg.payload.state = \"OFF\";\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 810,
        "y": 760,
        "wires": [
            [
                "96d60ca0976c555c"
            ]
        ]
    },
    {
        "id": "8c74c5f6.9a7a48",
        "type": "mqtt-broker",
        "name": "MQTTSERVER",
        "broker": "MQTTSERVER",
        "port": "1883",
        "clientid": "",
        "usetls": false,
        "compatmode": true,
        "keepalive": "15",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "closeTopic": "",
        "closePayload": "",
        "willTopic": "",
        "willQos": "0",
        "willPayload": ""
    }
]

HA Part : Instead of the generic setup above (Old post part)

mqtt:
 binary_sensor:
  - name: "FrontDoor"
    state_topic: "home/frontdoor/payload"
    value_template: "{{ value_json.state }}"
    device_class: door

Assembly in Dosbox, and draw a line

Last Updated or created 2022-11-16

Below my setup in Dosbox.
(As used 30 years ago)

First install dosbox (Linux/Windows)

download the package with used files and compilers from here:
https://media.henriaanstoot.nl/assembly.tgz

extract with tar xzvf /tmp/assembly.tgz to a directory

start dosbox and mount the directory as C

mount c /path/assembly

Run “a line”, this a batchfile which starts the editor (qedit)
When closing the file (esc – q menu)
It will compile the assembly and write out a executable

This is the batchfile

@echo off
q %1.asm
cls
masm %1.asm;
link %1.obj;
exe2bin %1.exe %1.com
echo READY!

line assembly code

    NAME lijnentrekroutine

.286

Code SEGMENT
    ASSUME CS:Code,DS:Code
org 100h
Start:
    mov ax,13h            ;set video mode
    int 10h

    mov bx,100
    mov cx,100
hiero:
    mov dx,0a000h
    mov es,dx
    mov ax,320
    mul cx
    add ax,bx
    mov di,ax
    mov al,2
    stosb
    inc bx
    inc bx
    inc cx
    cmp bx,150
    jnz hiero


    mov ah,8
    int 21h
    mov ax,3
    int 10h

    MOV AX,4C00h
    INT 21h

code ends
end start

Hercules to VGA

Last Updated or created 2022-11-16

While playing with MuseScore….
(Typesetting some scores for Pipes and Flute)

This came in: WOOOT

Trident 8900C (1024 x768 max 512Kb)

This is a Trident VGA card. While having a 16bit ISA connector, it can work in a 8bits ISA slot.

A while ago i bought a Laser XT/3, that’s the one my parents had.
This is where i did a lot of assembly programming on.
It’s a 8086 cpu, 640K and has a Hercules/CGA graphics card.

I found loads of assembly files and i want to see if i can get it running again.
While some code was written for hercules, ( That’s the monochrome image you see in the example above ) and a few for EGA (4 colors).

Most of it was written for VGA. Probably on a later machine like a 80386?

But i know there are vga cards for 8 bit msdos computers, and i found one. ( This one is even autodetect, so no jumpers to figure out)

So i’ve put this card in the machine, turned it on, and it works!
I’ve got only 2 examples living on the harddisk of the machine, both black and white … 🙂
I have to search for interesting code in hundreds of files.

Some friends of mine, picture was taken from an amiga genlock digitizer
The intro pages of a “amiga emulator” WHERE is the rest??? (end is a cga starfield demo)

Hercules Card

There is not much info available about this card:

  • Max resolution (Hercules) : 720×348
  • 15 pin analog monitor port (CN1)
  • BIOS enabled JP1 Pins 1 & 2 closed
  • BIOS disabled JP1 Pins 2 & 3 closed
  • CGA selected SW1 On
  • MDA (Hercules) selected SW1 Off

Floppy drive boot

My friend EDK and I made some demo’s like

And a boot demo, which was able to start from a bootsector, went into a graphic mode and ran a demo with sound. Edk wrote a sector loader for this.
I have some 5.25 inch floppy disks, labelled boot demo. So i wanted to try this today …
I needed to change the boot order, so i went online to search for jumper settings.

I see a led when it tries to boot, but my disks are probably formatted 720Kb instead of 360Kb, which this drive is.

So …. TODO!

Find a 720Kb floppy drive (5.25 inch), and sort through my code!
There is a 8bit soundblaster compatible soundcard that i bidding on online, hopefully i’ll get it

Assembly and modes

I wasn’t sure how to sort the assembly code into Hercules and VGA compatible, but i used this table (There are also extended modes for higher resolutions)

mode 0x00text 40×25 gray
mode 0x01text 40×25 16 colors
mode 0x02text 80×25
mode 0x03text 80×25 16 color
mode 0x04graphics mode (CGA) 320×200
mode 0x05graphics mode (CGA) 320×200
mode 0x06graphics mode (CGA) 640×200 (B/W)
mode 0x07text 80×25 Hercules
mode 0x0Fgraphics mode 640×350? gray
mode 0x10graphics mode 640×350?
mode 0x11graphics vga 2 colors
mode 0x12graphics vga 16 colors
mode 0x13graphics 320×200 256 colors
# Set VGA mode
    mov ax,13h
    int 10h         ;screen 320x200 256 colours

# Exit VGA mode
    mov ax,3
    int 10h         ;screen  80x25 text
    mov ax,4c00h
    int 21h         ;back to DOS

WIP – Designing a 7seg memory address “spy”

Last Updated or created 2022-11-15

UNTESTED, haven’t got all components yet!

Sometimes when i’m writing code i want to know what’s happening. For example when i’m working on the display, there is maybe no output.
With the above example i can write to address $01F0 (example address), and it will display on the 7 Segment displays.

Upperleft PLD is my address decoder, which has been running for a while now.

Secondary PLD adds the rest of the Addressbus lines, and gives me the opportunity to select in a range of 16 addresses, using jumpers/

The two smaller PLD’s latch the databus data when addressed.
AND decodes a nibble to 7-Segment output for 0-9A-F.
(There are apparently no chips available which do A-F)

I’m going to add the PLD code when everything works. Let me know if you like the idea.

Should be only a few Euro’s

Radar module RCWL-0516 with MQTT

Last Updated or created 2022-11-16

RCWL-0516 module (radar)

Last year i was playing with this radar module also, but today i made a version with MQTT and a linux client.
(There is a project on the internet which uses a HC-SR04, and a arduino connected to the Laptop. This setup is more sensitive and no need for a usb thinghy.)

HC-SR04 module (ultrasound)

Last years version, using a micro transformer and a ESP-12

When using MQTT i can integrate this in HomeAssistant, Domoticz, NodeRed and more.
But i’ve written a python script which runs on my Laptop.
For example i can: Kill vlc, change to my work desktop, stop sound output and lock the screen. (everything you can script)

I wanted to have a “mobile” version of the sensor so i can place it anywhere. (Frontdoor, gardengate, candydrawer 🙂 )

These modules are very cheap, but do their job well!

I’ve used a Wroom ESP32 and a BattBorg together with the module, that’s it.

Simplified schematic (without the battborg)

I’m using PIN34 as an analog input.

Radar module pins:

  • CDS not used
  • VIN 5V power
  • OUT 0-3.3V signal (analog)
  • GND
  • 3v3 not used

Arduino sketch

#include <WiFi.h>
#include <PubSubClient.h>
#include <Wire.h>

const char* ssid = "MYSSID";
const char* password = "MYPASS";
const char* mqtt_server = "IP-MQTT-SERVER";
const char* mqtt_username = "";
const char* mqtt_password = "";
const char* clientID = "radar";

const int tiltPin = 34;
int tiltState = 0;    
int previousState = 0;   

WiFiClient espClient;

PubSubClient client(espClient);

String translateEncryptionType(wifi_auth_mode_t encryptionType) {
 
  switch (encryptionType) {
    case (WIFI_AUTH_OPEN):
      return "Open";
    case (WIFI_AUTH_WEP):
      return "WEP";
    case (WIFI_AUTH_WPA_PSK):
      return "WPA_PSK";
    case (WIFI_AUTH_WPA2_PSK):
      return "WPA2_PSK";
    case (WIFI_AUTH_WPA_WPA2_PSK):
      return "WPA_WPA2_PSK";
    case (WIFI_AUTH_WPA2_ENTERPRISE):
      return "WPA2_ENTERPRISE";
  }
}
 
void scanNetworks() {
   int numberOfNetworks = WiFi.scanNetworks();
   Serial.print("Number of networks found: ");
  Serial.println(numberOfNetworks);
   for (int i = 0; i < numberOfNetworks; i++) {
 
    Serial.print("Network name: ");
    Serial.println(WiFi.SSID(i));
 
    Serial.print("Signal strength: ");
    Serial.println(WiFi.RSSI(i));
 
    Serial.print("MAC address: ");
    Serial.println(WiFi.BSSIDstr(i));
 
    Serial.print("Encryption type: ");
    String encryptionTypeDescription = translateEncryptionType(WiFi.encryptionType(i));
    Serial.println(encryptionTypeDescription);
    Serial.println("-----------------------");
 
  }
}
 
void connectToNetwork() {
  WiFi.begin(ssid, password);
   while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Establishing connection to WiFi..");
  }
   Serial.println("Connected to network");
 }

void reconnect() {
  while (!client.connected()) {
    if (client.connect(clientID, mqtt_username, mqtt_password)) {
    } else {
      delay(2000);
    }
  }
}
void setup()
{
  {
    Serial.begin(115200);
    scanNetworks();
    connectToNetwork();
    Serial.println(WiFi.macAddress());
    Serial.println(WiFi.localIP());
    client.setServer(mqtt_server, 1883);
    pinMode(tiltPin, INPUT);
  }
}
void loop() {
  tiltState = analogRead(tiltPin);
    if (tiltState < 3048) {
      client.publish("radar/state", "0"); //
    } else {
      client.publish("radar/state", "1"); //
    }
     delay(100);
   {
    if (!client.connected()) {
      reconnect();
    }
    client.loop();
  }
}

Lockscreen!

Below shows the speed of detection, and sending though the network

Python script which does a lock-screen using XDOTOOL

from paho.mqtt import client as mqtt_client
import subprocess
import time

broker = 'MQTT-SERVER'
port = 1883
topic = "radar/state"
client_id = "radarclient"

def connect_mqtt() -> mqtt_client:
    def on_connect(client, userdata, flags, rc):
        if rc == 0:
            print("Connected to MQTT Broker!")
        else:
            print("Failed to connect, return code %d\n", rc)

    client = mqtt_client.Client(client_id)
    client.on_connect = on_connect
    client.connect(broker, port)
    return client

def subscribe(client: mqtt_client):
    def on_message(client, userdata, msg):
        state = msg.payload.decode()
        print (state)
        if state == "1":
            subprocess.Popen(["xdotool","key","Super_L+l"])
            time.sleep(30)


    client.subscribe(topic)
    client.on_message = on_message

def run():
    client = connect_mqtt()
    subscribe(client)
    client.loop_forever()

if __name__ == '__main__':
    run()

change
subprocess.Popen([“xdotool”,”key”,”Super_L+l”])
into
subprocess.Popen([“switchdesktop”])
to run a script named switchdesktop

#!/bin/bash
# This is the switchdesktop script, it goes to the next screen using winows-page-down combo
xdotool key "Super_L+Page_Down"

Todo:

3D print a case
Make a version which becomes a Access Point.
Then make another arduino setup which controls my Nikon.
So it can act like a wildcam (offline)

Something like below, using a optocoupler ( i still got some leftovers from my doorbell to gpio-pin project.)

Workshop Cyanotype

Last Updated or created 2023-01-14

The cyanotype (from Ancient Greek kuáneos, “dark blue” and túpos, “mark, impression, type”) is a slow-reacting, photographic printing technique. It produces a cyan-blue print used for art as monochrome imagery applicable on a range of supports, and for reprography in the form of blueprints. For any purpose, the process usually uses two chemicals: ferric ammonium citrate or ferric ammonium oxalate, and potassium ferricyanide, and only water to develop and fix. Announced in 1842, it is still in use.

This technique was also used as a method of copying drawings.
For example buildings and schematics. While making copies of drawings with the exact dimensions of the original, making the result untemperable was another big plus. ( You could not move/redraw walls for example on the copy)

I’ve printed a photo on transparant sheets to experiment with.
(Next time, i’ll take a larger size, and fix the contrast.

The most interesting ones i’ve made today: