Tried to read 1mb storage with android


#1

Hi, I’m trying to use the 1Mb storage of my Location Beacon on Android and it doesn’t work. Is there any example of complete projet using storage on Android ? I only found pieces of code and i didn’t know how to use them.
I don’t want to use EstimoteSDK.initialize(applicationContext, “YOUR APP ID”, “YOUR APP TOKEN”); to read beacons.
Here’s what I tried

beaconManager.connect(new BeaconManager.ServiceReadyCallback() {
            @Override
            public void onServiceReady() {
                beaconManager.setConfigurableDevicesListener(new BeaconManager.ConfigurableDevicesListener() {
                    @Override
                    public void onConfigurableDevicesFound(List<ConfigurableDevice> configurableDevices) {
                        if(!configurableDevices.isEmpty()){
                            DeviceConnection dc = connectionProvider.getConnectionForStorageRead(configurableDevices.get(0));
                            dc.settings.storage.readStorage(new StorageManager.ReadCallback() {
                                @Override
                                public void onSuccess(Map<String, String> map) {
                                    Log.e("Main", "NEVER PRINT THIS "); //i'd like to do my stuff here
                                }

                                @Override
                                public void onFailure(DeviceConnectionException exception) {
                                    Log.e("Main", "NEVER PRINT TOO");
                                }
                            });
                        }
                    }
                });
            }
        });
        connectionProvider.connectToService(new DeviceConnectionProvider.ConnectionProviderCallback() {
            @Override
            public void onConnectedToService() {
                beaconManager.startConfigurableDevicesDiscovery();
            }
        });

I wrote this with the help of
DeviceConnectionProvider Javadoc
Github Docs
Did i miss a full example of reading storage with android? Because it’s working well on iOS with this
Thank you for helping me.


#2

What do you mean by “it doesn’t work”? Does it crash application? Do you have an error message on console?
Do you receive onFailure callback or you don’t get any callback at all?
Can you provide an error message and a log from logcat?
What SDK version are you using?
Don’t call getConnectionForStorageRead from inside onConfigurableDevicesFound because it would be called multiple times (onConfigurableDevicesFound is called every few seconds). Make sure you call it once.
Have you tried to connect to beacon using authorisation and read temperature for example? Does it work or fail in the same way?


#3

“it doesn’t work” mean I just have no output from ReadCallback. No error, no crash.
I use the SDK version 1.4.1.
Which authorisation do you mean ?
I have ‘com.estimote.mgmtsdk.feature.settings.ReadableDeviceSetting@b6afe53’ when i tried to read temperature…


#4

By authorization I mean generating APP_ID and APP_TOKEN in Cloud console and setting it by:

EstimoteSDK.initialize(applicationContext, “YOUR APP ID”, “YOUR APP TOKEN”);

It is required to access beacon settings, but it is not required to access storage.
com.estimote.mgmtsdk.feature.settings.ReadableDeviceSetting@b6afe53 is an accessor object that is used to read temperature. You need to call get method first.
Here is an example from tutorial how to read firmware version:

connection.settings.deviceInfo.firmware().get(new SettingCallback<Version>() {
  @Override 
  public void onSuccess(final Version value) {
    // Handle read data here. 
    // For example: display them in UI. This callback will be called in the same thread as connection was created (not opened).
    // You can use your activity method runOnUIThread(Runnable runnable) to handle that.
    Log.d("DeviceRead","Read firmware version:  " + value.toString());
  }

  @Override public void onFailure(DeviceConnectionException exception) {
    // Handle exceptions here.
    Log.d("DeviceRead","Reading firmware version failed.");
  }
});

I noticed that there no call to connect method which should look like this (also from tutorial):

// Pass your ConfigurableDevice to connection provider method
DeviceConnection connection = connectionProvider.getConnection(device);
connection.connect(new DeviceConnectionCallback() {
  @Override
  public void onConnected() {
    // Do something with your connection.
    // You can for example read device settings, or make an firmware update.
    Log.d("DeviceConnection", "onConnected");
  }

  @Override
  public void onDisconnected() {
    // Every time your device gets disconnected, you can handle that here.
    // For example: in this state you can try reconnecting to your device.
    Log.d("DeviceConnection", "onDisconnected");
  }

  @Override
  public void onConnectionFailed(DeviceConnectionException exception) {
    // Handle every connection error here.
    Log.d("DeviceConnection", "onConnectionFailed");
  }
});

There should be a log message telling that you are trying to make a read on not connected connection object.
Can you send logs to confirm that?


Not able to read/write from/to beacon storage
#5

I can’t use EstimoteSDK.initialize because the application should work without internet.
I don’t find any getters on this accessor.
When run this i juste have no output. With more output, i find it never enter in “onConnectedToService()” method from DeviceConnectionProvider. Is it normal ?
Most of the time i’ve got “java.lang.IllegalStateException: EstimoteSDK.getApplicationContext() must not be null” for the connect method which mean i didn’t have the autorisation i think, because i don’t want to use initialize.


#6

You have to use EstimoteSDK.initialize to set up and use SDK. That is why you are getting that exception. You cannot just say you don’t want to use it and expect SDK to work. Reading storage does not require internet access, because I would defeat purpose of having storage on Beacon (since you have internet connection, you can call cloud service for data). Calling EstimoteSDK.initialize does not mean you need internet access, you can leave app id and app token empty strings.
temperature() method should return you an object that should have a set of methods to read/write beacon settings. There should be a get method (as in example code from my previous post) that takes callback object to asynchronously read value from beacon.
It is normal to not get onConnectedToService if you didn’t called EstimoteSDK.initialize.


#7

Okay, it’s clearer now, thank you very much.
Now I have log from connect method callback :
E/DeviceRead: Reading firmware version failed.
E/EstimoteSDK: InternalEstimoteCloud$7.failure:531 403 Forbidden
E/EstimoteSDK: DeviceConnectionInternal$1.onError:260 Device […] does not belong to user.
E/DeviceConnection: onConnectionFailed
That’s normal ?


#8

Yes, you cannot read some settings without app ID and app token or from a beacon that you do not own or using connection obtained from “getConnectionForStorageRead”.
I think that the best method to approach this is to:

  1. Follow tutorial and implement code that would read a simple setting (like temperature or firmware version). Use valid appID and appToken.
  2. Add reading storage. Check if that works.
  3. Switch to getConnectionForStorage. Check if that works.
  4. Remove appId and appToken from EstimoteSDK.initalize. Check if that works.

#9

It works well, thank you !