Mikrotik

Switches and access-points

Today i got my RB4011 ! Wooot!

Total tally

  • MikroTik CRS305-1G-4S+IN – Lab
  • MikroTik RB2011UiAS-RM – Office
  • MikroTik hAP AC2 – Studio
  • MikroTik CRS109-8G-1S-2HnD-IN – Attic
  • MikroTik RB4011iGS+5HacQ2HnD-IN – Livingroom
  • NEW (2022-04-02) crs125-24g-1s-in (2022-04-02)

To replace .. 4 SLM2008 and a TPLink switch 🙂

How much fun is this! .. A display on a switch!

I’ll be posting something about connecting an arduino to the serial console using a tcp server later.

Mikrotiks are all you can eat .. And there is a lot of functionality. One of the main features (besides being switches and routers)

  • Openvpn server
  • DIY display connect
  • Proxy
  • Today Vincent mentioned Mqtt plugin (2022-apr-6)
  • https://help.mikrotik.com/docs/display/ROS/Packet+Sniffer sounds interesting also

Installing extra packages

  • Download correct package zip from ( https://mikrotik.com/download )
  • Extract and use file upload
  • Reboot your mikrotik

Mikrotik Guest Network

I’ve got several AccessPoints in my network.
Using a roaming setup, clients can connect to strongest AP.

For our Folkband i’ve setup same.
With the exception of those clients only being able to connect to the Internet, and not the rest of my Network

  • Virtual Access Point
  • Own subnet
  • dhcp server only for this access point
  • NAT and Firewall rules for access limitation
/interface bridge 
add name=bridgeguest
/interface wireless security-profiles 
add authentication-types=wpa2-psk eap-methods="" management-protection=allowed mode=dynamic-keys name=guest supplicant-identity=MikroTikHAP wpa2-pre-shared-key=guestkey
/interface wireless
add disabled=no mac-address=MACADDRESS master-interface=wlan1 name=guest security-profile=guest ssid=guest station-roaming=enabled wds-default-bridge=bridge wps-mode=disabled
/ip pool
add name=guest ranges=10.5.0.2-10.5.0.250
/ip dhcp-server
add address-pool=guest disabled=no interface=bridgeguest name=dhcpserverguest
/interface bridge port
add bridge=bridgenb interface=guest
/ip address
add address=10.1.0.5/24 comment=defconf interface=ether2 network=10.1.0.0
add address=10.5.0.1/24 interface=bridgeguest network=10.5.0.0
/ip dhcp-client
/ip dhcp-server network
add address=10.5.0.0/24 dns-server=1.1.1.1 gateway=10.5.0.1
/ip dns static
add address=10.1.0.5 name=router.lan type=A
/ip firewall filter
add action=drop chain=input dst-address=10.1.0.5 dst-port=22,80,443,8291,21,23 protocol=tcp src-address=10.5.0.1-10.5.0.254
add action=drop chain=input dst-address=MYNETWORKSHERE/16 src-address=10.5.0.2-10.5.0.250
add action=drop chain=forward dst-address=MYNETWORKSHERE/16 src-address=10.5.0.2-10.5.0.250
add action=drop chain=forward dst-address=MYNETWORKSHERE/16 src-address=10.5.0.2-10.5.0.250
/ip firewall nat
add action=masquerade chain=srcnat comment="defconf: masquerade" ipsec-policy=out,none out-interface-list=WAN
add action=accept chain=srcnat src-address=10.5.0.0/24

My computer Lab

Our servers came in! (20200612)

Bought some large servers with Vincent.
3 ProLiant ML350 G6 with loads of memory and cores.
My 2 nodes are running Ovirt Virtualisation, connected to a qnap iscsi host using 10gbps SFPs. Vincents server is running Proxmox.

Domoticz age checker

A script to check the age of sensors.
Sometimes you don’t have a good 433Mhz connection.
Or the battery has died of your sensor.

This script will warn you.

sensoragescript.sh (for cron)

#!/bin/bash
#Call as follows
#sensoragescript.sh <ipdomoticz> <idx-of-sensor> <age-to-test-in-seconds>

now=$(date +%s)
lastupdate=$(curl -s -i -H "Accept: application/json" "http://$1:8080/json.htm?type=devices&rid=$2" |  grep LastUpdate | cut -f4 -d\" )
#echo $lastupdate
seen=$(date -d "$lastupdate" +%s)
#echo $seen
#echo "$(( $now - $seen))"
difftime="$(( $now - $seen))"
if [ $difftime -gt $3 ] ; then
  echo "WARN : too old - $difftime seconds"
  exit 1
else
  echo "OK : $difftime seconds"
  exit 0
fi

Outputs:

./new.sh 192.168.1.1 123 60
OK : 22 seconds

./new.sh 192.168.1.1 123 60
WARN : too old - 69 seconds

check_mk / icinga check

#!/bin/bash
IPDOMO=192.168.1.1
IDX=123
agewarn=300
now=$(date +%s)
lastupdate=$(curl -s -i -H "Accept: application/json" "http://$IPDOMO:8080/json.htm?type=devices&rid=$IDX" |  grep LastUpdate | cut -f4 -d\" )
seen=$(date -d "$lastupdate" +%s)
difftime="$(( $now - $seen))"
if [ $difftime -gt $agewarn ] ; then
  echo "1 \"WARN - Age check Fridge\" realage=$difftime|age=$agewarn Age of fridge"
  exit 1
else
  echo "0 \"OK - Age check Fridge\" realage=$difftime|age=$agewarn Age of fridge"
  exit 0
fi

Domotemp – domoticz temperature floorplan

For my home automation i’m using Home Assistant and Domoticz.
All 433Mhz Temperature/Humidity are connected to a RFXcom device on two domoticx instances. (Master slave construction)

I’ve made a php script and a bash script to draw all sensors on a floorplan in realtime.

There is also a cron running which takes a snapshot of the generated image every 5 minutes.
These images are being converted to MP4 and animated GIF to have a timelapse with all temperatures displayed on a floorplan.

An obfuscated view of the floorplan

The circles are where sensors are placed.
Colors are from blue till red, representing the heat.
In the center is the measured temperature value.

The (shortened) PHP script: (index.php)

<?php
header('Content-type: image/png');
// This is the floorplan empty ..
$png_image = imagecreatefrompng('plattegrondenmerge.png');
$white = ImageColorAllocate($png_image, 0, 0, 0);

$max = 40;
$min = -10;

// living
// getstate is a bash script (see below which gets the values from domoticz using curl) 
// 840 is the domoticz idx
$temp840 = shell_exec('./getstate 840');
// A gray circle will be drawn if the temperature age is > 500 seconds
$age = shell_exec('./new.sh 18 840 500 >/dev/null || echo gray');
// location of circle
$start_x = 950;
$start_y = 760;
$line = $temp840 + 10;
// get x-th line from colors
$colorfromlist = shell_exec("tail --lines=$line ./colors2 | head -1");
if(strpos($age, "gray") !== false){
 $colorfromlist = "128,128,128";
};
$colors = explode(",", $colorfromlist);
$color = imagecolorallocatealpha($png_image, $colors[0], $colors[1], $colors[2], 50);
// draw circle
imagefilledellipse ($png_image, $start_x, $start_y, 175, 175, $color);
$start_x = $start_x - 70;
$start_y = $start_y + 15;
// add text
imagettftext($png_image, 24, 0, $start_x, $start_y, $white, './verdana.ttf', $temp840);

// winecellar
$temp840 = shell_exec('./getstate 839');
$age = shell_exec('./new.sh 18 839 700 >/dev/null || echo gray');
$start_x = 560;
$start_y = 840;
$line = $temp840 + 10;
$colorfromlist = shell_exec("tail --lines=$line ./colors2 | head -1");
if(strpos($age, "gray") !== false){
 $colorfromlist = "128,128,128";
};
$colors = explode(",", $colorfromlist);
$color = imagecolorallocatealpha($png_image, $colors[0], $colors[1], $colors[2], 50);
imagefilledellipse ($png_image, $start_x, $start_y, 175, 175, $color);
$start_x = $start_x - 70;
$start_y = $start_y + 15;
imagettftext($png_image, 24, 0, $start_x, $start_y, $white, './verdana.ttf', $temp840);

// ETC ETC

imagesavealpha($png_image, TRUE); 

  imagepng($png_image);
  imagedestroy($png_image);
?>


getstate bash script
(gets the temperature from domoticz instance1 given an idx)

#!/bin/bash
curl -s --connect-timeout 2 --max-time 5 "http://ip-domoticz1:8080/json.htm?type=devices&rid=$1" | egrep "Temp|Humid" | awk '{print $3 }' | cut -f1 -d\. | grep -v \" | tr -d "\n\r" | sed s/,/%\ /g | awk '{ print $2"° "$1 }'

new.sh script gets the age of the reading from
domoticz1 or domoticz1
Usage: ./new.sh <domoticz-last-numer-ip> <idx> <maxageinseconds>

#!/bin/bash
## server idx time
now=$(date +%s)
lastupdate=$(curl -s -i -H "Accept: application/json" "http://192.168.1.$1:8080/json.htm?type=devices&rid=$2" |  grep LastUpdate | cut -f4 -d\" )
#echo $lastupdate
seen=$(date -d "$lastupdate" +%s)
#echo $seen
#echo "$(( $now - $seen))"
difftime="$(( $now - $seen))"
if [ $difftime -gt $3 ] ; then
  echo "WARN : too old - $difftime seconds"
  exit 1
else
  echo "OK : $difftime seconds"
  exit 0
fi

colors2 – a list of colors representing the temperature
red -> green -> blue

255,0,0
255,10,0
255,20,0
255,30,0
255,40,0
255,60,0
255,70,0
255,80,0
255,90,0
255,100,0
255,120,0
255,130,0
255,140,0
255,150,0
255,160,0
255,180,0
255,190,0
255,200,0
255,210,0
255,220,0
255,240,0
255,250,0
253,255,0
215,255,0
176,255,0
101,255,0
62,255,0
23,255,0
0,255,16
0,255,54
0,255,131
0,255,168
0,255,208
0,255,244
0,228,255
0,196,255
0,180,255
0,164,255
0,148,255
0,132,255
0,100,255
0,84,255
0,68,255
0,50,255
0,34,255
0,2,255
0,0,255
1,0,255
2,0,255
3,0,255
5,0,255

Crontab and gif/mp4 generators

# crontab
5 * * * * root /scripts/domotemp/crontemp.sh

# crontemp.sh
# stores an image with a date.
cd /www/webdir/domotemp
wget https://mydomoticzweb/domotemp/ -O $(date +%Y%m%d%H).png >/dev/null 2>/dev/null 1>/dev/null


# rest scripts
mkdir -p embed
# below adds the time to the image
ls 2020*png | sort -n -k1 | while read ; do hour=$(echo $REPLY | cut -c9,10) ; convert -pointsize 80 -fill black -draw 'text 1650 100 '\"$hour:00\"'' -resize 960x540 $REPLY  embed/$REPLY ;done
# convert to gif
convert $(ls embed/2020*png | sort -n -k1) animation.gif
# convert to mp4
ffmpeg -f image2 -r 24 -pattern_type glob -i '*.png'   -vcodec libx264 -profile:v high444 -refs 16 -crf 0 -preset ultrafast -vf scale=1920:1080 domotemp.mp4

Making Art using 220V

I have a rol of printer paper that was used by an old 8bit computer. I forgot which one, one out of my collection.

Fractal-like ‘art’

I dont think it is thermal paper, maybe the printer uses electricity just like the movie clip you see below. (Well .. not using 220V directly on the paper maybe) 🙂

Having fun at our old place during moving to Hilversum.

3D Printing

In 2012 I started with 3D printing, I didn’t have my own yet. So it was done using shapeways.
April 2019 I ordered my own, a Creality CR-10S.

Specs

  • Build Volume: 300 x 300 x 400mm
  • Layer Thickness: 0.1-0.4mm
  • Positioning Precision: Z-axis – 0.0025mm, X & Y-axis – 0.015mm
  • Nozzle Temperature: 250°C
  • Printing Speed: 200mm/s
  • Filament Diameter: 1.75mm
  • Printer Weight: 9kg
  • Printing Filament: PLA, ABS, TPU, Wood, Carbon fiber, etc.
  • Input Support: SD card/USB
  • File Types: STL/OBJ/G-Code/JPG
  • Supports(OS): Windows/Linux/Mac/XP
  • Printing Software: Cura/Repetier-Host
  • Frame & Body: Imported V-Slot Aluminum Bearings
  • Power Requirement Input: AC110V~220V, Output: 12V, Power 270W
  • Output: DC12V, 10A 100~120W (Support storage battery)
  • Working Condition Temp:10-30°C, Humidity: 20-50%

Problem with this 3D Printer is the lack of a thermal runaway detection. My solution is a MQTT/Nodered warning system which plays an alarm and uses a shelly to disconnect the power.
https://www.henriaanstoot.nl/2022/05/11/mqtt-bash-nodered-notify/

Software I Use – see other posts

  • Openscad
  • Cura
  • Meshroom
  • Blender
  • Sketchup

Hardware

  • Octoprint on a raspberry pi – (with Octoscreen)
Octoscreen (image from internet) I’m using a faytec touchscreen monitor
  • Octoprint monitor
Little display on my desk which monitors the progress

I’m using a filament sensor like the one in below picture

It used to be a DIY thingy using an arduino. (below)

Filament under my table ( in the “dark” )

Software on my mobile

  • Octoremote
    https://play.google.com/store/apps/details?id=com.kabacon.octoremote

Hints and tips

  • Use painters tape against bending of the glass, it will warp because of the heat.
  • Use 3D spray to fix model to base-plate.
    (I used a gluestick before)
  • Always think of model placement, less support the better.
  • Try to remember which fill-in is the best for your purpose.
  • Calibrate distance print tool and glass using printing paper.
  • Know your printer, make a lot of test prints when starting.
  • Learn / read about 3D printing finishing. Sanding/smoothing/melting.
    I’ve got some smoothing liquid (print coating) , a dremel and below tool
  • Use a print model to test your leveling
    ( https://www.printables.com/model/69956-bed-level-calibration-square-grid )
  • Learn how gcode’s work!

Want to know what filament is in your gcode?

grep M104 <file.gcode>

# M104 is the temperature

M104 200 -> PLA
M104 240 -> PETG

Laser engraving using my 3D printer (pre lasercutter)

Websites

  • Yeggi
  • Thingiverse
  • printables – not that much

UPDATE 20230803

Best gap filler i found which is easily sanded down with a dremel.
Alabastine Polyester Plamuur

"If something is worth doing, it's worth overdoing."