Bluno General Arduino

Trying to Link to specific MACs and get a reply.

userHead fullauto2009 2018-07-13 05:50:44 3103 Views3 Replies
Im trying to have several BLE Links. Each attached to separate devices.

When any / all of the BLE Links come one, I want the Beetle to act to each Link, by flashing an LED.

The code basically filters through a set of MAC addresses placed in an array one by one.
It tries to BIND to the given MAC,
Send a RSSI request,
If there is a non zero return,

Slow blink the corresponding LED.

My problem is that, once I connect a Link.
I somehow still get return values after "Connecting" to a string that reads literally FakeMac as oppossed to a real MAC ie: 0x50658397CDC6

I have included many delays, many printouts to watch the serial monitor, which I have included a log of.
You can see right around connection loop 6, it starts getting an RSSI value even though the MAC is FakeMac1.
2022-02-28 01:39:42 Well this was the new method i have been trying since I got to know about it through https://bestwritingsclues.com/reviews/p ... om-review/ blogs. As I need to receive some payment for my works and this will be the best method to me. userHeadPic nekite6481
2018-07-13 05:51:45 Log:

Connection Attempt No:1
AT+EXIT
Begin AT Bind

Attempting to connect to MAC: 0x50658397CDC6
RSSI Value=0
Begin LED Output
End LED Output

Connection Attempt No:2
AT+EXIT
Begin AT Bind

Attempting to connect to MAC: FakeMac2
RSSI Value=0
Begin LED Output
End LED Output

Connection Attempt No:3
AT+EXIT
Begin AT Bind

Attempting to connect to MAC: FakeMac1
AT+BIND=FakeMac1
RSSI Value=0
Begin LED Output
End LED Output

Connection Attempt No:4
AT+EXIT
Begin AT Bind

Attempting to connect to MAC:
RSSI Value=0
Begin LED Output
End LED Output

Connection Attempt No:5
AT+EXIT
Begin AT Bind

Attempting to connect to MAC: 0x50658397CDC6
AT+BIND=0x50658397CDC6
RSSI Value=0
Begin LED Output
End LED Output

Connection Attempt No:6
AT+EXIT
Begin AT Bind

Attempting to connect to MAC: FakeMac2
RSSI Value=0
Begin LED Output
End LED Output

Connection Attempt No:7
AT+EXIT
Begin AT Bind

Attempting to connect to MAC: FakeMac1
RSSI Value=129
Begin LED Output
End LED Output

Connection Attempt No:8
AT+EXIT
Begin AT Bind

Attempting to connect to MAC:
RSSI Value=53
Begin LED Output
End LED Output

Connection Attempt No:9
AT+EXIT
Begin AT Bind

Attempting to connect to MAC: 0x50658397CDC6
RSSI Value=53
Begin LED Output
End LED Output

Connection Attempt No:10
AT+EXIT
Begin AT Bind

Attempting to connect to MAC: FakeMac2
RSSI Value=53
Begin LED Output
End LED Output

Connection Attempt No:11
AT+EXIT
Begin AT Bind

Attempting to connect to MAC: FakeMac1
RSSI Value=53
Begin LED Output
End LED Output
userHeadPic fullauto2009
2018-07-13 05:51:14 Code:


char* mac[] = {"0x50658397CDC6", "FakeMac2", "FakeMac1"}; //6 is the correct number, 5 is not. It should not connect on 2nd or 3rd element
unsigned long previousMillis = 0;
const long interval = 5000; // interval at which to awitch the connection (milliseconds), at least 10 seconds
int linkTo = 0; //MAC address variable
int LEDno = 0; //LED output variable
char Data[100];
char RAW[3]; // RSSI array
int INDEX;
char Value = '-'; //RSSI beginning character
int count = 1; //initialize cycle counter.

void setup() {
Serial.begin(115200);
pinMode(2,OUTPUT); //set port as OUTPUT
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(13, OUTPUT);
delay(100);


}

void loop() {

LEDno = linkTo +2;
unsigned long currentMillis = millis(); // get current time

if (currentMillis - previousMillis >= interval) { //Do this every 10 seconds
previousMillis = currentMillis; //Set last ttime ran

Serial.print("Connection Attempt No:"); // show cycle no.
Serial.println(count);

delay(50);

Bind(mac[linkTo++], LEDno);

delay(50);

if(linkTo > 3) linkTo = 0;
}
}

void Bind(char* Mac, int LEDno){
digitalWrite(13, HIGH);
delay(100);
Serial.println("AT+EXIT"); // Make sure we're out of AT MODE
delay(100);
Serial.println("Begin AT Bind");
Serial.println();
Serial.print("Attempting to connect to MAC: ");
Serial.println(Mac);
delay(100);
Serial.print("+++");// Enter AT mode of itself
delay(1000);
Serial.print("AT+BIND=");
Serial.println(Mac); // BIND to specific MAC
delay(1000);

Serial.println("AT+RSSI=?"); // Ask about the RSSI, Check connection to specified MAC
for(int x=0 ; Serial.available() > 0 ; x++ ){ // get the Enter AT mode words
delay(100); // Slow down for accuracy
Data[x] = Serial.read(); // Read and store Data Byte by Byte
delay(50);
if (Data[x] == Value ) // Look for the elemnt of the array that have "-" that's the start of the RSSI value
{
delay(50);
INDEX=x;
delay(50);
}
RAW[0] = Data[INDEX+1]; // Copy the RSSI value to RAW Char array
delay(50);
RAW[1] = Data[INDEX+2];
delay(50);
RAW[2] = Data[INDEX+3];
//RAW[3] = Data[INDEX+3];
}

delay(100);
Serial.println("AT+EXIT");
delay(100);
digitalWrite(13, LOW); //Get out of AT Mode

delay(100);
int RSSI = atoi(RAW); //Convert the Array to an integer
Serial.print("RSSI Value="); //Display RSSI
Serial.println(RSSI);

Serial.println("Begin LED Output");
if(RSSI != 0){ // If not connected it should be 0, If connected its non zero. 1 LED per MAC. Should blink LED 1, not LED 2 or 3.
digitalWrite(LEDno, HIGH);
delay(500);
digitalWrite(LEDno, LOW);
delay(500);
digitalWrite(LEDno, HIGH);
delay(500);
digitalWrite(LEDno, LOW);
delay(50);
RSSI = 0; //Reset RSSI just in case although as it restarts it should be rewritten anyway.
}
else{ // If RSSI is 0 aka no connection, rapid blink LED 1 to show no connection
digitalWrite(LEDno, HIGH);
delay(100);
digitalWrite(LEDno, LOW);
delay(100);
digitalWrite(LEDno, HIGH);
delay(100);
digitalWrite(LEDno, LOW);
}

delay(50);
Serial.println("End LED Output"); //Display showing end of function was reached.
Serial.println();
digitalWrite(13, LOW);
count++; //count inc
delay(1000);

}
userHeadPic fullauto2009