SOLVED: "Error claiming the device. Could not claim the device to your account"

Okay, so I found why this was ultimately caused.

I have known Raspberry Pis to take quite a while (seconds) to properly sync their filesystems to SD card once filesystem changes are made. Keep this in mind — RPi 1’s are especially vulnerable to this.

  1. Install fresh Raspbian to SD card.
  2. Boot on an old RPi 1 B
  3. Install particle-agent. This provisions a device_id and copies files into the proper directory in /var/lib/particle/devices.
  4. When the USB bus fails (as detailed in my other thread), unplug power within seconds. At this point, an inode has been created for /var/lib/particle/devices/<devid>/server_key.der, but no data was actually synced to the SD card!
  5. Now, move that SD card into a RPi 2 B which is not vulnerable to the USB bus weirdness, and boot.
  6. The Particle firmware silently accepts the zero-length server_key, and extrapolates a 0.0.0.0 IP address from it, causing the behaviour detailed in this thread.
  7. Subsequent re-runs of particle-agent setup do not fix this problem, due to this code, which doesn’t bother copying the key if the server_key merely exists (ignoring whether it is actually valid data or not): https://github.com/spark/particle-agent/blob/master/lib/particle_agent/setup.rb#L189-L191

Things that could have avoided this:

  • If the Raspberry Pi 1 B synced to SD card faster, or the user gave it more time to do so (what can I say, I was excited to get all of this working!)
  • Check that the server_key is not empty, either in firmware or in particle-agent setup.
  • In firmware, throw errors if it is empty.
  • In particle-agent setup, re-copy the file from /usr/share/particle/keys if it is determined to be empty.
3 Likes