Workbench - Can't flash code to device - bad token?

I have had Particle Workbench installed on my computer and I have always used it logged into my personal Particle developer account. Recently, I was asked to fill in for the chief IT person at a non-profit makerspace for a Particle-based system that I helped to develop. In the past, I have always developed and tested in my own Particle account and then turned the code over the the IT person for installation on the deployed Particle devices, which are in the facility's Particle account. Now that I am filling in for the IT person who is out of the country for a month, I found a need to flash code onto a deployed Particle device. I was given the facility's login and password and I used these credentials to log in to the facility's account via the workbench. Everything went fine until I tried to OTA flash compiled code to a device in the facility's account. Flashing failed owning to a token error. No further information was given on the terminal.

I tried several times - same result. I logged out of the facility's account and got the option to retain the token. If I say "Y", logout goes OK. If I say "n", I am asked for the password, which I gave correctly, but the logout is rejected.

I logged in and out with my personal account, both keeping the token and not keeping it, and all worked fine. But this procedure does not work with the facility's account.

I tried the web IDE with the facility's account and had no problem flashing code to the device.

I uninstalled VS Code and reinstalled it but the problem persists. After reinstalling VS Code and the Particle extensions, I was surprised to find out that launching Workbench seems to have all of my history, even through a complete reinstall of the code. Therefore, I believe that uninstalling the code leaves some file with my settings on the my computer, and that this file must have the "offending" token stuck in it.

Please help me to clear this up so that I can flash code to facility devices using Workbench. I am acting IT for the next 3 weeks and I need to maintain devices deployed in the facility. Using Web IDE is fine to flash Blink to a device, but there are too many files in the production code to make this a viable option.

How did you log into Workbench? From the command palette, Particle: Login is the option to change the account Workbench is logged into. You don't need to revoke any tokens to do that.

Yes, Particle:Login from the command palette. The login went OK but I can't flash devices that are claimed to this account and are online. The terminal says invalid token. The login and password are correct and i could flash code to these devices using this login and the Web IDE. so there must be some sort of "bad token" stuck in my workbench somewhere. But it won't let me logout with the option to not keep the token. This behavior is different than when I use the same workbench to login to my personal accout.

Hi Bob,
totally shooting in the dark here, but what happens if you execute particle login at the command prompt (with particle CLI)?

@gusgonnet : Thank you for the suggestion. I have already tried this and the result is the same.

Just to be clear: I am having no problem at all logging into Workbench. I can log in with my personal account and I can log in with the facility IT account. Both work and both let me edit and compile code. The problem is that I cannot OTA flash code to a Particle device that is claimed into the facility account even when I am logged into this account. The flash fails, with a message about an invalid token showing in the workbench terminal. I can log out of the facility IT account just fine, but only if I answer "Y" to the message about keeping the token. If I answer "n" to this question (to get rid of the token), I am prompted for my ID and PW but these credentials are rejected and I can't log out this way. So I am stuck with some bad "token" in my computer and I can't find it or otherwise get rid of it.

Just to be clear, when I do exactly the same things but logged in to my personal Particle account, there is no problem developing, compiling and cloud flashing to Particle devices that are claimed into my personal account. It all works, but not in the facility iT account.

Furthermore, I can use the web IDE to log into the facility IT account and I can compile and OTA flash code to Particle devices in the facility account just fine. So there are no problems with my facility IT credentials. There is something bad cached on my computer and I can't get rid of it.

One last clue that I believe is important: In an effort to clean out my computer's Workbench environment, I used Windows add or remove program to remove VS Code from my computer. Then I followed Particle's online instructions to reinstall VS Code and then the Particle extensions. Everything here went fine, but the problem persists. The clue here is that after a clean reinstall of Workbench, when I opened Workbench, I could do things like open-recent and Workbench shows me all of my recently accessed workspaces. So a "clean install" did not get rid of some file(s) that is storing all of my history and other information (including, I assume, this offending token). Windows removal of the program does not remove whatever personal Workbench history is cached on my computer. I believe that the file(s) that contain this history also contains the offending token and if I could identify and delete this file(s), I could then do a completely clean reinstallation and I believe that the problem would be fixed. However, I don't know what or where this file is!

