Help in code needed

I am using this code to send AT commands using HC-05 to calculate RSSI value :

#include <SoftwareSerial.h>

SoftwareSerial BTSerial(12, 13);
void command(const char *toSend, unsigned long milliseconds) {
  String result;
  Serial.print("Sending: ");
  Serial.println(toSend);
  BTSerial.println(toSend);
  unsigned long startTime = millis();
  Serial.print("Received: ");
  while (millis() - startTime < milliseconds) {
    if (BTSerial.available()) {
      char c = BTSerial.read();
      Serial.write(c);
      result += c;  // append to the result string
    }
  }
Serial.println(result);  // new line after timeout.
}
void setup(){
  Serial.begin(9600);
  BTSerial.begin(38400);
  command("AT+INQM=1,9,48\r\n", 48);
  //command("AT+INQ", 48);
  }
void loop(){}

I picked this function "command" from https://forum.arduino.cc/t/sending-at-commands-via-code/334031/3
but I am not receiving anything. pls help.

I also tried variations like "at+inqm=1,9,48\r\n" and "AT+INQM=1,9,48"
It's still not working

what is the device the code is communicating with and is there a datasheet for it?

I am using HC-05 to calculate the rssi value of my phone's bluetooth

what are the AT commands?

yeah so for calculating rssi value, I use the following AT commands:

  1. AT+INQM=1,9,48

  2. AT+INQ

These commands work when I type each in the serial monitor.
So currently I am trying to send the former through a code and expect to receive an OK from HC-05 which I am not getting.

is 48 msec long enough

yeah it works well when i put in serial monitor
should i try to increase this time?
Then what time do u suggest?

isn't 48 the amount of time your code waits for a response?

48 may also be the time you specify in the command for it to make a measurement over

so what change do u recommend

how is the response terminated? \n?

I don't know properly what it does, but I have seen people suggesting to end AT commands with \r\n.
\n is i guess for new line
\r is something called carriage return which I dont understand

on older teletypes, a new line, \n, rotated the carriage up one line and a carriage return, \r, moved the print head back to the left most column.

i'm asking what the device sends as the last character in its response.

why not wait for that character to be received instead of waiting a limited amount of time (48 msec)?

do u suggest to increase the time signicantly, so as to get the required the required answer, say 1000 or 2000 milliseconds?

no, i'm suggesting you wait to receive the termination character in the response

btw I tried this it returned "ERROR:[0]"
Atleast it returned something

yeah generally i wait for 1-2 minutes but receive nothing

suggesting

    while (true)  {
        if (BTSerial.available()) {
            char c = BTSerial.read();
            Serial.write(c);
            result += c;  // append to the result string

            if ('\n' == c)
                break;
        }
    }


didn't work :frowning:

what didn't work?

waiting to received a complete response from the device by waiting for a termination character instead of waiting a fixed amount of time (48 msec) or that your request failed and the device reported an ERROR?