Skip to content

Set Bluefruit LE advertising interval #422

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions examples/StandardFirmataBLE/StandardFirmataBLE.ino
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,10 @@ void setup()

stream.setLocalName(FIRMATA_BLE_LOCAL_NAME);

#ifdef FIRMATA_BLE_ADVERTISING_INTERVAL
// set the BLE advertising interval
stream.setAdvertisingInterval(FIRMATA_BLE_ADVERTISING_INTERVAL);
#endif
// set the BLE connection interval - this is the fastest interval you can read inputs
stream.setConnectionInterval(FIRMATA_BLE_MIN_INTERVAL, FIRMATA_BLE_MAX_INTERVAL);
// set how often the BLE TX buffer is flushed (if not full)
Expand Down
3 changes: 3 additions & 0 deletions examples/StandardFirmataBLE/bleConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@
//#define BLUEFRUIT_LE_SPI

#ifdef BLUEFRUIT_LE_SPI
// Value must be between 20ms and 10.24s
#define FIRMATA_BLE_ADVERTISING_INTERVAL 20 // 20ms

// Both values must be between 10ms and 4s
#define FIRMATA_BLE_MIN_INTERVAL 15 // 15ms
#define FIRMATA_BLE_MAX_INTERVAL 30 // 30ms
Expand Down
26 changes: 18 additions & 8 deletions utility/BluefruitLE_SPI_Stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class BluefruitLE_SPI_Stream : public Stream
BluefruitLE_SPI_Stream(int8_t csPin, int8_t irqPin, int8_t rstPin);

void setLocalName(const char *localName);
void setAdvertisingInterval(unsigned short advertisingInterval);
void setConnectionInterval(unsigned short minConnInterval, unsigned short maxConnInterval);
void setFlushInterval(int flushInterval);

Expand All @@ -38,6 +39,7 @@ class BluefruitLE_SPI_Stream : public Stream
Adafruit_BluefruitLE_SPI ble;

String localName;
unsigned short advertisingInterval;
unsigned short minConnInterval;
unsigned short maxConnInterval;

Expand All @@ -48,6 +50,7 @@ class BluefruitLE_SPI_Stream : public Stream

BluefruitLE_SPI_Stream::BluefruitLE_SPI_Stream(int8_t csPin, int8_t irqPin, int8_t rstPin) :
ble(csPin, irqPin, rstPin),
advertisingInterval(0),
minConnInterval(0),
maxConnInterval(0),
txCount(0)
Expand All @@ -58,6 +61,11 @@ void BluefruitLE_SPI_Stream::setLocalName(const char *localName)
this->localName = localName;
}

void BluefruitLE_SPI_Stream::setAdvertisingInterval(unsigned short advertisingInterval)
{
this->advertisingInterval = advertisingInterval;
}

void BluefruitLE_SPI_Stream::setConnectionInterval(unsigned short minConnInterval, unsigned short maxConnInterval)
{
this->minConnInterval = minConnInterval;
Expand Down Expand Up @@ -89,14 +97,16 @@ void BluefruitLE_SPI_Stream::begin()
ble.println(localName);
}

// Set connection interval
if (minConnInterval > 0 && maxConnInterval > 0) {
ble.print("AT+GAPINTERVALS=");
ble.print(minConnInterval);
ble.print(",");
ble.print(maxConnInterval);
ble.println(",,,");
}
// Set connection and advertising intervals
ble.print("AT+GAPINTERVALS=");
if (minConnInterval > 0) ble.print(minConnInterval);
ble.print(",");
if (maxConnInterval > 0) ble.print(maxConnInterval);
ble.print(",");
if (advertisingInterval > 0) ble.print(advertisingInterval);
ble.print(",,"); // Always omit fast advertising timeout, hence two commas
if (advertisingInterval > 0) ble.print(advertisingInterval);
ble.println();

// Disable real and simulated mode switch (i.e. "+++") command
ble.println("AT+MODESWITCHEN=local,0");
Expand Down