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?