giantpune
Posts: 20
Joined: Wed Sep 30, 2015 10:58 am

Scripting Simplify3D to upload to a flashair wireless SD card

I have a FlashForge Creator Pro printer, a Toshiba FlashAir series III card, and obviously Simplify3D. I spent some time last night getting the 3 of these things to play nicely together. The process was a bit involved, but the end result is I can click the 'save toolpaths to disk' button on Simplify3D and it creates the gcode, converts that to x3g because that's what my printer uses, pushes the file to my flashair SD card which is inserted in the printer, and finally downloads the file again from the flashair card to verify that it was written correctly. I felt this was worth sharing with the community.


I'm using a Linux/KDE system, but with a little work this should work on Windows and OSx.
1 - edit the config file on your flashair care to make it operate in client mode (STA mode in their docs) https://flashair-developers.com/en/docu ... g/#APPMODE . You also need to enter the SSID and passkey for your wireless network. After this, the flashair card connects to your network just like your computer, cell phone, printer, etc. You can send and retrieve files from it from any computer that is on the network.

2 - go into the wireless router's DHCP settings and configure the flashair so it always gets the same ip address. This way, every time you turn you printer on or off or move the SD card, you know that it will be at the same address.
s3d_tut0.png
3 - acquire some code that can upload files to the flashair's upload.cgi script. I was originally using curl, but then stumbled on somebody else's code in python that was a bit more robust and offered the "verify after upload" functionality. Mirrored here https://gist.githubusercontent.com/gian ... /upload.py

4 - add a bit of a wrapper/helper script around the python uploader. There is a bit of a race condition involved with the x3g file creation. When Simplify3D executes our upload script, there is no guarantee that the x3g file has been fully written. This led to me uploading only partial files to my sd card. The solution was to check the x3g's filesize every second and wait until it is not changed before starting to upload it. Our wrapper script is also a handy place to store the IP address of the flashair card. This is what my script looks like https://gist.githubusercontent.com/gian ... lashAir.sh

5 - Add our helper script to Simplify3D's additional commands. Go to the 'Edit Process settings'->'Show Advanced'->'Scripts' screen. At the bottom, find the box for additional terminal commands. Here, you can call your upload wrapper script. There are a couple placeholders you can use that get swapped out for the output path and output filename.
s3d_tut1.png
s3d_tut1.png (11.15 KiB) Viewed 4959 times
s3d_tut2.png
in my case, I used

Code: Select all

konsole -e sh -c "GCODE='[output_filepath]'; /home/j/3dprinting/uploadToFlashair.sh "${GCODE%.gcode}.x3g" || sleep 10"
This opens up my konsole, runs my upload wrapper script, and passes it the full path to the gcode file, but replaces the ".gcode" extension with ".x3g". And if that fails for some reason, it waits 10 seconds to allow me to see the error. You'll need to change this command to something appropriate for your computer and printer.

6 - test it. If you did everything right, then load up a model, click "prepare to print" and when you "save toolpaths to disk", it will do like it normally did, but it should also call our wrapper script, which waits for the x3g file to be written, and passes that file along with our flashair's ip address to the upload.py script, which uploads the file and then verifies it. If everything works, then you have to add the script command to any of the profiles you use for this printer.

This is a gist with both the upload python code and my wrapper script. https://gist.github.com/giantpune/4642bcac24604ac9edf5
JoeJ
Posts: 1435
Joined: Sun Feb 16, 2014 10:52 am

Re: Scripting Simplify3D to upload to a flashair wireless SD

Very cool! Thanks for sharing :D
Djiguy
Posts: 10
Joined: Fri Apr 10, 2015 4:42 pm

Re: Scripting Simplify3D to upload to a flashair wireless SD

Could you also copy the saved file and then paste it directly to the sd via its own wifi connection in the browser tab? That what both files are saved I case the sd card fails.
giantpune
Posts: 20
Joined: Wed Sep 30, 2015 10:58 am

Re: Scripting Simplify3D to upload to a flashair wireless SD

Djiguy wrote:Could you also copy the saved file and then paste it directly to the sd via its own wifi connection in the browser tab? That what both files are saved I case the sd card fails.
The script runs after Simplify3D saves the gcode and x3g files to the computer. After it's done, I have the gcode and x3g files saved on my computer and the x3g file is on my SD card so I can print it using octoprint.
john_davis12
Posts: 1
Joined: Mon Dec 10, 2018 2:17 pm

Re: Scripting Simplify3D to upload to a flashair wireless SD car

Hi could someone help a noobie :mrgreen: to 3d printing, i get to No "3 - acquire some code that can upload files to the flashair's upload.cgi script. I was originally using curl, but then stumbled on somebody else's code in python that was a bit more robust and offered the "verify after upload" functionality. Mirrored here https://gist.githubusercontent.com/gian ... /upload.py " and No 4 and i am totally lost could someone ex-plane what i need to do :oops:
please help.

Return to “General Discussion and Tips”