Nifty Shell script for compiling and then uploading to device

Using OSX or another unix based computer with Particle? Today I’ve written particle compile and then particle serial flash just too many times. I wanted to find a way to just execute a shell script that can do the compile and upload in one without me cutting and pasting. Here’s what I came up with:

line=`particle compile photon | grep 'firmware to:' | sed 's/^.*: //'`
echo "particle serial flash $line"
eval "particle serial flash $line"
#eval "particle serial monitor --follow"

The first bit compiles and then parses the output that comes after the string "firmware to: " into a variable called $line. We then output and execute this. The fourth line is commented, but if you want to see the serial output after uploading, just remove the hash sign. Press Control+c to exit the serial monitor.

If you put this in a file named “makeit.sh” in your project folder and make it executable (“chmod +x makeit.sh”), you can then just run it to flash the device connected via USB. It’ll stop at the prompt “Press ENTER when your device is blinking BLUE” but just ignore this warning and press Enter to flash :smiley:

Did you know about particle compile photon . --saveTo yourStandardName.bin ?
This way you can just use particle serial flash yourStandardName.bin

3 Likes

Nice one @ScruffR! I didn’t know and it doesn’t show in the builtin help for CLI either? I found it in the docs though.

I also got Eclipse going for local builds this week. That’s a pretty complete solution that I really like when it comes to debugging & uploading. The Intelli-sense isn’t all that great, but it works better than anything I have tried.

1 Like

Hey, here’s how to use VS Code for developing Particle firmware in case you would be interested.
I don’t know how debugging would compare to Eclipse, since I haven’t done that.
Cheers,
Gustavo.

Not to try and advertise, but have you looked into po-util?

It provides many methods for compiling and flashing to devices over USB using dfu-util.