【发布时间】:2017-10-14 14:02:48
【问题描述】:
我使用两个蓝牙信标和两个飞利浦 Hue 灯。我有一个 JSON 文件,其中包含每个区域的信标 UUID 和灯光 ID:
{
"features":
[
{
"iot_identifier" : "1",
"iot_beacon_uuid" : "E2C56DB5-DFFB-48D2-B060-D0F5A71096E1"
},
{
"iot_identifier" : "2",
"iot_beacon_uuid" : "E2C56DB5-DFFB-48D2-B060-D0F5A71096E0"
}
]
}
我的代码中还有一个显示当前区域 UUID 的字符串。当我进入另一个区域时它会改变。
这是我在读取 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
}
}
因此,每当我切换区域时,"regionUUID" 字符串都会发生变化。目前,无论我在哪个地区,我总是能够控制两个灯。
我正在寻找的是一种仅控制 JSON 文件中具有当前信标 UUID 的灯的方法。
类似:
对于regionUUID.equals(iot_beacon_uuid),只控制特征中regionUUID等于iot_beacon_uuid的ID的灯。
如果我改变区域,那么我只想控制另一个特性中的另一个灯,这句话再次成立。
有人可以帮我解决这个问题吗?
【问题讨论】:
标签: android json altbeacon philips-hue