I want to find out what devices are around me and say hello to each person around.
[SOLVED] Before saying hello, I do not understand what the error means:
request for member 'indexOf' in 'bt', which is of non-class type 'int'
string bt=0; // list of bt devices
void setup() {
Serial.begin(9600); // initializes serial communication at 9600 bits per second
Serial.print("AT+JDDS=0"); // search for devices
}
void loop() {
if(Serial.available() > 0){
bt = Serial.read();
if (bt.indexOf("device1") > 0){
"hello 1"}
}
EDIT 1: After solving the "int" problem and thinking I need to use AT mode, the question becomes:
How do I use AT mode to tell arduino what devices are nearby?
After I resolve this part I will play a sound saying Hello to each person.
The problem, I guess, is that "Serial.print("AT+JDDS=0");" will not do a search.
The first arduino code I ever managed to get working still works with this HC05, I can command arduino by phone.
I was trying to do something like so for the second project I ever tried to get working:
#include <SoftwareSerial.h>
SoftwareSerial mySerial(0,1); //RX,TX
int flag=0; // makes sure that the serial only prints once the state
String bt; // list of bt devices
void setup() {
pinMode(5, OUTPUT); // sets the pin as output
digitalWrite(5, LOW);
Serial.begin(9600);
mySerial.begin(9600);
delay(1000);
// long b=mySerial.read(); some comands from an example
// mySerial.println("AT+CIPMUX=1");
// b=mySerial.read();
// Serial.write(bt);
// delay(100);
// b="";
}
void loop() {
// search for devices, I don't know which is better from the two next lines
mySerial.println("AT+JDDS=0");
mySerial.write("AT+INQ/r/n");
if(Serial.available() > 0){
byte bt = mySerial.read();
flag=0;
if (bt.indexOf("device1") > 0){
digitalWrite(5, HIGH);
}
}
}//end void