How to fix Arduino [WiFiUdp.cpp:183] endPacket(): could not send data: 118

When you see a log message like

[ 13701][E][WiFiUdp.cpp:183] endPacket(): could not send data: 118

on your microcontroller, you can use Serial.println(strerror(118)); to find out what the error code 118 means.

In the case of 118 (tested with arduino-espressif32 v2.0.5) the error means

Host unreachable

Typically, this error means that you are not connected to the internet / network but it might also mean that the

Note that the error message by itself does not give any indication what part of your code tried to send the UDP packet – hence, it’s not immediately clear what host specifically can’t be reached. However, this message specifically happens with code that sends UDP packets. In almost all cases, the error won’t happen when the microcontroller responds to UDP packets from another host (such as ArduinoOTA) but when the microcontroller tries to send packets to the network initiated by the microcontroller itself (such as NTP).

Posted by Uli Köhler in Arduino, C/C++, Embedded

How to import existing C/C++ source files into STM32CubeIDE

In STM32CubeIDE, first create a folder for your source files to reside in. In order to do this, right click on your project and select New -> Folder:

Step 1: Create folder

In the dialog that opens, select the correct location (project & optionally subfolder) where the folder will be created. For this example, we’ll use occutils .

Step 2: Import files

Right click on the folder where you want to import the files into and click Import:

Now click General -> File system.

In the dialog that opens, select the From directory where you want to import the files from.

and click Finish. After that, your files will be included in the project.

Posted by Uli Köhler in STM32

How to create directory on RouterOS using the terminal

As of RouterOS 7.6 there is no official command to create a directory on a RouterOS filesystem. However, there’s a trick involving a SMB share. By creating the SMB share, RouterOS will create the directory. After that, you can delete the SMB share.

The following script will create the backups directory:

/ip smb shares add name=deleteme directory=backups ; /ip smb shares remove [find name=deleteme]')
Posted by Uli Köhler in MikroTik, Networking

How to delete file(s) by regex filename on RouterOS

The following RouterOS command will delete all files starting with backup-:

/file/remove [/file find where name~"^backup-.*\$"]

 

Posted by Uli Köhler in MikroTik, Networking

How to delete file on RouterOS by filename using terminal or SSH (minimal example)

In order to delete a file named mybackup.backup on a RouterOS device using the terminal, use the following command:

/file/remove [find name="mybackup.backup"]

 

Posted by Uli Köhler in MikroTik, Networking

Netmiko MikroTik RouterOS minimal example

This example prints the identity (i.e. user-defined name) of the switch/router at IP address 10.0.0.1 with password abc123abc.

from netmiko import ConnectHandler
mikrotik = {
    'device_type': 'mikrotik_routeros',
    'host':   '10.0.0.1',
    'username': 'admin',
    'password': 'abc123abc'
}

mikrotik_connection = ConnectHandler(**mikrotik)
print(mikrotik_connection.send_command(f'/system/identity/print', cmd_verify=False))

Example output:

name: MySwitch01

 

Posted by Uli Köhler in MikroTik, Networking, Python

MikroTik User Manager (RADIUS): Add user with VLAN

The following RouterOS terminal command adds a User Manager user assigned to a VLAN with ID 998. This setup is compatible with Unifi access points.

/user-manager user add attributes=Tunnel-Type:13,Tunnel-Medium-Type:6,Tunnel-Private-Group-ID:998 name=myuser password=uNah2ieghi

Note that Tunnel-Type:13,Tunnel-Medium-Type:6 will always stay the same, they will tell RADIUS to assign a VLAN.

In WebFig, the same config looks like this:

In WinBox, these settings look like this:

Posted by Uli Köhler in MikroTik, Networking

How to specify which docker image to use in .gitlab-ci.yml

The following .gitlab-ci.yml will build a native executable project using cmake with a custom docker image:

stages:
  - build

buildmyexe:
  stage: build
  image: 'ulikoehler/ubuntu-gcc-cmake:latest'
  script:
    - cmake .
    - make -j4

In this example, we have only one stage – if you have multiple stages, you can specify different images for each of them.

Posted by Uli Köhler in Docker, git, GitLab

MikroTik RouterOS Wake-on-LAN (magic packet) script example

