Batch Flash Photons Remotely - A How To

If you want to flash multiple Photons remotely with the same .bin file then here is one way to do it using a VBScript.

For this example, here is what you will need.
-Particle CLI installed

  • A compiled .bin file(on your C drive). As described here. Particle CLI. Take note of the file’s name. Mine is “photon_firmware_1470265344230.bin”

  • A file named Photon_Names.txt on your C drive containing the names of the Photons you want to flash in list form.

  • A .vbs file on your C drive containing to code below. I’m using PhotonBatchUpdate.vbs, but the actual name is not important. Where NameOfBinFile = “The name of your .bin file”.

    'wscript.echo “BEGIN”
    Dim fso, f, oShell, PhotonName, PathToNames, NameOfBinFile

PathToNames = “C:\Photon_Names.txt”
NameOfBinFile = “photon_firmware_1470265344230.bin”
Set fso = CreateObject(“Scripting.FileSystemObject”)
Set f = fso.OpenTextFile(PathToNames)

Set oShell = WScript.CreateObject (“WScript.Shell”)
oShell.run “cmd /K CD C:”

Do Until f.AtEndOfStream
PhotonName = f.ReadLine
'WScript.Echo PhotonName
oShell.run “%comspec% /k particle flash” & " " & PhotonName & " " & NameOfBinFile
WScript.Sleep 1000

Set oWmg = GetObject(“winmgmts:”)
strWndprs = “select * from Win32_Process where name=‘cmd.exe’”
Set objQResult = oWmg.Execquery(strWndprs)

For Each objProcess In objQResult

intReturn = objProcess.Terminate(1)

Next

Loop

f.Close

wscript.quit

Before running the .vbs script(by double-clicking it) you would manually login to your account using command line “particle login”. Then run the script. It will loop through each device name in the Photon_Names.txt file and flash the device with the .bin file.

Note: If you comment in the 'wscript.echo “BEGIN” and 'WScript.Echo PhotonName lines then message boxes will appear showing the current Photon name it is flashing to.

Hope this comes in handy for anyone wanting to update multiple Photons without doing it manually.

1 Like

This a cool idea! I have added this feature to po-util so that Mac and Linux users can flash firmware to multiple devices. It uses a file named devices.txt in the project directory to store the names of devices to flash.

Very cool!

Thanks for sharing this!

Will this work for Electrons also?

Yes it will, but flashing firmware over OTA can use a lot of your cellular bandwidth.

1 Like

Before you do this I think you also need to do particle login, don't you ?

If you have logged into CLI once (and don’t actively log out) CLI will be logged in for any following call.

I couldn’t stop myself todayso I wrote a gitlab-ci to git push to flash to particle photon

1 Like

You can also use Windows batch files/Linux bash scripts, eg

First batch file indicates which devices to program

echo flashall.bat
call flash Photon1
call flash Photon2
pause

Second batch file calls particle cli to perform the OTA update of the device passed in the first parameter of flash.bat

set FIRMWARE=myfirmware.bin
particle flash %1 %FIRMWARE%