How to prevent accidental flash from web ide?

I keep flashing code to the wrong photon device from the web ide. I just forget to change which device is selected. Is there way to lock a particular device to make it harder to do this accidentally?

Or, is there is there a way to prevent a specific device from running code not intended for it? Like if there was a switch in the firmware that looks for something specific in the user code before executing the code. If not maybe there is something I could do in all my code that checks for a hardware serial number before executing code.

This is not possible in the Web IDE. The recommend method is to use Particle Workbench, which remembers the target device per project.

You could make the device part of a product. If a product device is flashed with different firmware (OTA or locally by USB, DFU, or SWD/JTAG), when it next connects to the cloud it will be flashed back to its configured product firmware.

With Device OS 6.0 device protection it will be possible to prevent all on-demand OTA, USB, DFU, and SWD/JTAG flashing at the device level, though this is intended for enterprise products, not individual developer devices.

There is no way to make firmware check itself, since by the time your custom checking firmware runs, the old firmware will be deleted, which kind of defeats the purpose, though you could do something like go into safe mode at that point.

What I was thinking is that if my custom firmware could ID the device it is running on somehow it could then stop executing a portion of the code. Like a all encompassing if statement. Or maybe it could just stop itself from writing to outputs. Is there a way to check the devices serial number or name from my code?

I'll have to looking making it part of a product as you suggested. I'm not sure what that involves but I think I saw it in the console.

Use System.deviceID() to get the device ID and then use that to execute only certain parts of your code. That's much easier than the name, which is not stored on the device.

Thanks, that sounds like it will work.