Setup radxa zero 3w for use with gphoto2 to upload photos
This is the start of a series to get a photography bridge working. The hardware used is a radxa zero 3w with eMMC memory.
In this part: setup your radxa and make the ssid configurable using an SD card.
Table of contents
Why
On my old Nikon I had an Eye-Fi WiFi card which connected to a configured WiFi network and uploaded the new photos automatically. Since my new Nikon it wants to be its own access point, when doing this on a laptop, you have to connect firsts to the Nikon access point, download the photos and then upload to where you want them to be.
This solution uses a radxa zero 3w with eMMC and an USB cable to connect to your camera and it uses gphoto2 to sync your photos.
My choice for eMMC stems from the fact I lost too many SD cards on a pi when switching it of on a wrong moment and have the ability to configure your WiFi network using the SD card.
Installing the OS on the eMMC
I am only describing this the linux way, for other OSes it shouldn’t be much different.
The eMMC is 8GB in size, I tried radxa-zero3_bookworm_kde_b1.output_512.img but that one was too large so I used radxa-zero3_debian_bullseye_xfce_b6.img. I don’t care which window manager is used, because we are running headless so “text” mode is good enough.
To see if the radxa is recognized by the system, execute (it must be used with sudo, rkdeveloptool refuses to run as root!):
sudo rkdeveloptool ld
To install debian on the eMMC the following commands must be executed:
sudo rkdeveloptool db rk356x_spl_loader_ddr1056_v1.12.109_no_check_todly.bin
sudo rkdeveloptool wl 0 radxa-zero3_debian_bullseye_xfce_b6.img
More info at radxa zero3 rkdeveloptool.
First boot
Before booting the device, connect a keyboard, mouse and monitor.
DO NOT CONFIGURE THE WIFI YET!!!
The system will now boot in xfce, use the default username and password, it is strongly recommended to change the default password!
Open a terminal and execute the following command, it will put the radxa in “text” mode, or “mutli-user” mode, this will speed up the reboots and we need to do a few to check it we typed the commands correctly.
sudo systemctl set-default multi-user.target
To reboot and test if it worked, type:
sudo reboot
Configure the network
Login in on your radxa and switch to root, yes you read it correct, switch to root, using:
sudo -i
To see which Wi-Fi networks are available type
nmcli dev wifi list
To add the default connection, that will be connected to on a reboot
nmcli device wifi connect "YourNetworkSSID" password "YourPassword"
Change YourNetworkSSID and YourPassword to the one you want to use.
To Discover your IP address, this is later needed to connect to with an ssh client.
ip -4 addr show wlan0
Enable ssh
ssh is disabled by default, so it needs to be enabled and optionally started if you want to test the ssh connection.
systemctl enable ssh
systemctl start ssh
To test the ssh connection, use the previous found IP address and execute the following command in this example the radxa has IP address 10.0.0.100:
ssh radxa@10.0.0.100
The radxa should respond with an ssh login prompt, after you once accepted the host.
Now you can disconnect the keyboard, mouse and monitor and do the rest of the configuration over ssh.
Making the SD card auto-mount
The SD card is used to update configuration items which will be stored on the eMMC, so it can and will run without an SD card.
Preparation
Use lsblk to identify which device is your SD card, it is probably something like /dev/mmcblk1.
Create a directory where the SD card will be mounted, by running sudo mkdir /mnt/sdcard.
Create systemd mount and after-mount service units
Create a mount unit: Use the device name to name your mount unit. For /dev/mmcblk1, create a file named /etc/systemd/system/mnt-sdcard.mount with the following content:
[Unit]
Description=Mount SD Card
[Mount]
What=/dev/mmcblk1
Where=/mnt/sdcard
Type=auto
Options=rw,user,nofail,uid=1000,gid=1000
Create a file named /etc/systemd/system/after-sdcard.service with the following content:
[Unit]
Description=Launch My Daemon
Requires=mnt-sdcard.mount
After=mnt-sdcard.mount
[Service]
ExecStart=/root/bin/after-sdcard.sh
[Install]
WantedBy=mnt-sdcard.mount
For now create a file /root/bin/after-sdcard.sh make it executable and use the the following test content:
#! /bin/bash
echo "Done mounting" > /root/done_mounting
This will create the file /root/done_mounting when the service successful executed.
Create two udev rules
Create a udev rule file at /etc/udev/rules.d/90-sdcard-automount.rules.
Add the rules that triggers the mount based on the device’s properties, such as its subsystem or vendor/product ID. For example, a rule for a SD card reader might look like this:
SUBSYSTEM=="block", KERNEL=="mmcblk*", ACTION=="add", TAG+="systemd", ENV{SYSTEMD_WANTS}="mnt-sdcard.mount"
SUBSYSTEM=="block", KERNEL=="mmcblk*", ACTION=="add", TAG+="systemd", ENV{SYSTEMD_WANTS}="after-sdcard.service"
Reload udev and start the services
Reload the udev rules by running sudo udevadm control --reload-rules.
Start and enable the mount unit to have it run after boot:
systemctl start mnt-sdcard.mount
systemctl enable mnt-sdcard.mount
This setup will make systemd monitor the /mnt/sdcard directory, and when an SD card is inserted into the device, the udev rule will trigger the mount unit, which in turn will mount the card via the mount unit.
Start and enable the after-sdcard service to have it run after boot:
systemctl start after-sdcard.service
systemctl enable after-sdcard.service
Testing
If the file /root/done_mounting is there, remove it.
Remove and insert the SD card, now the file should be there again.
Repeat the above one more time, why, when the service is started for the first time, it will execute after the first mount. Reinserting the card will trigger the udev rule, so if you see the file the second time, all is successful!