Hi Roman,
Sorry it does not support multiple connection between several peripherals BLE to a single CENTRAL one. But it can be done by a different way, I called it
Switching connection.
The basic idea and steps:
- Set the BLE devices to be CENTRAL( One ) or PERIPHERAL( others )
- Keep record the MAC address of the PERIPHERAL BLE from the first to the last one.
- Set the CENTRAL BLE with AT comands AT+CMODE=UNIQUE and AT+BIND=0x0017ea9397e1( NOTE: just an example of a BLE mac address) to bind the first BLE;
- After finishing the data transmission from the first one, then use AT command "AT+RESTART" to disconnect the LINK with the first BLE.
- Repeat the step3 to bind the second BLE device.
- Repeat the step4 ...
****till the last one and then go back to LINK with the first BLE device.
Btw, this post can help you to enter AT mode in code.
How do I know my Bluno is connected in code?*******Update********I had some spare time to finish the code, it worked. However, for the connection to link with another BLE requires some time, so the link just can not switch from one to another very quickly. I test with 10 seconds, it would be fine.
(104.94 KiB) Downloaded 1550 times
Here is the code:
NOTE: Once you entered AT mode using code "Serial.print("+++")", it won't print any info through serial port, i.e. the Serial.print("....") won't work.Code: Select all/*my Bluno Mega2560 0xC8A030FA0CEF;
my Romeo BLE 0x20CD3987C659
my bluno 0xD03972C4CF0F
my Bluno Mega1280 0xB4994C5C2E77
*/
char* peripheral[] = {"0xC8A030FA0CEF", "0x20CD3987C659", "0xD03972C4CF0F", "0xB4994C5C2E77"};
unsigned long previousMillis = 0;
const long interval = 15000; // interval at which to awitch the connection (milliseconds), at least 10 seconds
int linkTo = 0;
void setup() {
Serial.begin(115200);
pinMode(13, OUTPUT);
delay(100);
}
void loop() {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
atBind(peripheral[linkTo++]);
//control();
}
if (linkTo > 3) linkTo = 0;
}
void atBind(char* peripheralAdd) {
digitalWrite(13, HIGH);
Serial.println("AT+EXIT");
delay(100); //can't be omitted, same below
Serial.print("+++");// Enter AT mode of itself
delay(700); // 700 milliseconds MUST be added or AT ode not work
Serial.print("AT+BIND=");
Serial.println(peripheralAdd); delay(100);
Serial.println("AT+RESTART"); delay(100);
digitalWrite(13, LOW);
}
void control() {
for (int i = 0; i++; i < 2) {
Serial.write(1);
delay(500);
Serial.write(0);
delay(500);
}
}