One last point - I have not tried local CLI flashing of the facility device. I suspect that this won't work either, but it is not practical to do this. I would have to (1) physically go to the facility, (2) grab a bunch of tools and climb up a big ladder to access the device, (3) while standing at the top of the ladder, I would have to unhook several wires form the device and then unscrew the device mounts to remove it from the wall. This is the only way that I could perform local flashing, so OTA is what the facility assumes is the way to update Particle devices.

Question: how do I completely uninstall Workbench, including any history or other information cached on my computer. If I can do this, then I believe that I can do a completely clean reinstallation and get everything working properly. And, PS, what exactly is this "token" that is interfering with my OTA flashing?

I tried again to uninstall and reinstall Workbench. Once again, the "fresh" install seems to know my history, which is strange and perhaps the cause of the problem. Once again, I can log in to my personal account and flash code to devices claimed into my personal accout just fine. I can log in to the facility IT account and I can cloud compile just fine, but it fails when I try and cloud flash the code. Here is what I see in the terminal window of workbench upon failure to flash:

Compiling code for mn_frontdoorsolenoidSpare1
Failed to flash mn_frontdoorsolenoidSpare1: Permission Denied
Error: Command failed with exit code 1: c:\Users\bobg5.vscode\extensions\particle.particle-vscode-core-1.16.16\src\cli\bin\windows\amd64\particle.exe cloud flash mn_frontdoorsolenoidSpare1 --target 3.0.0 --no-update-check
Compiling code for mn_frontdoorsolenoidSpare1
Failed to flash mn_frontdoorsolenoidSpare1: Permission Denied
at makeError (c:\Users\bobg5.vscode\extensions\particle.particle-vscode-core-1.16.16\node_modules\execa\lib\error.js:59:11)
at handlePromise (c:\Users\bobg5.vscode\extensions\particle.particle-vscode-core-1.16.16\node_modules\execa\index.js:114:26)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Note that I can log in to the Web IDE with the same facility IT credentials and flash the code just fine to this same device. So I know that (1) the device is claimed to the facility IT Particle account, and (2) that my facility IT login/PW are correct. I can log in to Workbench with this same account and cloud compile OK but it won't cloud flash.

Please help me to figure out how to fix this.

Between uninstalling Workbench and reinstalling it, you should delete or rename the .particle directory in your home directory. This will get rid of all settings and toolchains that were previously installed.

@rickkas7 : I did that. I also deleted the .vscode directory just to make sure. I then did the new install but I got the same result - there is memory and I can't flash to facility IT claimed devices. The fresh install created these folders again, as expected, but I haven't a clue where the memory is coming from. Sigh ...

Could you DM me the device ID of the device you are trying to flash and the user ID you are trying to use to flash it?

Also try Particle: Launch CLI then from the CLI:

particle whoami
particle flash mn_frontdoorsolenoidSpare1 --target 3.0.0 .

@rickkas7 : message the you requested has been sent.

Using CLI:
PS C:\Users\bobg5\Documents\GitHub\RFID_Lock\Software\Particle_SW\SolenoidFirmware> particle whoami
PS C:\Users\bobg5\Documents\GitHub\RFID_Lock\Software\Particle_SW\SolenoidFirmware> particle flash mn_frontdoorsolenoidSpare1 --target 3.0.0 .
Compiling code for mn_frontdoorsolenoidSpare1
Failed to flash mn_frontdoorsolenoidSpare1: Permission Denied

I finally was able to go into the facility today and power up a spare device (Argon, in this case) that was previously claimed to the facility's Particle account and I verified that I was able to flash code to it from my laptop workbench. So the problem was found to be related to the Photon (that I newly claimed into the facility's account). The IT Manager has returned from his overseas trip and I asked him to flash code to the Photon and he did, no problem. But I could not, using the correct account that is verified by my successfully flashing the Argon. We decided to unclaim the Photon and then to claim it again (to the facility account), but we gave it a different name. Now, I was able to flash code to it from my laptop workbench. We then renamed the device back to the original (correct) name and I can still flash code to it.

The conclusion is that there must have been some issue with the original claiming of the device to the facility account and then my trying to access it from my workbench. There must be some association of a device that it selected in workbench with some sort of access token and this must have somehow gotten corrupted on my laptop. Whatever this association is, it is not stored on the .particle folder that is created upon installation of workbench. The act of unclaiming the device and claiming it again somehow reset this association on my laptop. I cannot verify any of these details about the inner workings of workbench, but my issue is closed.

Thanks all of you who pitched in to help.

1 Like