private void startMeshbluListeners() {
   meshblu.on(
       Meshblu.REGISTER,
       new Emitter.Listener() {
         @Override
         public void call(Object... args) {
           Log.d(TAG, "Regsitered");
           emitter.emit(EVENTS.REGISTER, args);
           JSONObject deviceJSON = (JSONObject) args[0];
           setCredentials(SaneJSONObject.fromJSONObject(deviceJSON));
           startBeaconMonitoring();
           getDevice();
         }
       });
   meshblu.on(
       Meshblu.WHOAMI,
       new Emitter.Listener() {
         @Override
         public void call(Object... args) {
           Log.d(TAG, "Whoami");
           emitter.emit(EVENTS.WHOAMI, args);
         }
       });
   meshblu.on(
       Meshblu.GENERATED_TOKEN,
       new Emitter.Listener() {
         @Override
         public void call(Object... args) {
           emitter.emit(EVENTS.GENERATED_TOKEN, args);
         }
       });
 }
 public void start(List<String> beaconTypes) {
   this.beaconTypes = beaconTypes;
   startMeshbluListeners();
   if (!meshblu.isRegistered()) {
     Log.d(TAG, "Device is not registered, registering now");
     SaneJSONObject properties = new SaneJSONObject();
     properties.putOrIgnore("type", "device:beacon-blu");
     properties.putOrIgnore("online", "true");
     meshblu.register(properties);
   } else {
     Log.d(TAG, "Device is registered, starting...");
     startBeaconMonitoring();
     getDevice();
   }
 }
  private void sendBeaconChangeMessage(Beacon beacon) {
    String uuid = beacon.getId1().toString();
    // Payload
    SaneJSONObject payload = new SaneJSONObject();
    payload.putOrIgnore("platform", "android");
    payload.putDoubleOrIgnore("version", VERSION);

    // Beacon
    SaneJSONObject beaconJSON = new SaneJSONObject();
    beaconJSON.putOrIgnore("uuid", uuid);
    payload.putJSONOrIgnore("beacon", beaconJSON);

    // Proximity
    payload.putJSONOrIgnore("proximity", getProximity(beacon));

    // Message
    SaneJSONObject message = new SaneJSONObject();
    JSONArray devices = new JSONArray();
    devices.put("*");
    message.putArrayOrIgnore("devices", devices);
    message.putJSONOrIgnore("payload", payload);
    message.putOrIgnore("topic", "location_update");

    // Send
    BeaconInfo beaconInfo = getBeaconInfo(this.beaconInfo, uuid);
    Double distance = beacon.getDistance();
    if (beaconInfo.hasChangedDistance(distance)) {
      meshblu.message(message);
      emitter.emit(EVENTS.LOCATION_UPDATE, payload, beaconInfo);
    }
    beaconInfo.setLastDistance(distance);
  }
 private void setCredentials(SaneJSONObject deviceJSON) {
   meshblu.setCredentials(deviceJSON);
 }
 public void generateToken() {
   meshblu.generateToken(meshblu.uuid);
 }
 public void getDevice() {
   meshblu.whoami();
 }