I want hm-10 to recognize at least 3 android phones.
However, I have often seen mobile phones used as the master and hm-10 as the slave.
I want to measure RSSI with multiple mobile phones on one hm10, so I need to use hm10 as master.
But, even though I am advertising on my cell phone through an app called nRF connect, there is no change when I enter the AT+DISC? command in hm-10.
If anyone has had a similar experience, please give me some advice.
Below is my Arduino code
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(2, 3);
void setup() {
Serial.begin(9600);
BTSerial.begin(9600);
sendCommand("AT");
sendCommand("AT+RESET");
sendCommand("AT+ROLE1");
delay(1000);
}
void loop() {
Serial.println("Scanning for BLE devices...");
sendCommand("AT+DISC?");
String response = getResponse();
parseAndPrintDeviceNames(response);
delay(5000);
}
void sendCommand(String command) {
BTSerial.println(command);
delay(500);
}
String getResponse() {
String response = "";
long timeout = millis() + 5000;
while (millis() < timeout) {
if (BTSerial.available()) {
char c = BTSerial.read();
response += c;
}
}
return response;
}
void parseAndPrintDeviceNames(String response) {
int index = 0;
while ((index = response.indexOf("+DISC:", index)) != -1) {
int startIndex = response.indexOf(",", index + 6) + 1;
int endIndex = response.indexOf(",", startIndex);
if (startIndex != -1 && endIndex != -1) {
String deviceName = response.substring(startIndex, endIndex);
Serial.print("Found device: ");
Serial.println(deviceName);
}
index = endIndex;
}
}