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.