is it possible to loop an AT Command??

hello everyone. I'm new here and a newbie in arduino programming.
i just want to ask you if is it possible to loop an AT Command. btw, i'm trying to get the RSSI of a HC-05 bluetooth module. i am trying to make the arduino to continuously ask the RSSI of HC05. i have 2 HC-05 module and i already set one to a master, and another one to slave. and also i already bind the master to the slave.
Now like i said, i want to continuously ask the arduino to send an AT command to the serial monitor, like "AT+INQ just to get the RSSI of HC 05.
is it possible? because i try to loop it in setup with for loop, but it wont work. i tried also to put it in void loop, yes it loops, but it is printing randoom character and not RSSI.
please help me, im a newbie.

here is my simple code.
i know maybe you'll notice some code that i don't know that is wrong. so please teach me. thank you very much.

#include<SoftwareSerial.h>
SoftwareSerial BTSerial(10, 11); //10 is Tx, 11 is Rx
void setup() {
  // put your setup code here, to run once:
  BTSerial.begin(38400);
  Serial.begin(38400); // opens the serial port
  Serial.println("Getting RSSI Value..."); //Prints value on to the serial monitor
 BTSerial.println("AT");
 delay(10);
 BTSerial.println("AT+INIT");
 delay(10);
 BTSerial.println("AT+INQ");
 delay(10);
}

void loop() {
  // put your main code here, to run repeatedly:


  if (BTSerial.available()) 
  {
    Serial.write(BTSerial.read()); // Keep reading from HC-05 and send to Arduino Serial Monitor

  }
  if (Serial.available())  //Get the number of bytes (characters) available for reading from the serial portx
  {
    BTSerial.write((Serial.read())); // Keep reading from Arduino Serial Monitor and send to HC-05

  }

}

Without bothering to look at your code, or considering the practicality of what you are trying to do, the answer is a conditional yes.

You cannot be in communications mode and AT mode at the same time, so all you need do is be able to switch between the two. This can be accomplished by controlling the power supply to HC-05 from within the loop, instead of directly from the 5v pin.

This is simply an answer to your stated question. It has nothing to do with your intentions, which will probably be futile, and possibly impossible. You may get better joy with a BLE device, which are better suited to this sort of stuff.

With some of my devices you need to send a string of +++++ before it pays attention to the AT command, not sure if that applies here.

What I would suggest that you do is try this using a sketch that copies between Serial and BTSerial (like a terminal program) and manually type commands to see what you need.

Nick_Pyner:
Without bothering to look at your code, or considering the practicality of what you are trying to do, the answer is a conditional yes.

You cannot be in communications mode and AT mode at the same time, so all you need do is be able to switch between the two. This can be accomplished by controlling the power supply to HC-05 from within the loop, instead of directly from the 5v pin.

This is simply an answer to your stated question. It has nothing to do with your intentions, which will probably be futile, and possibly impossible. You may get better joy with a BLE device, which are better suited to this sort of stuff.

oww. i just want to build 2 devices. device 1 with Arduino, HC05 master and a buzzer. and the device 2 is only a slave HC05 connected directly to a 5V power supply.
I just want to loop the "AT+INQ" command just to keep on scanning for the RSSI. then when I do it, I am planning to make a conditional loop that compare the RSSI strength of device 2(slave HC05). just like if the device 2 is getting far from device 1, then the RSSI is getting weak, then if it is detected that RSSI is getting week, the buzzer will triggered, to warn me that the device 2 is getting far.

that is what i am trying to do. that's why I'm asking how am i suppose to loop the AT command every 2 secs for example.

what do you think?? is it possible ?
is it easy to do? you see, I'm newbie here hoping have a clue with you guys to build this thing. :slight_smile:
please help me.
thank you very much.

I guess receive a warning through a buzzer is not the final purpose of your project.

If loosing the connection is acceptable another possability is master sends a few bytes
slave receives them and sends a acknowledge-byte
master waits for acknowledge-byte if it is not received within a timeout-time buzz

With this way you wouldn't have to change between command-mode and communication-mode.
Though it needs some programming work too with timeouts.

If you tell us the final purpose a better suited advice can be given.

best regards Stefan

StefanL38:
I guess receive a warning through a buzzer is not the final purpose of your project.

If loosing the connection is acceptable another possability is master sends a few bytes
slave receives them and sends a acknowledge-byte
master waits for acknowledge-byte if it is not received within a timeout-time buzz

