DeviceConnection+Settings

How can I read multiple settings of a beacon at the same time?

I’ve tried it in this way, but is there a possibility to do it simpler?

DeviceConnection connection = connectionProvider.getConnection(this.connectedTo);

                    connection.connect(new DeviceConnectionCallback() {
                        @Override
                        public void onConnected() {
                            Log.d(TAG, "onConnected: connected to " + connectedTo.deviceId.toString());
                            try {
                                connection.settings.eddystone.uid.namespace().get(new SettingCallback<String>() {
                                    @Override
                                    public void onSuccess(String s) {
                                        Log.d(TAG, "onSuccess: namespace= " + s);
                                    }

                                    @Override
                                    public void onFailure(DeviceConnectionException e) {
                                        Log.e(TAG, "onFailure: ", e);
                                    }
                                });

                                connection.settings.eddystone.uid.instance().get(new SettingCallback<String>() {
                                    @Override
                                    public void onSuccess(String s) {
                                        Log.d(TAG, "onSuccess: instance= " + s);
                                    }

                                    @Override
                                    public void onFailure(DeviceConnectionException e) {
                                        Log.e(TAG, "onFailure: ", e);
                                    }
                                });

                            } catch (Exception e) {
                                Log.e(TAG, "onConnected: ", e);
                            }
                        }

                        @Override
                        public void onDisconnected() {
                            Log.d(TAG, "onDisconnected: disconnected from " + connectedTo.deviceId.toString());
                            connectedTo = null;
                        }

                        @Override
                        public void onConnectionFailed(DeviceConnectionException e) {
                            Log.e(TAG, "onConnectionFailed: ", e);
                            connectedTo = null;
                        }
                    });

connectedTo is current ConfigurableDevice.

As you can see, I always try to get a setting and get it as SettingsCallback…each time.
As I asked above: can I get all settings in one request?

Hmm, sadly, no—you can write multiple settings in one swoop with SettingsEditor, but reading, we haven’t thought of that.

An alternative is to use EstimoteCloud#fetchDeviceDetails, because we keep a copy of all the beacon settings in Estimote Cloud. You’ll get a Device object with access to all the settings.

You can try using com.estimote.sdk.connection.settings.SettingsReader:

    DeviceConnection conn = ...
    SettingsReader reader = new SettingsReader(conn);
    reader.get("interval", conn.settings.beacon.advertisingInterval());
    reader.get("power", conn.settings.beacon.transmitPower());
    reader.read(new SettingCallback<Map<Object, Object>>() {
      @Override
      public void onSuccess(Map<Object, Object> values) {
        int power = (int) values.get("power");
        int interval = (int) values.get("interval");
        ....
      }

      @Override
      public void onFailure(DeviceConnectionException e) {

      }
    });

You can use any objects as keys (as long as they are valid HashMap keys). If a settings is not available it won’t be present in returned map.

1 Like

@pober thank you a lot!