Category Archives: Computer

Webcam image slash command mattermost

I’ve got my own chat server, because WhatsApp sucks.

With this I can play around.

Below is a script to capture an image from a (Reolink) webcam, and show this in a Mattermost channel.

You need to configure your /slash command in Mattermost and a webserver with PHP

When entering
/labcam
in a channel, an image will be shown.

Code:

<?php

// See token from screenshots above
$expected_token = 'YOUR_MATTERMOST_TOKEN';
$token = $_POST['token'] ?? '';

if ($token !== $expected_token) {
    http_response_code(403);
    echo 'Invalid token, go away';
    exit;
}


// Reolink camera settings
$ip = '192.168.1.2'; // Replace with your camera IP
$user = 'admin';       // Camera username
$pass = 'admin';// Camera password
$rs = uniqid();        // Unique request string

$url = "http://$ip/cgi-bin/api.cgi?cmd=Snap&channel=0&rs=$rs&user=$user&password=$pass";

// Temporary image save path (ensure this directory is public and writable)
$image_filename = 'snapshot_' . time() . '.jpg';
$image_path = __DIR__ . '/snapshots/' . $image_filename;  // e.g., public_html/snapshots/
$image_url = 'https://labcam.henriaanstoot.nl/snapshots/' . $image_filename; // Public URL

// Fetch image from Reolink using cURL
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, "$user:$pass");
$image_data = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

if ($http_code !== 200 || !$image_data) {
    echo json_encode([
        'response_type' => 'ephemeral',
        'text' => 'Failed to get snapshot from Reolink camera.',
    ]);
    exit;
}

// Save image
file_put_contents($image_path, $image_data);

// Respond to Mattermost
$response = [
    'response_type' => 'in_channel',
    'text' => 'Live snapshot from camera:',
    'attachments' => [[
        'image_url' => $image_url,
        'fallback' => 'Reolink snapshot'
    ]]
];

header('Content-Type: application/json');
echo json_encode($response);

Little OBS toy.

I use OBS sometimes to explain things, I thought it would be nice to have a moving avatar thingy in my screencast which moves when I talk.

The image is a transparent PNG, and I’m moving it up and down using the microphone and a python script.

CODE:

import pygame
import pyaudio
import numpy as np
import sys

# Settings
PNG_PATH = "your_image.png"  # Replace with your transparent PNG path
CHUNK = 1024
FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 44100
MOVEMENT_THRESHOLD = 1
GRAVITY = 3 # Tweak this, to get smoother "talk" bounch
JUMP_MULTIPLIER = 3  # Controls jump power Tweak this shit
MAX_JUMP_HEIGHT = 30   # Max  bounce 
START_OFFSET = -450      # How far below screen the PNG starts ( so my avator stays covered in bottom )

# Initialize PyAudio
p = pyaudio.PyAudio()
stream = p.open(format=FORMAT,
                channels=CHANNELS,
                rate=RATE,
                input=True,
                frames_per_buffer=CHUNK)

# Initialize Pygame
pygame.init()
info = pygame.display.Info()
screen_width, screen_height = info.current_w, info.current_h
screen = pygame.display.set_mode((screen_width, screen_height), pygame.FULLSCREEN)
pygame.display.set_caption("Mic Bounce PNG")

# Load image
image = pygame.image.load(PNG_PATH).convert_alpha()
img_rect = image.get_rect()
img_rect.centerx = screen_width // 2
img_rect.top = screen_height + START_OFFSET  # Start below the screen

velocity_y = 0
clock = pygame.time.Clock()

def get_loudness():
    data = np.frombuffer(stream.read(CHUNK, exception_on_overflow=False), dtype=np.int16)
    volume = np.linalg.norm(data)
    return volume / CHUNK

# Bottom and top bounce limits
bottom_y = screen_height + START_OFFSET
top_y = screen_height + START_OFFSET - MAX_JUMP_HEIGHT

