Commissioning on Android phone and only getting timeouts

So I have downloaded the SDK and have added it to my project. I am following the example apps and I am only getting timeouts whenever i try to commission the app.

I’m not sure what could possibly be wrong?

Also, does the SDK handle/check if the wifi password is valid? or should we get an error that will tell us if the wifi password or wifi is invalid? Or how would we know that it is the wifi that is incorrect if the blinkup were to fail.

Also, I tested by passing in valid and invalid wifi credentials and I only get a timeout.

Below is my code which is pretty much following the example codes. So not sure if there something that I am missing here?

  public class ConnectBreakerStartActivity extends BaseActivity {

private ActivityBlinkupStartBinding binding;
private ConnectBreakerStartActivityVM viewModel;
private BlinkupController blinkupController;

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    binding = DataBindingUtil.setContentView(this, R.layout.activity_blinkup_start);
    viewModel = ViewModelProviders.of(this).get(ConnectBreakerStartActivityVM.class);

    setUpToolBar();
    setUpBlinkUp();
}

@Override
protected void onResume(){
    super.onResume();

    viewModel.getUpdatedCurrentRegistrationFromRealm();
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    blinkupController.handleActivityResult(this, requestCode, resultCode, data);
}

private void setUpBlinkUp() {
    blinkupController = BlinkupController.getInstance();
    blinkupController.intentBlinkupComplete = new Intent(
            this, ConnectBreakerSuccessActivity.class);
 

    binding.blinkupInformationStartButton.setOnClickListener(v -> 
    blinkupController.selectWifiAndSetupDevice(ConnectBreakerStartActivity.this, 
    getString(R.string.BLINKUP_API_KEY), errorHandler));
 }

  private ServerErrorHandler errorHandler = s -> {
    Toast.makeText(ConnectBreakerStartActivity.this, s, Toast.LENGTH_LONG).show();
    Log.d("Error", ": " + s);
  };

}

My activity that handles the result, or should. But I only get a timeout from the token.

public class ConnectBreakerSuccessActivity extends BaseActivity {

private ActivityBlinkupSuccessBinding binding;
private BlinkupController blinkupController;

private SimpleDateFormat dateFormat = new SimpleDateFormat(
        "yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.US);

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    binding = DataBindingUtil.setContentView(this, R.layout.activity_blinkup_success);

    blinkupController = BlinkupController.getInstance();
    setUpToolBar();
}

@Override
protected void onResume() {
    super.onResume();
    blinkupController.getTokenStatus(callback);

}

@Override
protected void onPause() {
    super.onPause();
    blinkupController.cancelTokenStatusPolling();
}

private TokenStatusCallback callback = new TokenStatusCallback() {

    @Override
    public void onSuccess(JSONObject json) {
        SharedPreferences pref
                = PreferenceManager.getDefaultSharedPreferences(
                ConnectBreakerSuccessActivity.this);
        SharedPreferences.Editor editor = pref.edit();

        try {
            String dateStr = json.getString("claimed_at");
            dateStr = dateStr.replace("Z", "+0:00");
            Date claimedAt = dateFormat.parse(dateStr);

            String planId = json.getString("plan_id");
            String agentUrl = json.getString("agent_url");

            String impeeId = json.getString("impee_id");
            if (impeeId != null) {
                impeeId = impeeId.trim();
            }

            editor.putString("planId", planId);
            editor.putString("agentUrl", agentUrl);
            editor.putLong("claimedAt", claimedAt.getTime());
            editor.putString("impeeId", impeeId);
            editor.commit();

            finish();
        } catch (JSONException e) {
            onError(e.getMessage());
        } catch (ParseException e) {
            onError(e.getMessage());
        }
    }

    public void onError(String errorMsg) {
        Log.d("BlinkUp error "," :  "+ errorMsg);
    }

    @Override
    public void onTimeout() {
        Log.d("BlinkUp:", " timeout");
    }

 };

}

If you’re not an Electric Imp customer, the SDK will not work for you — it requires authorization that is only available to customers (the API key).

We are a customer and we do have an API Key.

So I’m not sure what we are possibly doing wrong. The SDK seems fairly simple to follow and so do the examples, which we are following to the dot. My only thought is if its possible that a configuration is set wrong? F

For example, if I want to use a Google API service, then i generate a key by associating it with my apps package name. We were never asked for our package name, so I’m not sure if maybe some configuration is off. I could totally be wrong here though.

I assume you’re not seeing the BlinkUp flash? Sounds like it’s timing out when the SDK requests a device enrollment token and plan ID. What is the logged error message?

Calling selectWifiAndSetupDevice() is the easiest mode. It asks you for WiFi details and then connects to the impCloud and retrieves a plan ID and an enrollment token; it then sends these and the WiFi details to the device. There’s no further config required than providing your activity and error handler function, and your BlinkUp API key, so it sounds like this is something to do with your phone’s connectivity.

The SDK doesn’t check the validity of entered WiFi credentials.

What you might try is calling blinkupController.setupDevice(), which takes your WiFi SSID and password as strings.

What version of the SDK are you using, BTW?

One further thing to check: you do have a BlinkUp API key, not a Build API key (from the legacy IDE)?

We do see the blinkUp flash. And yes the process times out, the Timeout in the TokentStatusCallback is what gets called. Once in a while the onError from the TokenStatusCallback gets called, and the error message is “timeout”. So not much help there with the error message.

And we have tried both setupDevice() and selectWifiAndSetupDevice and both are giving us the same issue.

We have also tried it with two phones with both of them connected to the LTE network or wifi. We also made sure that the brightness is all the way turned on for both phones, and we also accounted for the power saving mode being disabled for the Samsung phone we used. (Other phone we used was a Pixel XL)

And we are using the 6.3.0 version of the SDK. And we are currently checking in with the people who gave us the key to make sure that it is the correct key.

And as far as verifying the wifi password. What is the best way to handle on verifying this (what suggestions do you guys have)? We have tried to verify this in the app but it is apparently not possible, unless you are Google since they have special APIs.

Thanks for the help so far.

You need to check that the imp-enabled device you are trying to configure is either a blessed production device or a development device that has been already assigned to any development device group (impCentral) or model (legacy IDE). Note that the device group/model must be within the account to which the API key belongs.

If the device is not blessed and hasn’t been assigned to a device group, its enrollment will be rejected. This is because the SDK delivers production BlinkUp, not developer BlinkUp (you can only use the Electric Imp app to enrol ‘raw’ development devices).

You should also update to SDK 6.3.2.

1 Like

Thanks for the help so far.

But I will verify that the device we are trying to commission is actually assigned to the account to which the API key belongs. I honestly think that this is the problem.

And I’m not following this part of your comment, (you can only use the Electric Imp app to enrol ‘raw’ development devices). Is this referring the actual Electric Imp app? Like we could use the app to “commission” a device?

Also, I will update to 6.3.2. Didn’t realize that the SDK had been updated from 6.3.0.

Thanks.

Basically if you are trying to enroll a device that is registered to account A (or no account) with an app using the BlinkUp API key for account B, then enrollment will fail. You need to get B to enroll the device for you and to assign it to any device group, then you can test the SDK-based app on that device.

If the development device has not yet been assigned to any account, then yes, it must be added to an account (ie. B) using the Electric Imp mobile app first.

More info on all of this here.

1 Like