Automating upload to OctoPrint on a Mac

Post your advice, tips, suggestions, etc...
Post Reply
jsc
Posts: 1864
Joined: Thu Apr 10, 2014 4:00 am

Automating upload to OctoPrint on a Mac

Post by jsc » Sat Jul 05, 2014 8:00 am

I just set up OctoPrint on my new Beaglebone Black. I set it up to automatically upload gcode files saved to a folder, and thought I would document the process. The Mac portion of this will work on any OctoPrint installation, but you must be running the devel version.

Installing OctoPrint
If you are using Angstrom, follow these instructions: https://github.com/foosel/OctoPrint/wik ... g-Ångström

I have the rev C, which runs stock Debian, so it is a little simpler:

Set up a separate user for OctoPrint:
useradd octo
passwd octo
sudo usermod -a -G tty,dialout octo

Get the source:
git clone http://github.com/foosel/OctoPrint

Switch to the devel branch (needed for the better API):
cd OctoPrint
git checkout devel

Make the OctoPrint source directory the home directory for the octo user:
cd ..
sudo mv OctoPrint /home/octo
sudo chown octo.octo /home/octo

Log in as the octo user, using the password you used. Type "./run &" to start the server. You will want to set this up to start automatically through init scripts, but I leave that as an exercise.

Go to http://beaglebone.local:5000/ (or whatever the hostname or IP address of your Beaglebone is) and set it up to run properly. Open the settings, go to the API section, enable it and make a note of your API key.

Now for the Mac bit:
Create the folder you want to use.
Run the Automator app (you can do this using AppleScript and Folder Actions, but after doing some research it seems that Automator is not only easier, but works more reliably).
Create a new Folder Action.
Add a Run Shell Script action, under Utilities.
Select the folder you just created, and choose "Pass input: as arguments".
For the body, enter:

Code: Select all

api_key=YOUR_API_KEY

for f in "$@"
do
	curl -H "X-Api-Key: $api_key" -F select=true -F print=false -F file=@$f http://beaglebone.local:5000/api/files/local
done
Replace "YOUR_API_KEY" with your actual key, and the URL if it's not right for you. "select=true" loads the file immediately, and "print=false" (the default) says don't start printing; change it to true if you wish to start printing automatically, which I do not recommend.

Save your folder action and give it a name, like "Upload to OctoPrint".

Once you have saved it, it is active. In your slicer, save the gcode to your folder, and watch it appear shortly in your OctoPrint file list.

markb
Posts: 180
Joined: Tue Apr 15, 2014 11:06 pm

Re: Automating upload to OctoPrint on a Mac

Post by markb » Wed Aug 13, 2014 8:02 pm

Does it run faster with this board? Is it better than the PI setup?

jsc
Posts: 1864
Joined: Thu Apr 10, 2014 4:00 am

Re: Automating upload to OctoPrint on a Mac

Post by jsc » Wed Aug 13, 2014 8:10 pm

Are you asking about Beaglebone Black vs Raspberry Pi? There are a bunch of sites that will give you a blow-by-blow on their comparative merits. My take on it is, the BBB has a faster CPU, some internal flash, and is a better basis for standalone projects, but the RaspPi has better video support, a bigger community, and is better for media projects or if you're going to treat it as a tiny computer.

I doubt that you would be able to notice a difference when running OctoPrint.

markb
Posts: 180
Joined: Tue Apr 15, 2014 11:06 pm

Re: Automating upload to OctoPrint on a Mac

Post by markb » Wed Aug 13, 2014 8:15 pm

Thanks. I was asking about when running OctoPrint.

jepmn
Posts: 2
Joined: Sun Nov 09, 2014 7:24 am

Re: Automating upload to OctoPrint on a Mac

Post by jepmn » Sun Nov 09, 2014 7:30 am

VERY helpful writeup. As this comment is a few months later, I'd like to just add a couple of things for people landing here. First off, I'd probably not check out the devel branch. I went down that path and ran into all sorts of issues. As of writing this, there is a stable release from just a couple of weeks ago. It seems like this contains the new API that the OP was wanting when using the devel branch.

Also, make sure you do (as root or sudo):

python setup.py install

