# Notes on the Raspberry Pi Zero W + Emacs + iPad

edited May 7

Emacs + phi-notes + Seafile + Tailscale + Blink.sh. Inspired by the possibility of getting back to work in coffee shops and libraries...

After some research, Seafile appeared to be the best choice for synchronizing notes, since I can't trust Dropbox anymore and want to keep everything hosted in servers I can control. It has the particular advantage of supporting WebDAV natively (thus it works with 1Writer) and being easy to set up.

I also did some tests with emacs running with a GUI using TigerVNC + Screens for iOS: the performance is better than expected, even when running at full Retina resolution. Terminal mode with Blink.sh provides a better general experience though.

I still didn't make BerryLan play nicely to configure the Wi-Fi through Bluetooth (I'm not sure if it is supposed to be compatible with Tailscale). Maybe writing a client/server BT application with Pythonista?

Post edited by brunoc on

• Dang, I love this forum!

Read Raspberry Pi in the title and knew that my geek-o-meter will be maxed out for a week. It is getting cyberpunky!

I am a Zettler

• @brunoc said:

After some research, Seafile appeared to be the best choice for synchronizing notes, since I can't trust Dropbox anymore and want to keep everything hosted in servers I can control. It has the particular advantage of supporting WebDAV natively (thus it works with 1Writer) and being easy to set up.

I imagine you checked out SyncThing as well, so interested to know why you prefer Seafile.

Thanks.

• edited May 8

@brunoc Can you explain your setup a bit more, i.e. how the iPad and the Pi Zero W interact?

I know of:

But since you're using Blink.sh, are you SSH'ing onto the Pi and running emacs there? Via emacsclient and the Pi as server, or emacs -nw directly?

Can recommend the r/cyberdeck subreddit. Not many iPad integrations, but lots of Pi's and cheap external displays. (Examples: here and here). Some even wrist-mounted.

Author at Zettelkasten.de • https://christiantietze.de/

• @Sascha said:
Dang, I love this forum!

Read Raspberry Pi in the title and knew that my geek-o-meter will be maxed out for a week. It is getting cyberpunky!

Haha, yes!

• edited May 8

@ctietze said:
@brunoc Can you explain your setup a bit more, i.e. how the iPad and the Pi Zero W interact?

The Pi Zero has all the notes in it, synchronized with seafile-cli. It runs emacs -nw with all the bells & whistles! To have everything promptly available, I'm also running emacs in a tmux session started as a systemd service. It takes about 100 seconds to have everything ready. After that, I only have to connect from the iPad.

Blink.sh makes use of mosh, which is interesting because it will not drop the connection if the iPad goes idle or if you switch applications.

To be sure, it takes some time to index a few thousand notes when I call helm-phi-find -- as shown above -- for the first time (later calls will be cached). This is mostly because of the Pi's limited I/O throughput with the microSD card. But the setup is perfectly usable -- otherwise, I might learn how to implement a persistent sqlite cache in emacs Lisp.

As for network connections, Tailscale is magic (it will assign each device a fixed private IP address and deal with all the routing complexities for you). I've found that it would be trivial to simply configure wpa_supplicant.conf with multiple networks. I've already tried with my home network as first priority, falling back to the iPhone's hot spot (the idea would be to connect everything to the hot spot when working in the street). The next step is to configure eduroam with adequate keys and credentials in between those options -- and that could be sufficient for most of my usage scenarios, I think. This could make the Bluetooth configuration approach superfluous, perhaps. For exceptions, I could carry a lightning adapter with microSD card reader and edit Pi's config to add a new network. It wouldn't solve the problem of captive portals, though. For that, people are connecting the Pi via USB-C to their newer iPads -- I still didn't try connecting the Pi to my older iPad with an OCB cable and haven't found anybody doing it, so I don't know if it is possible with my current hardware.

I know of:

I tried iSH, but it is really limited. I guess it would be difficult to compile a recent version of emacs + seafile etc. -- and it doesn't appear to be sufficiently stable for real work.

I couldn't trust a microSD card for central storage -- those Pi-as-NAS setups usually have SSDs attached, from what I've seen. What I'm doing is running the seafile server on a virtual server in Digital Ocean and keeping backups on my home Synology NAS via WebDAV. It is easy to set up the whole Seafile service using Docker containers (even some NASses could do it, but mine is really entry-level). The host operating system on the Digital Ocean server also has emacs installed and the notes synchronized, so it's a handy alternative to the Pi setup if I happen to have a stable Internet connection (but not as cool ).

On the other hand, as a bonus, the local Pi can provide the notes on a smb share. It thus makes it possible for example to circumvent iA Writer's irritating lack of WebDAV support!

Geekiness aside, among other interesting applications would be to run an HTTP server and produce presentations out of notes, e. g. with RevealJS, projecting them with the iPad connected through HDMI.

Can recommend the r/cyberdeck subreddit. Not many iPad integrations, but lots of Pi's and cheap external displays. (Examples:

Amazing! Nothing beats the keyboard + monitor combo in some situations (such as seating at the airport, something I have been subjected to recently, after two years without taking a plane). I find the Pine particularly appealing!

My motivation, though, was to carry something light and keep equipment to a minimum. With in-person classes back this semester, I remembered how much I enjoy working with my old (?) 5th-gen iPad and reading lecture notes from 1Writer -- a function, to mention, that has been fulfilled by The Archive in the Mac during the whole pandemics!

