To get successful results from PostBoxControler API you have to ensure the following:
1. Bluetooth must be enabled on the device.
2. The (MyRenz) Box must be physically nearby.
3. The (MyRenz) Box PKA id must match the configuration.
If any of these requirements are not met you will not get a NearbyPostBox, because you won’t be able to open it.

Get Nearby PostBoxes

With the PostBoxController you can observe NearbyPostBox‘es.

postBoxController.getNearbyPostBoxes().collect { nearbyBoxes: List<NearbyPostBox> ->
    // get list of nearby boxes (when available)

Every NearbyPostBox contains a PostBox, which can be either a LetterPostBox or a ParcelPostBox.

If the PostBox is of type LetterPostBox you do not need to set any PostBoxCredentials. If it is a ParcelPostBox you must set the PostBoxCredentials before you wanna open that NearbyPostBox.

The reason is data privacy. We (Sensorberg) are not allowed to store the credentials for a ParcelPostBox. So you have to handle this on your side and setting them before opening them.

Overwrite PostBoxCredentials

The following shows an example how to update the PostBoxCredentials when the Box is of type PostBox.ParcelPostBox.

// we assume you got a nearbyPostBox as a result of postBoxController.getNearbyPostBoxes()

val postBox: PostBox = nearbyPostBox.postBox
if (postBox is PostBox.ParcelPostBox) {
    // create new PostBoxCredentials
    val postBoxCredentials = PostBoxCredentials(username = "username", password = "password")

	// copy the postBox witht new new postBoxCredentials
    val updatedPostBoxWithCredentials: PostBox.ParcelPostBox = postBox.copy(postBoxCredentials = postBoxCredentials)

    // copy the NearbyPostBox with the updated postBox
    val updateNearbyPostBox: NearbyPostBox = nearbyPostBox.copy(postBox = updatedPostBoxWithCredentials)

    // no updateNearbyPostBox is ready to be opened

Open a Nearby PostBox

Once you got a NearbyPostBox you can open it. For integration reasons you must pass an instance of Application., application)
    .onSuccess {
        // ...
    .onError {
        // ...

Our SDK is Kotlin and Coroutines first. So the main API will offer suspend functions or return Flow. We also provide support functions that uses Callback API or LiveData in case you can not use Coroutines (or even Kotlin).