try:
    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT or \
               (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE):
                raise KeyboardInterrupt

        loudness = get_loudness()

        if loudness > MOVEMENT_THRESHOLD and img_rect.top >= bottom_y:
            # Jump upward with capped power
            velocity_y = -int(min((loudness - MOVEMENT_THRESHOLD) * JUMP_MULTIPLIER, MAX_JUMP_HEIGHT))

        # Apply gravity
        velocity_y += GRAVITY
        img_rect.y += velocity_y

        if img_rect.top >= bottom_y:
            img_rect.top = bottom_y
            velocity_y = 0

        if img_rect.top <= top_y:
            img_rect.top = top_y
            velocity_y = 0

        # Draw chromakey green background
        screen.fill((0, 255, 0))

        # Draw PNG
        screen.blit(image, img_rect)

        pygame.display.flip()
        clock.tick(60)

except KeyboardInterrupt:
    stream.stop_stream()
    stream.close()
    p.terminate()
    pygame.quit()
    sys.exit()

Working on a Bluetooth beacon game for a friend.

Got some bluetooth beacons in the mail.

The plan is to hide these in the woods, and children have to find them using a scanner device.

3D printed scanner (model not mine, but changed to hold electronics

Using a ESP32 with bluetooth, using RSSI (strength of signal) I can limit the range of detection.

The order of finding the tags is important, so a hidden tag should not be found when another should be found first.

These tags, hidden in toys, should be placed in a treasure chest.
(In order)
Then lights and sounds should hint the kids that they have successfully completed the mission.

So same detecting but even shorter range ESP is hidden in the Chest.

Some leds or a single blinking one should give hints about the distance of the object.

=== Matching iTags ===
MAC: 5b:08:10:4d:2a:01 | RSSI: -47
MAC: 5b:45:aa:0d:f7:9c | RSSI: -31 #### NEAR 
MAC: 5b:88:fc:fc:e8:a9 | RSSI: -94 #### FAR AWAY
MAC: 5b:8b:00:00:1d:40 | RSSI: -66 

Some test code:

#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEScan.h>
#include <BLEAdvertisedDevice.h>

int scanTime = 5; // seconds
BLEScan* pBLEScan;

void setup() {
  Serial.begin(115200);
  Serial.println("Starting BLE scan...");

  BLEDevice::init("");
  pBLEScan = BLEDevice::getScan();
  pBLEScan->setActiveScan(true);
  pBLEScan->setInterval(100);
  pBLEScan->setWindow(99);
}

void loop() {
  BLEScanResults results = *pBLEScan->start(scanTime, false);
  Serial.println("=== Matching iTags ===");

  for (int i = 0; i < results.getCount(); i++) {
    BLEAdvertisedDevice device = results.getDevice(i);
    String mac = device.getAddress().toString();

    if (mac.startsWith("5b:")) {
      Serial.print("MAC: ");
      Serial.print(mac);
      Serial.print(" | RSSI: ");
      Serial.println(device.getRSSI());
    }
  }

  Serial.println("======================");
  pBLEScan->clearResults();
  delay(2000);
}

Mqtt Pong

This weekend we went to Nerdland in Belgium.
I saw a cool game when we had to wait before some talks started.

What is so special about pong?
Well, half of the audience was playing the other part of the audience.
250 against 250 Multiplayer.
It used mqtt websockets, and the audience mobile phones with tilting.
Average of 33+ % choosing up? Paddle goes up, Center and down the same.

I think I can make it myself.
So below my two days progression.
MQTT via internet.
Sound and score counter.
Using the mobile phone’s tilt sensor.

I changed left and right because we sat in the wrong chairs.

Maybe I’m going to change it into some 3D maze game.
Code soon

Locked phone data recovery

A friend came with a locked phone.
His son had changed the swipe lock thingy, and forgot what it was,

How I recovered Pictures and Movies:

ADB was turned off, and MTP doesn’t work when locked.
Phone was one of the below.
MT6781, MT6789, MT6855, MT6886, MT6895, MT6983, MT8985

git clone https://github.com/bkerler/mtkclient
cd mtkclient
pip3 install -r requirements.txt
./python3 mtk.py rl test

Press Volume up and volume down and keep pressed.
Now connect the USB cable.

Partitions are downloading, we need userdata.bin
This takes a while!

Next: Extract data

Install Guestfish

sudo guestfish --ro -a userdata.bin
<fs> 
run
list-filesystems
mount /dev/sda /
ls /
glob copy-out /media/0/DCIM/Camera/* .

Data extracted and phone was still locked.
That’s all that was needed, factory reset was next.

Weather display using LilyGO T5-4.7 inch S3 E-paper E-ink ESP32-S3

I was planning to make a RSS reader using this display, but I came across a weather display project I wanted to check out.
(So I probably end up buying another one)

There are many questions and issues around this project using the S3.

So here is my solution.

Install vscode

Goto plugins and install platformio

git clone https://github.com/Xinyuan-LilyGO/LilyGo-EPD-4-7-OWM-Weather-Display.git

Warning this is NOT the branch you want to use

git checkout web

(git pull)

open directory in code

open platformio.ini and change line 13
default_envs = T5_4_7Inc_Plus_V2
(If needed add upload_port = /dev/tty**** at the end)

Change INO file lines 144-146.
Comment serial out, else update won’t work using regular power or battery.



When saving this platformio.ini file, some downloading and installing should be popping up.
When issues occur about libraries see below.

Fill out
data>config.json
and owm_credentials.h to be sure.
(use owm_credentials information to fill config.json)

Next press the platformio icon

Fix for uploading:

Press and hold STR_IO0 button
Press REST button
Release STR_IO0 button

Libraries:

Press platformio icon, libaries and install ArduinoJson, Button2 and LilyGo-EPD47 (select your project while doing so!)

Note: Per default once per hour update, change if you want to.
Line 70 in the INO file

Build/Upload errors? .. Press clean to recompile using a clean state !

Animatronics again

I like animatronics.

In the past, I made animatronics using :
Windscreen wipers, Servo controllers and stepper motors.

I bought a new controller with an 8 channel receiver. Now I can manually control and test setups.

Some “drunk” eyes. Need to fix.

I altered and 3D printed this model from Will Cogley

Now I have to make this more programmable, python on a RPi should do it.

Controller I used for the tentacle animatronic

Planning to use a 360 degrees lidar, so the eyes can follow you around.

I got some other new stuff in also:

Some 360 degrees servo’s and a mini led strip which a connected to a WLED with digital I2S microphone.

Pushover notifier for dates

Below is my python script to push messages via pushover to my phone.

It’s being run from a cron during the day.

CODE

import csv
import datetime
import requests

# configure own creds
PUSHOVER_USER_KEY = 'keykeykeykeykeykeykeykey'
PUSHOVER_API_TOKEN = 'tokentokentokentokentokentokentoken'
CSV_FILE = '/data/notifications.csv'

def send_pushover_notification(message):
    url = "https://api.pushover.net/1/messages.json"
    payload = {
        "token": PUSHOVER_API_TOKEN,
        "user": PUSHOVER_USER_KEY,
        "message": message
    }
    response = requests.post(url, data=payload)
    if response.status_code != 200:
        print("Failed to send notification:", response.text)

def check_and_notify():
    today = datetime.date.today()
    with open(CSV_FILE, newline='') as csvfile:
        reader = csv.DictReader(csvfile)
        for row in reader:
            try:
                day = int(row['day'])
                month = int(row['month'])
                if today.day == day and today.month == month:
                    send_pushover_notification(row['message'])
            except ValueError:
                continue

if __name__ == "__main__":
    check_and_notify()

notifications.csv file

day,month,message
1,1,Birthday of a new year
16,05,Project Deadline
16,05,Test2 (blah) 2
7,3,Glorious bastard Rik Mayall birthday
27,3,International whisky day

Nice to haves (didn’t implement because i’m a lazy bastard)

  • 3rd Saturday every may
  • Getting dates or updates from another app
  • Selecting Pushover device, level of alertness .. etc

Wireless ping tester with beeps using Wemos

While I’ve used a Laptop with a ping script I made in the past, I needed something more portable.

So I build:

  • Scan for wifi networks
  • Connect
  • Enter IP to ping
  • Buzzer beeps when ICMP packet received
  • Gateway not reachable ? Sound alarm note

This way I can use both hands, hanging upside-down in a hard-to-reach place, without turning my head to a screen or my phone.

CODE (Below code is for D6)

#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>
#include <ESP8266Ping.h>

ESP8266WebServer server(80);
String pingHost = "";
bool startPinging = false;
unsigned long lastPingTime = 0;
bool gpioState = false;

void setup() {
  Serial.begin(115200);
  pinMode(D6, OUTPUT);  

  // WiFiManager captive portal
  WiFiManager wm;
  if (!wm.autoConnect("ESP_SetupAP")) {
    Serial.println("Failed to connect, restarting...");
    ESP.restart();
  }

  Serial.println("WiFi connected. IP:");
  Serial.println(WiFi.localIP());

  // Web UI
  server.on("/", HTTP_GET, []() {
    String html = "<html><body><h2>ESP Continuous Ping</h2>"
                  "<form action='/start'>"
                  "Host/IP to ping: <input name='host' type='text'>"
                  "<input type='submit' value='Start Pinging'>"
                  "</form></body></html>";
    server.send(200, "text/html", html);
  });

  server.on("/start", HTTP_GET, []() {
    if (!server.hasArg("host")) {
      server.send(400, "text/plain", "Missing 'host' parameter.");
      return;
    }
    pingHost = server.arg("host");
    startPinging = true;
    server.send(200, "text/plain", "Started pinging " + pingHost);
  });

  server.begin();
}

void loop() {
  server.handleClient();

  if (startPinging && millis() - lastPingTime > 2000) {
    lastPingTime = millis();
    bool success = Ping.ping(pingHost.c_str(), 1);

    if (success) {
      gpioState = !gpioState;
      digitalWrite(D6, HIGH);
      delay(500);
      digitalWrite(D6, LOW);
      delay(500);
      Serial.println("Ping success, toggled D6.");
    } else {
      Serial.println("Ping failed.");
      digitalWrite(D6, LOW);
    }
  }
}

Further ideas

D2 pin because easier soldering

New project : Find nearest booze shop.

Or anything else. ( idea from a reddit post )

UPDATE: 20250523

Combining a GPS module, compass, a LED ring and some code, I want to make a little device which shows you the way to the nearest … something.

To make it completely standalone, I have to use a SIM module. (Same as I have used before) This POC will use my phone as hotspot.

The LED ring will show the direction to go.

Edit: Maybe not a LED ring but a little display.

As previously posted, I was playing with Overpass turbo.
Using an API, I can use code to query this.

  • Arduino sends latitude, longitude to my webserver
  • Webserver queries API for neastest POIs and calculates distance.
  • Send data from webserver to arduino
  • Arduino uses heading data to light up direction LED
    (also on secondary display with distance info?)
    edit: and shop info

Test code for my web server to query the data

import overpy
import math

api = overpy.Overpass()

# This location will be filled with data from GPS module on Arduino.
latitude = 52.2270745        # Center latitude (e.g. Berlin)
longitude = 5.177519      # Center longitude
box_size = 0.05         # Box size in degrees (about ~5 km)

south = latitude - box_size
north = latitude + box_size
west = longitude - box_size
east = longitude + box_size

def haversine(lat1, lon1, lat2, lon2):
    R = 6371  # Earth radius in km
    phi1 = math.radians(lat1)
    phi2 = math.radians(lat2)
    d_phi = math.radians(lat2 - lat1)
    d_lambda = math.radians(lon2 - lon1)

    a = math.sin(d_phi / 2)**2 + math.cos(phi1) * math.cos(phi2) * math.sin(d_lambda / 2)**2
    c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a))

    return R * c  # Distance in kilometers

# Calculate bearing in degrees (0-360)
def bearing(lat1, lon1, lat2, lon2):
    phi1 = math.radians(lat1)
    phi2 = math.radians(lat2)
    delta_lon = math.radians(lon2 - lon1)

    x = math.sin(delta_lon) * math.cos(phi2)
    y = math.cos(phi1) * math.sin(phi2) - math.sin(phi1) * math.cos(phi2) * math.cos(delta_lon)

    initial_bearing = math.atan2(x, y)
    compass_bearing = (math.degrees(initial_bearing) + 360) % 360  # Normalize to 0–360

    return compass_bearing

# Overpass QL query
query = f"""
[out:json];
node
  ["shop"="alcohol"]
  ({south}, {west}, {north}, {east});
out body;
>;
out skel qt;
"""

try:
    result = api.query(query)

    # Collect and sort places by distance
    places = []
    for node in result.nodes:
        node_lat = float(node.lat)
        node_lon = float(node.lon)
        distance = haversine(latitude, longitude, node_lat, node_lon)
        direction = bearing(latitude, longitude, node_lat, node_lon)
        name = node.tags.get("name", "Unnamed")
        places.append((distance, direction, name, node_lat, node_lon))

    places.sort()

    print(f"Found {len(places)} alcohol-related places sorted by distance:")
    for dist, dir_deg, name, lat, lon in places:
        print(f"- {name} at ({lat:.5f}, {lon:.5f}) — {dist:.2f} km, {dir_deg:.0f}°")

except Exception as e:
    print(f"Error: {e}")

Output:

Found 10 alcohol-related places sorted by distance:
- The Skiff at (52.22583, 5.17860) — 0.16 km, 152°
- Onzewijnen at (52.22612, 5.17045) — 0.49 km, 258°
- Gall & Gall at (52.23244, 5.19204) — 1.15 km, 59°
- Gall & Gall at (52.21536, 5.16735) — 1.48 km, 208°
- Eric's Beer Craft at (52.21549, 5.16632) — 1.50 km, 211°
- Slijterij at (52.21082, 5.15692) — 2.29 km, 218°
- Gall & Gall at (52.21590, 5.14074) — 2.80 km, 244°
- Gall & Gall at (52.25422, 5.22705) — 4.53 km, 48°
- Gall & Gall at (52.26808, 5.18348) — 4.58 km, 5°
- Il DiVino at (52.27507, 5.16414) — 5.41 km, 350°

Example using Overpass Turbo to find breweries

Other ideas

  • Geocaching (Thanks Vincent)
  • Find each other at festivals?

UPDATE

Building the hardware : First design

Screen programming (First setup)

Some test code

#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_GC9A01A.h"

// Overrule stuff
#define TFT_CS 18   // Chip select
#define TFT_DC 5    // Data/command mode
#define TFT_BL 4    // Backlight control
#define TFT_MOSI 12 // SPI Out AKA SDA
#define TFT_SCLK 13 // Clock out AKA SCL 
#define TFT_MISO -1 // pin not used
#define TFT_RST 23  // Reset ################# IMPORTANT, won't work without!! Took me a hour!

// Need this changed from example also
Adafruit_GC9A01A tft(TFT_CS, TFT_DC,TFT_MOSI,TFT_SCLK,TFT_RST,TFT_MISO);

float angle = 0;

void setup() {
  tft.begin();
  tft.setRotation(0);
  tft.fillScreen(GC9A01A_BLACK);
  drawCompassFace();
}

void loop() {
  drawNeedle(angle, GC9A01A_RED);
  delay(1000);
  drawNeedle(angle, GC9A01A_BLACK);  // Erase previous needle
  angle += 15;
  if (angle >= 360) angle = 0;

  tft.setCursor(60, 100);
  tft.setTextColor(GC9A01A_WHITE);  tft.setTextSize(2);
  tft.println("230 Meters");

}

// Draw static compass face
void drawCompassFace() {
  int cx = tft.width() / 2;
  int cy = tft.height() / 2;
  int radius = 100;

  tft.drawCircle(cx, cy, radius, GC9A01A_WHITE);
  tft.setTextColor(GC9A01A_WHITE);
  tft.setTextSize(1);
  tft.setCursor(cx - 3, cy - radius + 5); tft.print("N");
  tft.setCursor(cx - 3, cy + radius - 10); tft.print("S");
  tft.setCursor(cx - radius + 5, cy - 3); tft.print("W");
  tft.setCursor(cx + radius - 10, cy - 3); tft.print("E");
}

// Draw compass needle
void drawNeedle(float angleDeg, uint16_t color) {
  int cx = tft.width() / 2;
  int cy = tft.height() / 2;
  float angleRad = angleDeg * DEG_TO_RAD;
  int x = cx + cos(angleRad) * 90;
  int y = cy + sin(angleRad) * 90;
  tft.drawLine(cx, cy, x, y, color);
}