Upload gcode files automatically from Simplify3D to OctoPrint

 

Some slicers, like Slic3r, have a built-in feature that allows you to send gcode files directly to OctoPrint’s queue without saving and uploading manually. I wanted this feature in Simplify3D.

Someone must have done this already, right?

Kinda. there are a few solutions I found, but they have some disadvantages:
cURL – using cURL to send a POST request to OctoPrint’s REST API via the additional terminal commands for post processing in Simplify3D. This works, but it has a security flaw. A pretty big one – Simplify3D includes the post processing command inside the Gcode file, and the command for cURL contains the unique and secret API key for your OctoPrint server.
This means that ANYONE who has access to the interface (let’s say you opened a port in the router and made it accessible from anywhere) can download files in the queue WITHOUT LOGIN, open them, read the API key and take full control over your printer.
Not good.

curl
The content of a Gcode file sent with cURL

scp – what about copying straight to the machine? well, yes, it works. We are not using the API so no key is required and if you set up ssh keys, you wont need to enter your username and password.
The problem with this is that we are moving files behind OctoPrint without talking to the application, this means that in order to see our file in the queue and print them, we must refresh the webpage.
Not what I’m looking for.

A better solution

From the other examples we learn that we can’t have the API-key in the command and that we must talk to the server (i.e. use the API). This brings one thing to mind – a script!

After some googling and learning a bit about REST and python, I wrote this simple script :

import requests
import sys
requests.post('http://192.168.123.102/api/files/local', files={'file': open(sys.argv[1], 'rb')}, headers={'Host': '192.168.123.102', 'X-Api-Key': 'XXXXXXXXXXX'})

The “local” in the url can be changed to “sdcard” in order to save the files on the SD card.
In order to use the script for your setup, replace the IP with your server’s IP and the API-Key with the one for your server (can be found in OctoPrint’s settings under API).

After testing that the script works on its own, it was time to insert it to the post-processing box in Simplify3D.

settings

Note that because I put the script in the Simplify3D folder, the program needed to be run as administrator to run the script (took me a while to figure that one out). You can put it anywhere else and not have this problem.

We can see that there’s no key in the post processing command, let’s see if that’s the same in the file:

pyscript
The content of a Gcode file sent with python script

Success!

Additional features

Once you realize that you can run arbitrary scripts after the file saves, you can do pretty much anything. The REST API allows you to fully control the printer and local commands work fine. I haven’t found any use for other functionalities at this point, but I saw some people who wanted the file to be removed from the computer once uploaded or maybe start the print when the file uploads or run a special Gcode sequence. Not a problem, a quick look at the documentation and you’ll find commands for anything in the interface and a lot more.

3D Printer Lead Screw Upgrade

I built my 3D printer more than a year ago and I think it’s time for an upgrade.

This upgrade was long due and delayed because of lack of time (I worked full time in the summer) and the crawling pace in which the local postage service here works, but enough excuses – let the fun begin!

This upgrade will concentrate on the Z axis movement only, and the replacement of the threaded rods with proper lead screws.

Lead Screw? But Why?

After a year of printing, it can clearly be seen that threaded rods are not meant for this kind of application. The rod itself is not straight (which is not that big of a deal because there are straight rods keeping the movement straight), it squeaks pretty loudly during movement and its threads get full of black goo that consists of dust, oil and metal shavings from the friction with the nut.


A threaded rod is meant to be tightened with a nut and not move, the whole principal of its operation is based on friction – a thing we don’t really want in a moving mechanism.
A lead screw is much more rigid, it’s very hard so it doesn’t bend, it has a very smooth surface and its shape is specifically designed for moving inside a nut.

Made from scratch

I searched for a premade model so I wouldn’t have to model everything from scratch, but with all the different variations and sub-models of the Prusa i3, I couldn’t find one that I was sure would fit without further alterations. Eventually, I decided to design them myself and share for everyone with a similar printer to mine.
I had some big plans and special designs for this project, but It would take a lot of time and I couldn’t stand the threaded rods any more, so I decided to take the current design and improve on it. After the printer is functional with the threaded rods installed, I could take my time and experiment.
This project took two days total over the weekend, including modeling, printing and installing.

