Communicate with mobile phone using hm-10 as master

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;
  }
}

I moved your topic to an appropriate forum category @12doctorpep .

In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.

This is an important part of responsible forum usage, as explained in the "How to get the best out of this forum" guide. The guide contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

1 Like

I think you should change that to always, and there lies the problem.

There is a command to change the master and slave roles in HM-10,

and can advertising in android phone.

Isn't the opposite also possible?

Incoherent.

If you wish to communicate with a phone using HM-10 as a master, all you need do is configure the phone as a slave.

And while you are at it, you should ensure that AT+DISC is a kosher command for your HM-10. . Although the official documentation lists many commands, not all of them are supported by all versions, the most common version supports very few, and this is one it doesn't. The only (presumably) full bottle HM-10 I know of is that by TinySine