Android SDK not claiming P1

We’re using the AcroOptics-SparkSetup Android SDK to do discovery on a Particle P1 Module, but we are unable to claim the device for a new user. It goes through all the steps successfully, but it fails while trying to verify the claimed ownership, and the console shows the owner as “unowned”. Note that this also happens when we use the Particle app downloaded from the Google Play store.

Here are the relevant log entries from the claim process:

io.particle.devicesetup.exampleapp I/DiscoverDeviceActivity: Changing owner to particle@ralphdosser.com
io.particle.devicesetup.exampleapp D/DiscoverDeviceActivity: Waiting a couple seconds before trying the socket connection…
io.particle.devicesetup.exampleapp D/DiscoverProcessWorker: Setting claim code using code: LChoGuPn7DqjwYM9IUzWCHkX0k8QYLw4Zoi82VqnchYrgRHp+gUJEyWlm/zNicC
io.particle.devicesetup.exampleapp I/CommandClient: Preparing to send command 'set’
io.particle.devicesetup.exampleapp I/CommandClient: *** BUILT COMMAND DATA: 'set\n80\n\n{“k”:“cc”,“v”:“LChoGuPn7DqjwYM9IUzWCHkX0k8QYLw4Zoi82VqnchYrgRHp+gUJEyWlm/zNicC”}'
io.particle.devicesetup.exampleapp D/CommandClient: Writing command data
Reading response data…
io.particle.devicesetup.exampleapp D/CommandClient: Command response (raw): \n{“r”:0}
Command response: io.particle.android.sdk.devicesetup.commands.SetCommand$Response@36339768
io.particle.devicesetup.exampleapp D/DiscoverProcessWorker: Successfully set claim code

We could use any thoughts on what might be going wrong. Thanks in advance.

The actual error was “Claim code failed error=user can not claim a device belonging to a product”. That typically happens because the device was still claimed to a user, and you can’t transfer a product device that way. Unclaiming from the previous user first should solve that problem.

Is there a way to do that within the Android SDK?

Oh, wait, that device is not currently claimed, but is a product device.

In that case, the problem is that you are using a user-level claim code instead of a product claim code.

If you are using simple auth, make sure you’ve set the product flag, product ID, and token correctly.

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <bool name="productMode">true</bool>
    <integer name="product_id">1319</integer>
    <string name="oauth_client_id">tempmon04-4338</string>
    <string name="oauth_client_secret">460edfd8d70742dd1f1e75c3d5cac5973351465d</string>
    <string name="http_log_level">HEADERS_AND_ARGS</string>
</resources>

If you are using two-legged auth, make sure you’ve injected the session token properly.

ParticleCloudSDK.getCloud().setAccessToken("6be554f128d4a548efab81f9f58078ed3efa824c");

We’re using two-legged. Do I need to get a product session token as opposed to a user session token?

The current login request I’m making is:

https://api.particle.io/oauth/token

with post values:

    "grant_type=password&username={$particleUser}&password={$particlePassword}"

For two-legged you need a product-scoped customer access token. From curl, it would look like this:

curl -X POST -u "tempmon06-3459:460edfd8d70742dd1f1e75c3d5cac5973351465d" \
-d email=customer14a@company.com -d no_password=true \
https://api.particle.io/v1/products/1319/customers

It needs hit the product API so the customer is associated with the product, that’s why claiming was rejected.

Yes, that was essentially it. Many thanks.

1 Like