To keep the nut in place, I embedded M3 knurl nuts in holes in the plastic about 0.5 mm smaller in diameter than the outside of the nuts. The nuts are inserted by heating them with a soldering iron and pushing them in. A screw helps keep the nut straight while it’s inserted.
The linear bearings are held in place by the plastic itself.

At first, I thought I could get away with replacing only the X axis mounts, but I didn’t account for the lead screw’s center that had to move to make room for the big nut. eventually (after disassembling the printer, swapping the mounts, reassembling and realizing the mistake) I remodeled the mounts, printed them again and reassembled everything.

The old top bracket only supported the straight rod, the threaded rod’s top was floating, which didn’t help with it not being straight.
I improved on the design by including support for the new lead screw, which barely needs it thanks to it’s rigidity.
Instead of letting the lead screw move inside a hole in the plastic, I included bearings that hold the lead screw securely in place while letting it rotate freely.

The bottom brackets are basically the same, I just had to move the straight rod’s hole further out to follow the center dictated by the X axis carriage and the bigger lead screw nut.

All parts were printed in blue PLA @ 0.2 mm layer height and 200 degrees C with no support and no heated bed.
All models are available for Free download on Thinginverse.

wpid-wp-1447771950553.jpeg

The lead screw and threaded rod have different thread counts (the amount of turns per length unit) so the steps per millimeter value for the Z axis needs to be changed in the firmware. This is easily done by simply moving the Z axis 100 mm (direction doesn’t matter), measuring the actual movement and multiplying the current steps per millimeter value by the actual movement measured divided by 100 (watch your units). Repeat this process a few times, each time gets you closer until you reach the accuracy wanted.
Note that the error will be more apparent with longer movements. If you move your axis 1 mm and measure you might not see the error. A 1% error would translate to 0.01 mm with a 1 mm movement (which is something my analog caliper can’t measure), but with a 100 mm movement it would be much clearer at 1 mm.

20151026_001340

That’s it. All done. No more squeaking Z axis and wobbly rods. I don’t expect a real improvement in printing quality, although that would be nice, but an improvement in the printing experience.

Final Thoughts

I’ve had some comments about losing resolution with lead screws because of the lower thread count, so lets see if that’s true (spoiler – it’s not):
The threaded rod I had measured at about 1 mm per turn (if I turn it inside a nut once, it will move 1 mm through the nut) and the lead screw measures at around 7.5 mm.
This means that my lead screw is 7.5 times faster than my threaded rod. If I want them to move the same distance, I need to turn the lead screw 7.5 times less than the threaded rod.
If I had a continuously rotating motor, I could, theoretically, have the same resolution (infinite) but the motors used in my printer are stepper motors, these motors move in steps and not continuously. My motors take 200 steps to make a full turn, this is the maximum resolution we can reach (well, there’s microstepping but the idea is the same, there still is a step to be made that determines the maximum resolution and amount of error to be expected).
With 200 steps per turn and 1 mm per turn, we get 200 steps per millimeter. That’s 0.005 mm per step. That’s the smallest increment in length we can make without microstepping.
At 7.5 mm per turn we get 0.0375 mm per step. While this is a larger number, the smallest increment you would expect to make while printing is still even larger. So what does this mean?
This means that the Maximum resolution your axle can reach will go down, but because the actual maximum resolution a 3D printer can reach is even lower, this doesn’t matter.
The maximum resolution I reached with my printer is 0.1 mm layer height and I don’t print at that resolution often. Even if I try to reach 0.05 mm, the lead screw would still be enough. Moreover, my firmware has microstepping enabled so the maximum resolution is much higher (microstepping can go down to 1/32 or even 1/64 of a step) and if I really want to go crazy, I could get geared motors to reduce the ratio to 1:14, 1:30 or even slower.