コード例 #1
0
  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);
  }
コード例 #2
0
 private void beaconRangeChange(Collection<Beacon> beacons, Region region) {
   for (Beacon beacon : beacons) {
     String uuid = beacon.getId1().toString();
     DecimalFormat df = new DecimalFormat("#.000");
     String distance = df.format(beacon.getDistance());
     Log.d(TAG, "Beacon (" + uuid.substring(0, 8) + ") is about " + distance + " meters away.");
     Boolean enabled = isBeaconEnabled(uuid);
     if (enabled != null) {
       if (enabled) {
         sendBeaconChangeMessage(beacon);
       }
     } else {
       emitter.emit(EVENTS.DISCOVERED_BEACON, beacon);
     }
   }
 }