Mirror beacon demo with location beacon


#1

I am trying to implement mirror beacon demo with one of my beacon.

I have created app in estimote cloud, assigned tag (mirror_demo) to mirrors as well my beacon and followed step shown cast-from-a-mobile-app. I am able detect my beacon but content is not shown on mirror display.

Here is my code.

    class MirrorHome : AppCompatActivity() {

        private lateinit var mirrorClient : MirrorClient
        private lateinit var  observationHandler : ProximityObserver.Handler

        private  val ESTIMOTE_APP_ID:String ="mirror-demo-cred" //replaced here(have valid creds)
        private  val ESTIMOTE_APP_TOKEN:String ="my_cred" //replaced here(have valid creds)
        private val TAG="mirror_demo"
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
            setContentView(R.layout.activity_mirror_home)
            initBeacon()
        }

        private fun printLog(msg:String){
            Log.e(MirrorHome::class.java.simpleName,msg)
        }

        private fun configureAndRunMirror(){
            val posterData = PosterViewData.Builder()
                    .setHeader("Hello, Herman!")
                    .setBody("You just picked one of your beacon.")
                    .setImage("assets/estimote.png")
                    .create()

            val posterStyle = PosterViewStyle.Builder()
                    .setTextAlign("center")
                    .setTextPosition(Position(Horizontal.center(), Vertical.bottom(80)))
                    .setImagePosition(Position(Horizontal.center(), Vertical.top(80)))
                    .create()

            val poster = PosterView(posterData, posterStyle)

            //Create a MirrorClient object
            mirrorClient = MirrorClient.Builder(this).build()


            val dictionary = Dictionary()
            dictionary.template = "Herman"
            dictionary.put("Product Name", "Savanna")
            dictionary.put("Info", "Thanks for grabbing life by...")


            //Prepare your Estimote Cloud credentials
            val cloudCredentials = EstimoteCloudCredentials(ESTIMOTE_APP_ID, ESTIMOTE_APP_TOKEN)

            //Build ProximityObserver with Cloud credentials
            //You can find here how to build it:
            // https://developer.estimote.com/proximity/android-tutorial/#create-a-proximity-observer-object
            val proximityObserver =
                    ProximityObserverBuilder(applicationContext, cloudCredentials)
                            .withLowLatencyPowerMode()
                            .withTelemetryReportingDisabled()
                            .withEstimoteSecureMonitoringDisabled()
                            .onError {
                                if(it.message!=null) {
                                    txtBLEError.text = it.message
                                }
                                it.printStackTrace()
                            }.build()

            //Define a near proximity zone:
            val nearZone =  ProximityZoneBuilder()
                    .forTag(TAG)
                    .inNearRange()
                    .onEnter {
                        printLog(it.deviceId+" "+it.tag)
                        txtBLEError.text=""
                        txtBLEMirror.text="\nBeacon found : "+it.deviceId+"\n\nTAG "+it.tag
                        if(it.deviceId == "52cd1b1d48607200c68639bea89ab527"){
                            txtBLEMirrorView.text="\nMirror Found : "+it.deviceId+" TAG : "+it.tag
                        }
                        mirrorClient.forDevice(it.deviceId)
                                .take(dictionary)
                                .display()

                        mirrorClient.forAnyDevice().take(poster)

                    }
                    .build()

            //Start proximity observation for declared Proximity Zone
            observationHandler = proximityObserver.startObserving (nearZone)
        }


        /**
         * Initialize beacon with necessary permission
         */
        private fun initBeacon() {
            RequirementsWizardFactory.createEstimoteRequirementsWizard()
                    .fulfillRequirements(this, onRequirementsFulfilled = {
                        configureAndRunMirror()
                    }, onRequirementsMissing = {
                        for (req in it) {
                            printLog("Req missing " + req.name)
                        }
                    }, onError = {
                        it.printStackTrace()
                    })
        }


        override fun onDestroy() {
            super.onDestroy()
            try {
                observationHandler.stop()
                mirrorClient.destroy()

            }catch (ex:Exception){
                ex.printStackTrace()
            }

        }

Let me know where am I going wrong.


#2

@Manoj_Neosoft,

Thanks for sharing the feedback and code snippet with us :slight_smile:

I think that Proximity SDK doesn’t cooperate with your Estimote Mirror - the probable issue here is incorrect settings configuration on the device.

To update the configuration and make it correct, you’ll need to synchronize the device with Estimote Cloud. You can easily do that by connecting to the Estimote Mirror through Estimote’s Android application.

  1. Go to the Configuration
  2. Click on the appropriate Mirror
  3. Connect and synchronize settings

That should solve the problem and you’ll be able to detect Mirror zones properly and send the content to the device.

One more thing that comes to my mind is that you are trying to display 2 different things at once:

mirrorClient.forDevice(it.deviceId)
   .take(dictionary)
   .display()

mirrorClient.forAnyDevice().take(poster)

A rule of thumb is displaying only one view at a time.


#3

I assume that Proximity SDK is able to detect Mirror (so you are getting Beacon found:) and it is mirrorClient that does not connect and display content.

// Are you sure that there is a template "Herman" on Mirror? You don't have any error listeners  registered here so there is no way of knowing it in the code.
mirrorClient.forDevice(it.deviceId)
                                .take(dictionary)
                                .display()

// This line does nothing because there is no .display() at the end
                        mirrorClient.forAnyDevice().take(poster)

Try this to get some error messages:

mirrorClient.forDevice(it.deviceId)
                          .take(dictionary)
                          .onDisplayFailure {
                              txtBLEMirror.text = it.toString()
                          }
                          .onDisplaySuccess {
                              txtBLEMirror.text = "Success"
                          }
                          .display()

Try this and see if it works:

                    val dictionary = Dictionary()
                    dictionary.template = "estimote/clock"
                    mirrorClient.forDevice(it.deviceId)
                            .take(dictionary)
                            .onDisplayFailure {
                                txtBLEMirror.text = it.toString()
                            }
                            .onDisplaySuccess {
                                txtBLEMirror.text = "Success"
                            }
                            .display()

#5

Thanks, I will try to synchronize settings to cloud first as my Proximity sdk is not able detect mirror.
dictonary display and poster display I was testing. I am testing it with one at a time only.


#6

This code block works, I had to go very close to mirror beacon.
However I wanted it to work like if I lift my blueberry beacon it should trigger mirror one, But it says it cannot detect mirror in that case. Testing it with inFarRange(). Also if you could tell me how to change tags programmatically for beacon. is there any api available for same?