On RouterOS, we can create a simple Wake-on-LAN script using a MAC address using

/tool/wol mac=DC:4A:3E:7A:87:12 interface=bridge

 

Posted by Uli Köhler in MikroTik, Networking

How to setup image slideshow kiosk on Raspbian

1. Configure autologin

sudo raspi-config -> 1 System options -> S5 Boot / auto-login -> Set to B2 Console Autologin

2. Use our script to configure the kiosk

sudo apt -y install xserver-xorg xinit x11-xserver-utils matchbox-window-manager xautomation unclutter feh
mkdir -p ~/kiosk-images

sudo cat >~/kiosk.sh <<EOF
#!/bin/sh
xset -dpms
xset s off
xset s noblank
matchbox-window-manager -use_titlebar no &
unclutter &
feh -Y -x -q -D 5 -B black -F -Z -z -r ~/kiosk-images
EOF
chmod a+x ~/kiosk.sh

sudo cat >>~/.bashrc <<EOF
# Kiosk xinit
xinit ~/kiosk.sh -- vt$(fgconsole)
EOF

3. Place images in ~/kiosk-images

e.g. via scp or rsync

4. Reboot

sudo reboot

Note: When logging in using SSH, the .bashrc hack (found originally at reelyactive) will cause xinit to run, with the message

/usr/lib/xorg/Xorg.wrap: Only console users are allowed to run the X server

appearing on screen and the console not opening. In that case, just type Ctrl+C to stop xinit and see the normal shell.

Posted by Uli Köhler in Raspberry Pi

What pitch to JST “XH” connectors have?

JST XH connectors have a pitch of 2.5mm (not to be confused with 2.54mm).

Source: JST website

Posted by Uli Köhler in Electronics

How to enable KiCAD snap to pads in measure distance mode

In order to enable snapping to pads (also called magnetic pads) in KiCAD pcbnew, open Preferences -> Preferences:

and then open PCB Editor -> Editing Options, and set Magnetic Points -> Snap to pads to Always:

After you click OK, you can snap to points when using the Ctrl+M Interactively measure distance between points tool:

Posted by Uli Köhler in KiCAD

Command line: When to use “-” (single hyphen) or “–” (double hyphen)

On the command line, the - character is used to indicate a short form argument, which is a single-letter argument that can be specified using a single hyphen and the letter of the argument. For example, the -h argument is commonly used to show the help message for a command, and the -v argument is commonly used to enable verbose output. You can only use the single hyphen (-) when the argument consists of a single letter.

Examples where single hyphen can be used: -h-Rand-f, but you can not use single hyphens for multi-letter arguments such as -verbose or -help.

The -- characters are used to indicate a long form argument, which is a multi-letter argument that can be specified using a double hyphen and the name of the argument. For example, the --help argument is commonly used to show the help message for a command, and the --verbose argument is commonly used to enable verbose output.

Examples where double hyphens can be used: --verbose--server and --help, but you can’t use them for single-letter arguments like --h or --R 

Examples of how to use single or double hyphens:

# Show the help message for a command using the -h short form argument
my_command -h

# Enable verbose output for a command using the --verbose long form argument
my_command --verbose

# Combine multiple arguments
my_command --verbose --server https://techoverflow.net -f 0.1

 

Posted by Uli Köhler in Linux

How to show current CoreOS system version using rpm-ostree

In CoreOS, run

sudo rpm-ostree status

and look for the entry with the dot () in front of it to see which deployment – i.e. which CoreOS version is currently active. Then, look for Version:  in the line below. This serves as the alternative to lsb_release -a which is not available on CoreOS.

Example output:

State: idle
AutomaticUpdatesDriver: Zincati
  DriverState: active; periodically polling for updates (last checked Thu 2022-12-08 03:49:05 UTC)
