Recently my team has been working on developing an Android application to serve as a purpose similar to a teacher-attendance tool. The idea is a teacher device will advertise and around ~20 student devices will discover and connect with it.
Right now, we are testing with three Kindle Fire 7 devices. One is the "teacher" and the other two are students. Our use case is:
- "Teacher" device advertises
- First "student" device discovers
- Verify first "student" device is connected to teacher
- Second "student" device discovers
- Verify second "student" device is connected to teacher
It turns out, when a specific one of the devices is used as the "teacher," the above use case works every time with no problems. However, when the "teacher" is hosted on either of the other two devices, we encounter some problems. The most common result in this case is that the teacher will advertise, the first student will discover it and connect, and then the second student will discover it as well, but will fail to request a connection (line 5 above), returning STATUS_BLUETOOTH_ERROR. In some cases, the same device will significantly delay its process of discovery, in which it stalls for several minutes before it even starts looking for endpoints, and eventually results in the same error.
I've scanned through Stack Overflow posts regarding this bluetooth error, and we've tried to make the fixes that have been suggested- having bluetooth toggled, setting both P2P_STAR and P2P_CLUSTER as the strategy, restarting the devices, stopping discovery of the faulty device and re-attempting discovery and requesting the connection- but unfortunately it seems like none of these are really resolving the issue.
Does anyone have insight into why this could succeed on certain devices, but not for others? We made sure all of these devices have identical network settings/configurations, and they're the same model of Kindle, so I'm not sure what could be going wrong.
EDIT: I haven't included my code because there's a lot pertaining to Nearby Connections and I didn't want to make the length of this post overblown; In general, we directly emulated the approach demonstrated by Google's example repos for Rock, Paper, Scissors and Walkie-Talkie. If it would still be helpful to see the code, I will post it.