https://github.com/rberenguel/PiWrite Skip to content Toggle navigation Sign up * Product + Actions Automate any workflow + Packages Host and manage packages + Security Find and fix vulnerabilities + Codespaces Instant dev environments + Copilot Write better code with AI + Code review Manage code changes + Issues Plan and track work + Discussions Collaborate outside of code Explore + All features + Documentation + GitHub Skills + Blog * Solutions For + Enterprise + Teams + Startups + Education By Solution + CI/CD & Automation + DevOps + DevSecOps Resources + Learning Pathways + White papers, Ebooks, Webinars + Customer Stories + Partners * Open Source + GitHub Sponsors Fund open source developers + The ReadME Project GitHub community articles Repositories + Topics + Trending + Collections * Pricing Search or jump to... Search code, repositories, users, issues, pull requests... Search [ ] Clear Search syntax tips Provide feedback We read every piece of feedback, and take your input very seriously. [ ] [ ] Include my email address so I can be contacted Cancel Submit feedback Saved searches Use saved searches to filter your results more quickly Name [ ] Query [ ] To see all available qualifiers, see our documentation. Cancel Create saved search Sign in Sign up You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert {{ message }} rberenguel / PiWrite Public * Notifications * Fork 1 * Star 77 Use your Kindle Paperwhite as a writing device License MIT license 77 stars 1 fork Activity Star Notifications * Code * Issues 3 * Pull requests 0 * Actions * Projects 1 * Security * Insights More * Code * Issues * Pull requests * Actions * Projects * Security * Insights rberenguel/PiWrite This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository. main Switch branches/tags [ ] Branches Tags Could not load branches Nothing to show {{ refName }} default View all branches Could not load tags Nothing to show {{ refName }} default View all tags Name already in use A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch? Cancel Create 1 branch 0 tags Code * Local * Codespaces * Clone HTTPS GitHub CLI [https://github.com/r] Use Git or checkout with SVN using the web URL. [gh repo clone rberen] Work fast with our official CLI. Learn more about the CLI. * Open with GitHub Desktop * Download ZIP Sign In Required Please sign in to use Codespaces. Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Launching Xcode If nothing happens, download Xcode and try again. Launching Visual Studio Code Your codespace will open once ready. There was a problem preparing your codespace, please try again. Latest commit @rberenguel rberenguel Forgot to update the _year_ of the LICENSE file ... 7f22902 Sep 24, 2023 Forgot to update the _year_ of the LICENSE file 7f22902 Git stats * 26 commits Files Permalink Failed to load latest commit information. Type Name Latest commit message Commit time media Reduce size of larger video September 24, 2023 12:43 piwrite Reduce size of larger video September 24, 2023 12:43 test First push September 23, 2023 18:05 .gitignore First push September 23, 2023 18:05 LICENSE Forgot to update the _year_ of the LICENSE file September 24, 2023 13:06 README.md Update README.md September 24, 2023 13:04 poetry.lock This _should_ not be needed September 23, 2023 18:47 pyproject.toml This _should_ not be needed September 23, 2023 18:47 View code [ ] PiWrite What? How? Why? Contributions? Installing the package Trying it before installing Setting up your Raspberry Pi Zero Basics Pairing with a Bluetooth keyboard Wireless access point Install the package and set it up Some oddities Development README.md PiWrite vid-s.mov What? Have you ever wanted to use your Kindle Paperwhite to write, even more, with a vim-like editor? This is what PiWrite is for. How? The TL;DR is a webserver running somewhere a keyboard can be plugged, and a page opened in the Kindle's web browser. The not-so-short version requires more effort and details, but is the UX I wanted to get: * A Raspberry Pi Zero W... * Paired with a Bluetooth keyboard... * Set up in access point mode... * With this package installed... * And configured to start automatically on boot. Why? I was inspired by SolarWriter by Michael Solomon. I had always wanted to use my Kindle for writing. SolarWriter solves that by setting up a local web server on your phone (iOS or Android), then you type with a Bluetooth keyboard paired with it. But you need to set up hotspot, keep your screen on... I didn't like those parts. So I wrote this. Contributions? This is open source, and I'll be happy to see it extended and improved. But I'm unlikely to accept contributions: I want a reduced feature set, with only what I need. This is why I didn't release this to PyPI, so anybody can have its own version with custom tweaks and installs it easily from their own repository. --------------------------------------------------------------------- Buy Me A Coffee --------------------------------------------------------------------- Installing the package With a current enough version of pip you can install directly from the repository (or from your fork) with pip install piwrite@git+https://github.com/rberenguel/PiWrite Or with pipx (recommended) with pipx install piwrite@git+https://github.com/rberenguel/PiWrite You might need to add /home/YOU/.local/bin to your PATH (like adding export PATH="/home/YOU/.local/bin:$PATH" at the end of your .bashrc, .zshenv or similar). Trying it before installing Once you have installed it you can try it locally (by default it will serve back at 127.0.0.1:80), and optionally configure host and port, like: PIWRITE_HOST=pi PIWRITE_PORT=31415 Point your web browser to this address and try! The editor is vim inspired, and the instructions can be found in help Setting up your Raspberry Pi Zero If you need a Pi, I can't recommend Pimoroni enough. I'm not affiliated, I just buy always from them. The instructions below may be missing some piece, I have written it based on my bash history and what I remember having to tweak. With the information of what you need to do, there are plenty of tutorials on how to approach each step though. Basics Best is installing a lightweight Raspbian version, since the Zero is not a terribly fast machine. By "mistake" (I was trying something) I updated the lite version (on Buster, I think) to Bookworm. Don't do that, not needed. To configure everything you will need to set up the Raspberry for ssh access, and better with password. For using it as a "magical thing that lets the Kindle work as a text editor" is better if you disable requiring password for logging in via tty. You can enable this (known as autologin) by running sudo raspi-config, in the System Options section. You specifically want Console autologin. You also better set up wifi connectivity too. You can set this up by adding a wpa_supplicant.conf file to the boot partition of the SD card with contents like the following: network={ ssid="YOUR_NETWORK_NAME" psk="YOUR_PASSWORD" key_mgmt=WPA-PSK } Steps needed after this: * Pair with a Bluetooth keyboard; * Set up a wireless access point on your Raspberry; * Install the package and set it up; * Nice-to-have: ssh via USB (there are many tutorials for this). Pairing with a Bluetooth keyboard Pick your poison. The standard way is using bluetoothctl. I found that installing Bluetuith was more convenient to be sure the pairing had worked. On the con side, you need to install the whole Go runtime. Remember: the keyboard will be usable in the tty session, not in any ssh-initiated session. If you want any fancy keyboard configuration (I use Colemak, and like my caps to be control) you will have to edit /etc/default/keyboard and add something like the following: XKBMODEL="pc105" XKBLAYOUT="us" XKBVARIANT="colemak" XKBOPTIONS="ctrl:nocaps" Wireless access point I followed the instructions from here: Turn a Raspberry Pi into a Web Server with Its Own Wifi Network (Tech Note). From these instructions, you can (optionally) skip the routing stuff for this. Although the post mentions only working in Buster, I followed the exact same steps and worked just fine in Bookworm. The TL;DR version: Get the access point and DNS services sudo apt install hostapd dnsmasq Turn it on sudo systemctl unmask hostapd sudo systemctl enable hostapd Edit /etc/dhcpcd.conf (sudo) and add at the end interface wlan0 static ip_address=192.168.11.1/24 nohook wpa_supplicant Important When you want to re-connect your Zero to your wifi, you need to comment this out, otherwise you are out of AP access and out of SSH via Wifi (or even USB gadget) access. If you forget, you'll need to edit the raw disk from another Linux device. You now need to configure /etc/dnsmasq.conf with interface=wlan0 # Listening interface dhcp-range=192.168.11.2,192.168.11.20,255.255.255.0,24h # Pool of IP addresses served via DHCP domain=write # Local wireless DNS domain address=/pi/192.168.11.1 # Alias for this router and now that you are at it, change /etc/hostname to be pi. Finally, configure /etc/hostapd/hostapd.conf with (use your country code, of course) country_code=CH interface=wlan0 ssid=EnchantedRose hw_mode=g channel=7 macaddr_acl=0 auth_algs=1 ignore_broadcast_ssid=0 wpa=2 wpa_passphrase=CHOOSE SOMETHING wpa_key_mgmt=WPA-PSK wpa_pairwise=TKIP rsn_pairwise=CCMP Now, reboot (sudo shutdown -r now or sudo systemctl reboot). If you ever want to disable AP and enable normal wifi, run sudo systemctl disable hostapd dnsmasq AND remove the static IP setting mentioned above. Install the package and set it up Install pipx with sudo apt install pipx and then install piwrite with pipx install piwrite@git+https://github.com/rberenguel/PiWrite You'll want to add pipx's binaries to the path, for example by adding export PATH="/home/YOU/.local/bin:$PATH". Since the ideal experience is not having to add a port in the Kindle browser, the default port piwrite uses is 80. But that needs allowlisting: sudo setcap CAP_NET_BIND_SERVICE=+eip /usr/bin/python3.11 Tweak the Python version depending on what you have. You can test if it works (i.e.. if it is the right version or not) or not by starting piwrite now (you may need to change the exported host). You'll also want to start piwrite on tty user start, you can do this by adding the following to the end of your .profile export PIWRITE_HOST=pi.write # or pi, if it's not under the access point piwrite --------------------------------------------------------------------- Some oddities The Kindle browser is weird and does not support everything. No websockets, only longpolling (or so it seems). For some reason, only version 3.0 of the socketio JavaScript libraries worked correctly. I found no way to get the Kindle browser to rotate the whole page via CSS so I could have a landscape view. My first trial implementation tried using pynvim (the NeoVim API layer) as the underlying editor. That would have been awesome, real vim! But it didn't work for obscure reasons (I had to do some unholy things with asyncio that caused it to explode easily). Development I wrote half of this directly on the Zero from my iPad, using Blink to SSH into it. The second half, I wrote it on my iPad with iVim, ish and Inspect Browser. The finishing touches (moving to Poetry and cleaning up), on my Mac. For local development, you can then use basically anything. Just choose a valid port for your system and make sure the host is valid. 127.0.0.1 is the default choice and the one that should work. --------------------------------------------------------------------- Buy Me A Coffee --------------------------------------------------------------------- About Use your Kindle Paperwhite as a writing device Resources Readme License MIT license Activity Stars 77 stars Watchers 1 watching Forks 1 fork Report repository Languages * Python 88.6% * JavaScript 5.8% * CSS 4.3% * HTML 1.3% Footer (c) 2023 GitHub, Inc. Footer navigation * Terms * Privacy * Security * Status * Docs * Contact GitHub * Pricing * API * Training * Blog * About You can't perform that action at this time.