Deployments:
● fedora:fedora/x86_64/coreos/stable
                  Version: 37.20221106.3.0 (2022-11-28T20:05:48Z)
               BaseCommit: 6278bd1e5f311880a6975307e7ce734076a0b1a37f8a97c875c07037c748ddcc
             GPGSignature: Valid signature by ACB5EE4E831C74BB7C168D27F55AD3FB5323552A
          LayeredPackages: bmon docker-compose htop iotop make tailscale tree wget xe-guest-utilities-latest

  fedora:fedora/x86_64/coreos/stable
                  Version: 36.20221030.3.0 (2022-11-11T15:51:02Z)
               BaseCommit: eab21e5b533407b67b1751ba64d83c809d076edffa1ff002334603bf13655a14
             GPGSignature: Valid signature by 53DED2CB922D8B8D9E63FD18999F7CBF38AB71F4
          LayeredPackages: bmon docker-compose htop iotop make tailscale tree wget xe-guest-utilities-latest

In this example, CoreOS 37.20221106.3.0 is active.

Posted by Uli Köhler in CoreOS

Free wordpress plugin for searching categories while editing posts & pages

WP Admin Category Search is a free search plugin for searching categories while editing your posts or pages. It allows you to quickly find categories without scrolling through a long list of categories:

Step 1: Install WP Admin Category Search

Go to Plugins -> Install and search for WP Admin Category Search. Install and activate it by clicking the button

Step 2: When editing posts, search for categories…

Step 3: … and find and select them

Posted by Uli Köhler in Wordpress

How to fix zincati not updating CoreOS: rpm-ostree deploy failed: error: Packages not found: …

Problem:

My zincati service – the service that automatically updates CoreOS could not update CoreOS due to the following logs (view with journalctl -xfu zincati.service):

[ERROR zincati::update_agent::actor] failed to stage deployment: rpm-ostree deploy failed:
    error: Packages not found: magic-wormhole

Solution:

The solution typically involves uninstalling the package – in this case magic-wormhole using

sudo rpm-ostree uninstall magic-wormhole

Note that this might uninstall a service that is required for your infrastructure, and it will delete files associated with the package in the process of uninstalling it. You should make a backup of valuable data in any case.

Posted by Uli Köhler in Allgemein, CoreOS

How to find first element in sorted numpy array that is larger than a given scalar

Also see How to find first element in sorted numpy array that is smaller than a given scalar

You can use np.searchsorted() like this:

idx = np.searchsorted(arr, scalar, side='right') + 1

Full example:

import numpy as np

# Example array
arr = np.array([1, 2, 3, 4, 5])

# We'll search for this value
scalar = 3.5

# Use numpy.searchsorted() to find the first element in the array that is larger than the scalar
# We need to use + 1 since searchsorted() returns the first element that is smaller than the scalar
idx = np.searchsorted(arr, scalar, side='right') + 1

# Print the resulting index
print(idx)

 

Posted by Uli Köhler in Python

How to find first element in sorted numpy array that is smaller than a given scalar

Also see How to find first element in sorted numpy array that is larger than a given scalar

You can use np.searchsorted() like this:

idx = np.searchsorted(arr, scalar, side='left')

Full example:

import numpy as np

# Example array
arr = np.array([1, 2, 3, 4, 5])

# We'll search for this value
scalar = 3.5

# Use numpy.searchsorted() to find the first element in the array that is smaller than the scalar
idx = np.searchsorted(arr, scalar, side='left')

# Print the resulting index
print(idx)

 

Posted by Uli Köhler in Python

How to fix CMake Error: Cannot find source file: *.cpp

Problem:

You are trying to build your CMake-based project using a CMakeLists.txt like

cmake_minimum_required(VERSION 3.10)
project(my_project)

add_executable(my_project *.cpp)

Solution:

You can’t use the glob pattern *.cpp directly in add_executable(). You need to use file(GLOB ...) in order to set a variable, which you can then use in add_executable():

cmake_minimum_required(VERSION 3.10)
project(my_project)

file(GLOB SRC_FILES *.cpp)
add_executable(my_project ${SRC_FILES})

 

Posted by Uli Köhler in CMake

How to add progress bar to “for i in range(…)” loop in Python

You can use the tqdm library to easily add a progress bar to your Python for i in range(...) loop:

Just

from tqdm import tqdm

at the top of your script and then surround range(...) with tqdm(...). For example,

mysum = 0
for i in range(50):
    sum += i

becomes

mysum = 0
for i in tqdm(range(50)):
    mysum += i

 

Posted by Uli Köhler in Python
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Cookie settingsACCEPTPrivacy &amp; Cookies Policy