after you copy over the dir and before you run ./run.

jsc
Posts: 1864
Joined: Thu Apr 10, 2014 4:00 am

Re: Automating upload to OctoPrint on a Mac

Post by jsc » Sun Nov 09, 2014 6:29 pm

I'm glad it was helpful to somebody. One additional bit I figured out later is how to get it to run automatically under Debian. It uses "systemd" now, which more and more Linux distributions are moving towards, so maybe we will get out of this multiple init system hell we're currently in.

Create a file /lib/systemd/system/octoprint.service with the following contents:

Code: Select all

[Unit]
Description=OctoPrint

[Service]
Type=simple
ExecStart=/home/octo/run
Restart=always
RestartSec=60
User=octo

[Install]
WantedBy=multi-user.target
Then run "sudo systemctl enable octoprint.service". That should start the service on startup. To run it immediately, use "sudo systemctl start octoprint.service". You can also use "stop" and "restart". man systemctl for the gory details.

jepmn
Posts: 2
Joined: Sun Nov 09, 2014 7:24 am

Re: Automating upload to OctoPrint on a Mac

Post by jepmn » Mon Nov 10, 2014 4:43 am

Cheers once again. Was just about to get around to that and you made it much easier. Now all that's left is turning off the default webserver and changing octoprint over to use 80. Can't really complain if that's all I have to do. :)

wiredinoc
Posts: 4
Joined: Tue Dec 30, 2014 9:09 am

Re: Automating upload to OctoPrint on a Mac

Post by wiredinoc » Tue Dec 30, 2014 9:18 am

Hi JSC and all, EXCELLENT WRITEUP!! I picked up a BBB and a RBP based on this thread. Got both to work fine, the biggest limitation I'm running into is USB ports on the BBB. There is only one, and the handful of non-powered port extenders I tried will not power up the external wifi card and printer, even with the 5v barrel plug. Which sucks. I really see the additional horsepower with the BBB. The RBP can hang with 4 powered usb devices plugged in and being powered simply by the microUSB port. I don't think it makes much difference at the end of the day as the CPU stays in check on the RBP around 10% during prints and interface use. The RBP was B+ was $19 vs $59 for the BBB I might add..

Anyways, JSC, I have a question, hope this makes it your way quick. Regarding the API and automator tasks. I used your instructions to the tee. When I drop a file into the selected folder, I can see network traffic via the blinking dongle, but the file is not copied. I have no idea how to debug this. Do you have this working still with the latest build? Any pointers to troubleshoot?

The next add I'm researching is a relay to power down the printer when jobs are finished. Loving it!!

Thank you!!

jsc
Posts: 1864
Joined: Thu Apr 10, 2014 4:00 am

Re: Automating upload to OctoPrint on a Mac

Post by jsc » Tue Dec 30, 2014 6:50 pm

wiredinoc, you really will not be able to power a USB wifi adapter using USB power without using a powered hub. Even just powering just the wifi adapter through the USB port is a marginal situation. I got a four port Amazon Basics hub that was cheap and works well.

To debug your Automator upload, try running that curl line in the script manually in the Terminal and see what response you get. Maybe add in a "-v" to get verbose output. Replace $api_key and $f with your API key and the filename of your gcode file.

As jepmn pointed out, I left out the instructions on installing OctoPrint itself so that it can run. Before you run "sudo python setup.py install", you should also run "sudo pip install -r requirements-bbb.txt". Some further info is available here: https://github.com/foosel/OctoPrint/wik ... g-Ångström, although on a C model with Debian you will not have opkg available and should use apt-get.

The stable release has had an API for a long time, but I'm not quite sure if it's the new API available in the devel branch. It was the old insufficient API when I was putting this together, and I have not checked on the status of the released version. Also I needed the dual extruder support. The "advantage" of being on the devel branch is that you get to live on the bleeding edge by running "git update" in the octoprint directory.

Oh, one other thing I found running on a BBB: if you're interested in using the webcam support, you will need to set your CPU frequency governor to "performance", I found I was getting kernel panics when the load got too high with the default governor. "sudo cpufreq-set -g performance": http://derekmolloy.ie/changing-the-beag ... frequency/

Post Reply