by djh_83 Sat Mar 21, 2015 1:37 pm
Hi,

I connect to the bluno with my iphone app over blue tooth. When I connect, a little led turns on, on the board and I can now send and receive bytes over Bluetooth. I'd like to know from within the bluno program that I am now connected with a device. The reason being is to only start sending serial data after a successful connection with the smart phone.

Thanks
by tiojoca Thu Apr 30, 2015 11:38 am
I ended up solving this using a totally different approach. I set the board to AT mode and use the AT+RSSI=? command to get the RSSI which will always be -000 if Bluno is not connected to a BT device. An example implementation of this solution:

[code]
const int ledBLE = 13;
typedef enum {START, WAIT_AT, WAIT_RSSI, WAIT_EXIT, NORM_MODE, _TMP} state_type;
state_type state = START;
char chr;
String buffer, rssi, data;
bool reading = false;

void setup() {
Serial.begin(115200); //Initiate the Serial comm
pinMode(ledBLE, OUTPUT);
state = START;
}

void loop() {
if (state == START) {
start();
} else if (state == WAIT_AT) {
wait_at();
} else if (state == WAIT_RSSI) {
wait_rssi();
} else if (state == WAIT_EXIT) {
wait_exit();
} else if (state == NORM_MODE) {
norm_mode();
}
}

void start() {
delay(10);
Serial.print("+");
Serial.print("+");
Serial.print("+");
data = "";
state = WAIT_AT;
}

void wait_at() {
while (Serial.available() > 0) {
chr = Serial.read();
if (chr == 'E') {
reading = true;
buffer = "";
}
if (reading) {
buffer += chr;
} else {
data += chr;
}
if (reading && buffer == "Enter AT Mode\r\n") {
Serial.println("AT+RSSI=?");
reading = false;
state = WAIT_RSSI;
} else if (data == "led_on") {
digitalWrite(ledBLE, HIGH);
data = "";
} else if (data == "led_off") {
digitalWrite(ledBLE, LOW);
data = "";
}
}
}

void wait_rssi() {
while (Serial.available() > 0) {
chr = Serial.read();
if (chr == '-') {
reading = true;
buffer = "";
}
if (reading) {
buffer += chr;
}
if (buffer.length() == 4) {
rssi = buffer;
Serial.println("AT+EXIT");
reading = false;
state = WAIT_EXIT;
if (rssi == "-000") {
digitalWrite(ledBLE, LOW);
}
}
}
}

void wait_exit() {
while (Serial.available() > 0) {
chr = Serial.read();
if (chr == 'O') {
reading = true;
buffer = "";
}
if (reading) {
buffer += chr;
}
if (buffer == "OK\r\n") {
reading = false;
state = NORM_MODE;
}
}
}

void norm_mode() {
Serial.println("\r\n<<<");
Serial.println(rssi);
Serial.println(">>>\r\n");
Serial.flush();
state = START;
}
[/code]

Not sure this is the best way to do it, though. I'm not very comfortable with using Serial for all the different inputs/outputs of different sources: executing AT commands and getting their results, getting data from BT, and outputting data back to USB.

Does anyone have a better suggestion on how to do this?
by timjanwall Thu Jul 14, 2016 12:08 pm
I think Leff ment i2c and i looking for the same solution as tiojoca, i will try dig in to how to get to the CC2540 with i2c. If you find enything usefull post here or pm :)

Who is online

Users browsing this forum: No registered users and 9 guests

cron