Author Topic: How to check if bluetooth in connect  (Read 695 times)

tmsio

  • RFduino Jr. Member
  • **
  • Posts: 35
  • Karma: +0/-0
    • View Profile
How to check if bluetooth in connect
« on: December 26, 2016, 09:44:01 AM »
Hi, wich is the way for checking if rfduino in connect to a device?
Im using lazarus library and it work fine.... but i want to prevent rfduino sleep mode when the phone is connect to the module.
Thank you.

Regards

tolson

  • Global Moderator
  • *****
  • Posts: 859
  • Karma: +20/-0
    • View Profile
    • Thomas Olson Consulting
Re: How to check if bluetooth in connect
« Reply #1 on: December 26, 2016, 09:56:12 AM »
Perhaps set a flag in onConnect to indicate phone is connected.
And reset that flag in onDisconnect.
Then just test that flag in your other routines.

Assumption: what if once connected the phone moves out of range.
Hopefully the onDisconnect gets called when it realizes the phone went out of range.
Please test the idea.


tmsio

  • RFduino Jr. Member
  • **
  • Posts: 35
  • Karma: +0/-0
    • View Profile
Re: How to check if bluetooth in connect
« Reply #2 on: December 26, 2016, 11:00:24 AM »
Done!!
Thank you!!
The code is similar to this...

Code: [Select]
#include <RFduinoBLE.h>

bool isconnected = false;

void setup() {
  // setup the leds for output
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT); 
  pinMode(led3, OUTPUT);

  RFduinoBLE.advertisementData = ‚ÄúTest";
  RFduinoBLE.deviceName ="Amigo";
 
  // start the BLE stack
  RFduinoBLE.begin();
}

void loop() {
  // switch to lower power mode
  RFduino_ULPDelay(INFINITE);
  if (isconnected){
  delay(3000);
  RFduinoBLE.send('hello');
  } 
}

void RFduinoBLE_onConnect() {
  isconnected = true;
}

void RFduinoBLE_onDisconnect() {
isconnected = false;
}