With this way you wouldn't have to change between command-mode and communication-mode.
Though it needs some programming work too with timeouts.

If you tell us the final purpose a better suited advice can be given.

best regards Stefan

thanks stefan.
my final purpose of my project just put the 2nd device to the things that very important to us or expensive.

example, laptop, you will put the 2nd device to the bag of laptop, so if you suddenly forgot it somewhere. before you can get so far, you will be notified right away. so you can go back immediately for your laptop.
s it will be a anti theft also because if it suddenly get away to you, it will also notified by buzzer.

same with a mother and child. the mother can place the 2nd device to her child and the master is at her pocket. so if the mother go to Market with her child, it will prevent of having lost track of her child. because if her child suddenly went somewhere in the middle of shopping without consent of mother, the mother will notified right away.

that is my goal.
please help me.

Do you have any kind of democode that shows how communication with the bluetoothmodule works?

You should provide a datasheet and or a usermanual of your bluetooth module and the microcontroller that you are using.

How much knowledge do you have about programming?
Just a rough estimation or a desciption of your most complex project you have done.

Best regards Stefan

StefanL38:
Do you have any kind of democode that shows how communication with the bluetoothmodule works?

You should provide a datasheet and or a usermanual of your bluetooth module and the microcontroller that you are using.

How much knowledge do you have about programming?
Just a rough estimation or a desciption of your most complex project you have done.

Best regards Stefan

hmm. to be Honest, I'm a newbie here in Arduino programming.
I'm just started studying programming and not an expert yet.
in other programming language I know C++ but not expert, maybe i know roughly 65 - 75% and other one is HTML and I am planning to continue in CSS. I am just studying online tutorials.

but now I am newbie in Arduino Programming. and about my last C++ program did is, C++ program that will compute a math problem about finding unknowns of an equation via Matrix program.

btw, about bluetooth communication, i just search it in google how to use it.
but base on my searched,
first you need to set one to master and one to slave. and you can set it by typing an AT Commands in serial monitor.
like this ff command: example
AT+BIND= Bluetooth address - to set the master to only connect to that address.
AT+ROLE=1 - to set it a Master and 0 if slave.
AT+INQM - to set Search Parameters.
AT+INQ - to start searching devices and its signal strength. and this one is i am trying to loop. to scan continuously.

so I made a program that automatically send AT commands that I want to send to serial monitor.
and it works.
but i am having a problem on coding the AT commands especially "AT+INQ" to run continuously.

few hours ago I tried this program. my logic is start the setup and print the RSSI automatically.
then i put "return 0" just like in C++ to end the current program and put again setup(); to start again from the start.
at first try, it went well and work the way i wanted. but when I restart again the arduino, it wont work agian and again. i wonder why.

here is my code again.

#include<SoftwareSerial.h>
SoftwareSerial BTSerial(10, 11); //10 is Tx, 11 is Rx

void setup() {
// put your setup code here, to run once:
Serial.begin(38400); // opens the serial port
BTSerial.begin(38400);
Serial.println("Getting RSSI...");
BTSerial.println("AT"); //testing AT Command
delay(10);
BTSerial.println("AT+INIT");
delay(10);
for(int x=0;x<2;x++){
BTSerial.println("AT+INQ"); //getting RSSI of slave HC05
delay(1000);}
return 0;
setup(); //restart setup

}

void loop() {
// put your main code here, to run repeatedly:

if (BTSerial.available())
{
Serial.write(BTSerial.read()); // Keep reading from HC-05 and send to Arduino Serial Monitor

}
if (Serial.available()) //Get the number of bytes (characters) available for reading from the serial portx
{
BTSerial.write((Serial.read())); // Keep reading from Arduino Serial Monitor and send to HC-05

}

}

StefanL38:
I guess receive a warning through a buzzer is not the final purpose of your project.

If loosing the connection is acceptable another possability is master sends a few bytes
slave receives them and sends a acknowledge-byte
master waits for acknowledge-byte if it is not received within a timeout-time buzz

With this way you wouldn't have to change between command-mode and communication-mode.
Though it needs some programming work too with timeouts.

If you tell us the final purpose a better suited advice can be given.

best regards Stefan

Stefan. I think i will try this method.
Because measuring signal strength continously is complicated. With this method i will try to measure the time byte flight. With a set time and the acknowledge byte did not receive by master, buzzer triggered.
I hope it works.
Thanks guys.