try {
while (close.get() == 0) {
if (deviceThreePresent.get() == 1) {
// Thread.sleep(3000);
ZigBeeDevice device = findDevice(api, 3);
System.out.println("+++ ACTION FOR DEVICE " + device);
// api.on(device);
waitingForEvents.add(api.read(device, ZigBeeApiConstants.CLUSTER_ID_BASIC, Attributes.MANUFACTURER_NAME.getId()));
deviceThreePresent.decrementAndGet();
}
Thread.sleep(1000);
Set<Future<CommandResult>> toRemove = new HashSet<Future<CommandResult>>();
System.out.println("Waiting for " + waitingForEvents.size() + " responses to be received");
for (Future<CommandResult> f : waitingForEvents) {
if (f.isDone()) {
CommandResult cr = f.get();
System.out.println("Command status: " + cr);
if (cr.isSuccess())
System.out.println("response : " + cr.getResponse());
toRemove.add(f);
}
}
waitingForEvents.removeAll(toRemove);
}
}
Actually, if a command is issued imediately after the device is found/detected, the AF-DATA_REQUEST is timed out.
If a sleeptime is added (Thread.sleep(3000);), the command behaves as expected.