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");
}
};
}