0

I work with two Bluetooth beacons and two Philips Hue lights. I have a JSON file which contains the beacon UUID for each region and the light IDs:

{
  "features":
  [
    {
      "iot_identifier" : "1",
      "iot_beacon_uuid" : "E2C56DB5-DFFB-48D2-B060-D0F5A71096E1"
    },
    {
      "iot_identifier" : "2",
      "iot_beacon_uuid" : "E2C56DB5-DFFB-48D2-B060-D0F5A71096E0"
    }
  ]
} 

I also have a string in my code which displays the current region UUID. It changes when I enter the other region.

This is my code to control the two lights after reading in the JSON:

List<Feature> listFeatures; //Features from JSON file
int count = listFeatures.size();

for(int i=0; i<count; i++){

     // Here I have the UUID (not elegant, but does its work)
     String regionString = beaconManager.getMonitoredRegions().toString();
     String regionUUID = regionString.substring(6, 43).toUpperCase();

     // Here I get the JSON properties for each feature
     String iotIdentifierString = listFeatures.get(i).getIotIdentifier();
     String iotBeaconUuid = listFeatures.get(i).getIotBeaconUuid();

     // need this value as double to associate the JSON-ID with the Hue light ID
     double iotIdentifierDouble = Double.parseDouble(iotIdentifierString);

     if( /* anything */ ){

        // get the light with the ID of the current JSON feature
        String lightId = hueLightObjects.getFeatures().get(i).getIotIdentifier();
        final PHLight light = bridge.getResourceCache().getLights().get(lightId);

        // control the lights, turn on/off

     }
}

So the "regionUUID" string changes whenever I switch the region. Currently I am always able to control both lights, no matter in which region I am.

What I am looking for is a way to only control the light that has the current beacon UUID in the JSON file.

Something like:

For regionUUID.equals(iot_beacon_uuid), only control the light with the ID in the feature where regionUUID equals the iot_beacon_uuid.

If I change the region, then I only want to control the other light in the other feature where this statement is true again.

Could someone help me with this?

Arastat
  • 143
  • 1
  • 10

1 Answers1

1

First of all I believe that your question can be more shorter something like ( A Minimal, Complete, and Verifiable example)

So when I am in the region where the minor ID = 1, I only want to select the lamps, where the property "Minor_ID" is also 1

Your code can achieve that in your case it's depend on how you using it after retrieving process.

But you can do that with current way too:

for (int i=0; i<count; i++) {
           if(selectedLamp == iotIdentifierDouble ){
            //do what you wish
           }
    }
  • I completely reworked the question since I wasn't able to express my problem properly. Now I think it is more understandable. What I am ultimately looking for should be independent from the light ID itself. More like "choose all light IDs where the regionUUID equals the corresponding UUID in the features of the JSON file". I hope it's better to understand now. – Arastat Oct 14 '17 at 17:47
  • @Arastat Which UI you used to make effect? listView or what ? –  Oct 14 '17 at 20:27
  • The project is about controlling the lights by pointing on them, so there is no UI, just a single button that triggers the light the smartphone is pointed at. The user gets an indoor map when he enters a beacon region and a red button that turns green, when the smartphone points towards a light. But for now, every light can be pointed at, no matter in what region the light is. The light objects themself are organized in a list, yes, according to the official demo app Philips provide for the work with hue products. But the light controlling doesn't take account of this list. – Arastat Oct 14 '17 at 20:43
  • @Arastat If it's just a button or switch, put your button there and get `String lightId = hueLightObjects.getFeatures().get(i).getIotIdentifier(); final PHLight light = bridge.getResourceCache().getLights().get(lightId);` inside on your click or switch listeners. –  Oct 15 '17 at 03:08