Yes, you can run Octoprint on a modern router / access point. Octoprint is a service that can be provided by that flash-based device which is already up and running on your LAN. I’ve been running Octoprint 1.4.3 on a Netgear R7800 Running 19.07 of OpenWRT for a year and a half, driving an Ender 3D printer. I just installed Octoprint 1.7.3 on a Linksys WRT1900ac-v2 also running OpenWRT 19.07. In both cases Octoprint runs quite nicely.
The router will need a reasonable CPU. In my case both routers use a dual core ARMv7 running at 1.6Ghz. Both devices also have 512MB of onboard RAM. I suspect a device with 256MB would still run fine.
The biggest concern is flash memory. An easy installation without having to play any games requires about 400MB. If your device has less than that, you can add flash memory using OpenWRT’s extroot mechanism, presuming you have a free USB connector. Both of my devices had two USB connectors, so one became the home of a 512MB microSD USB drive, and the other is where the 3D printer attaches.
These are the steps:
-
Visit openwrt.org/toh/start and find an OpenWRT build for your router. I used version 19.07 of OpenWRT. I trust that the later 21.02 release will work fine as well. This build will allow your router to fulfill its primary purposes as a network switch and a wireless access point. You can add packages to provide other services, such as DHCP/DNS, DDNS and OpenVPN. If you want a highly personalized system you can consider installing the OpenWRT Image Builder and cooking up your own build. Once installed, go through the basic configuration for your network and do some rudimentary testing.
-
You’ll need about 300MB more flash memory to proceed, so if the Software tab of the OpenWRT shows less, you’ll need to expand the onboard file system using a USB Flash drive by following the steps found here: openwrt.org/docs/guide-user/additional-software/extroot_configuration. FWIW, these directions recommend using the ext4 file system, but my preference is to use the f2fs file system (flash friendly file system). If you feel the same, install the f2fs packages ‘kmod-fs-f2fs f2fs-tools’ and reboot before following those directions, and use mkfs.f2fs instead of mkfs.ext4.
-
Once you have booted back up with your expanded file system, install the OpenWRT packages needed to run Octoprint. You’ll need python, the gcc compiler and support for the serial connection to your printer. We install the gcc compiler because a few of the python pieces will be auto-compiled during installation. SSH into the device and run:
opkg update
opkg install gcc python3 python3-pip python3-dev
opkg install kmod-usb-serial kmod-usb-serial-ch341
- Install Octoprint. In my case, each of the following commands completed without any intervention. SSH into the device and run:
pip3 install pip --upgrade
pip3 install wheel
pip3 install regex
pip3 install psutil
pip3 install octoprint
- Create the octoprint user and it’s home directory:
- Edit /etc/passwd and add:
octoprint:x:1001:1001:dialout:/octoprint:/bin/ash
- Edit /etc/group
Octoprint:x:1001: Dialout:x:20:octoprint
- Edit /etc/shadow
Octoprint:x:0:0:99999:7:::
- Assign the new user a password (I use octoprint):
passwd octoprint
- Create octoprint a home directory:
mkdir /octoprint chown octoprint:octoprint /octoprint
- Login as octoprint and run the Octoprint server for the first time. If everything went well, you should not see any errors:
su - octoprint
/usr/bin/octoprint serve
- After about 10 seconds, you should be able to visit Octoprint from a nearby browser:
-
For the moment, kill Octoprint with a Ctl-C.
-
Octoprint creates some files which are not appropriate for a flash file system, so we’ll direct them off to /tmp. This requires three changes:
- cd to the .octoprint sub-directory and issue these commands:
rm -rf logs generated uploads ln -s /tmp/octoprint/logs logs ln -s /tmp/octoprint/generated generated ln -s /tmp/octoprint/uploads uploads
- Back in the Octoprint home directory, create an executable file called ‘start’, and populate with these commands:
#$ /bin/ash mkdir /tmp/octoprint mkdir /tmp/octoprint/generated mkdir /tmp/octoprint/logs mkdir /tmp/octoprint/uploads /usr/bin/octoprint daemon start
- Configure OpenWRT to auto-start Octoprint by adding this command to the ‘System->Startup->Local Startup’ LuCI Screen:
su - octoprint /octoprint/start
- Restart the router using the following command. Octoprint should startup and be waiting for you within seconds:
reboot
You’ll now need to connect your printer to the second USB port. If Octoprint has trouble connecting to your printer, review /tmp/system.log (or run ‘logread -f’ before you attach the USB cable), and watch for any errors about missing serial drivers. You should be able to use opkg or the Software web page in LuCI to install the driver you need.
Proceed with configuring Octoprint for your purposes, and happy printing!
A final note about flash memory:
If your device is on the cusp of being able to host this installation using internal flash memory, you might consider checking if the final installation can be copied back onto the internal /overlay partition. First, use the extroot mechanism to do the initial installation. After Octoprint is up and running, remove the gcc package and the supporting files, since they are not necessary once Python3 is installed:
opkg --autoremove remove gcc
Using ‘df’ and ‘du -a’, see if there is room on /rwm (if you followed the extroot directions closely). If so, you can work backwards through the extroot directions and copy the final contents from the new /overlay partition back over the original /overlay partition, then tweak the fstab on the original /overlay partition to NOT mount the new /overlay partition. A reboot should bring you back to the internal /overlay, but with Octoprint installed.
If you need a scooch more internal space, consider using ImageBuilder to include the python3 package in the installation image (it will therefore be compressed into /rom instead of existing uncompressed on the /overlay partition.)
Fair disclaimer: I have not tried this whole /overlay swap. I was going to, but found that the external /overlay contents were too big for the internal /overlay. Seems like it should work, though
P.S. Sorry about the formatting of this post - new to posting here.