The idea is to have this Pi companion for the occasional work in the library between classes or in the street. I have also tested a cheap used Chromebook with emacs, and it works surprisingly well too. But a tablet is such a practical tool for teaching you can walk with in the classroom, and the Retina screen on the iPad is hard to beat. On top of that, Blink.sh does an excellent job in dealing with colours and fonts, making the terminal experience aesthetically very pleasant (by the way, it already comes with the IBM Plex Mono font, which I'm obsessed with).

Post edited by brunoc on
• edited May 8

@Jeremy said:

I imagine you checked out SyncThing as well, so interested to know why you prefer Seafile.

Yes! SyncThing was one of the options considered, but from what I have seen it has no support for WebDAV. This was a requirement in order to sync with 1Writer, which is my preferred iOS notes app.

• Hmm Nextcloud has WebDAV, so you could host that on Digital Ocean and on the Pi, then connect both servers to share a folder, then use WebDAV for the Pi Nextcloud instance where possible + fall back to Nextcloud's iOS app for Files integration (which doesn't help with iA Writer sadly because Nextcloud's Files API implementation is incomplete).

mosh is a plus. iSH actually shuts down a lot in the background oftentimes, so even if you'd just use it for ssh'ing onto the Pi + maybe running emacsclient directly, the experience wouldn't be as nice I imagine. 👍

smb exposure of the Pi's storage is interesting. I actually never connected any iOS app to a Samba share, ever, so thanks for pointing out this is possible!

Need to try out Seafile and Tailscale on my Unraid NAS for this. Your network settings still go over my head, and that cannot stand!!1

Author at Zettelkasten.de • https://christiantietze.de/

• @brunoc said:

Yes! SyncThing was one of the options considered, but from what I have seen it has no support for WebDAV. This was a requirement in order to sync with 1Writer, which is my preferred iOS notes app.

OK. My use of SyncThing is purely to synchronise files across three machines, one Pi, one macbook and one iMac. I suppose that would mean having all the 1Writer files in each machine, which might not be what you want.

• edited May 15

@ctietze said:
Need to try out Seafile and Tailscale on my Unraid NAS for this. Your network settings still go over my head, and that cannot stand!!1

For the network settings, I also found that adding an Access Point option to the list is pretty straightforward. The configuration now comprises three modes: 1) home network; 2) tethering with the phone; 3) the Pi as an internetless Access Point accessible at 10.57.0.1.

Having no internet may be a positive feature: a no-distraction environment.

## Configuration (tested with Raspbian Buster)

### Network setup

You need to install dnsmasq to provide a DHCP server. Then you may configure /etc/dnsmasq.d/wlan0 like this:

interface=wlan0
dhcp-authoritative
dhcp-leasefile=/tmp/dhcp.leases
dhcp-range=10.57.0.2,10.57.0.10,24h
dhcp-option=1,255.255.255.0

# Do not send gateway to client
dhcp-option=3


And these are the configurations for wpa_supplicant and the interfaces:

/etc/wpa_supplicant/wpa_supplicant.conf:

country=br
update_config=1
ctrl_interface=/var/run/wpa_supplicant

network={
scan_ssid=1
ssid="Home Network"
psk="XXXXXXX"
id_str="dhcp_client"
}

network={
scan_ssid=1
ssid="Bruno's iPhone"
psk="XXXXXXXXX"
id_str="dhcp_client"
}

network={
ssid="Bruno's Pi"
mode=2
key_mgmt=WPA-PSK
psk="XXXXXXXXX"
frequency=2437
id_str="dhcp_server"
}


/etc/network/interfaces.d/wlan0:

auto wlan0
iface wlan0 inet manual
wpa-driver nl80211
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf


/etc/network/interfaces.d/dhcp_client:

iface dhcp_client inet dhcp


/etc/network/interfaces.d/dhcp_server:

iface dhcp_server inet static


### Network selection

To change the network configuration from the command line, you can create different <network>.conf files and store them inside /etc/wpa_supplicant/ (i. e.: the network { ... } fragments above, in different files such as home.conf, phone.conf, ap.conf). You may then evoke a script, e. g. sudo wifichange <network>, to select a network configuration. This is its code:

/home/pi/bin/wifichange:

#!/bin/sh
[ -z "$1" ] && exit 1 [ ! -f "/etc/wpa_supplicant/${1}.conf" ] && echo "$1 is not a wpa_supplicant config file" && exit 1 sudo killall wpa_supplicant sudo wpa_supplicant -B -i wlan0 -c "/etc/wpa_supplicant/${1}.conf"


Don't forget to chmod +x /home/pi/bin/wifichange.

The Seafile client may take some time (2-3 minutes) to have the notes synchronized after booting. So it's a good thing to be warned when it's ready. I use Pushover to receive notifications on my phone.

/home/pi/bin/sync-notify (substitute Notes for the Seafile Library name and fill in the application token and user key):

#!/bin/bash
while [ "$((/usr/bin/seaf-cli status 2>/dev/null || echo failure) | awk '/^Notes/ { print$2 }')" \
!= "synchronized" ]
do
sleep 5
done

APP_TOKEN="XXXXXXXXXXXXXXXXXXXXXXXXXXX"
USER_KEY="XXXXXXXXXXXXXXXXXXXXXXXXX"

curl -s \
--form-string "token=${APP_TOKEN}" \ --form-string "user=${USER_KEY}" \
--form-string "message=The notes are now in sync" \
https://api.pushover.net/1/messages.json >/dev/null


Then chmod +x /home/pi/bin/sync-notify.

Now you just need to add this line to the crontab (crontab -e):

@reboot /home/pi/bin/sync-notify

Post edited by brunoc on
• Thanks so much for sharing your config, @brunoc! That will likely save me 3hrs or so of research and setup! 🎉

Author at Zettelkasten.de • https://christiantietze.de/

• @ctietze said:

Have fun! 😀