Skip to content

CurieBLE: add broadcast property to characteristic #420

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

Closed
don opened this issue Feb 1, 2017 · 8 comments
Closed

CurieBLE: add broadcast property to characteristic #420

don opened this issue Feb 1, 2017 · 8 comments
Assignees
Milestone

Comments

@don
Copy link

don commented Feb 1, 2017

I was porting some BLEPeripheral code to the Arduino 101 and noticed that BLEBroadcast is missing from CurieBLE.

screen shot 2017-01-30 at 11 14 56 pm

I'd like to be able to add the BLEBroadcast property to a Characteristic. setValue should update the advertising data when the characteristic's value changes.

@kitsunami kitsunami added this to the Deneb milestone Feb 1, 2017
@SidLeung
Copy link
Contributor

SidLeung commented Feb 1, 2017

Hi, Don:

I have not use the broadcast() API before in the previous library. However, I have used the BLENotify option in a Characteristic in one of my Peripheral sketches. To notify the connected Central for data ready, my sketch just need to use the setValue() API to set the local buffer with the data. The BLE library takes care of the notification process. There is no specific API to call to prompt the library to perform a notification. I would think the broadcast option to be similar.

@don
Copy link
Author

don commented Feb 2, 2017

@SidLeung BLENotify requires a connection between the client and the server.

BLEBroadcast allows me to send data without a connection. I created a demo sketch for you. I ran it on a RFduino, but it'll work on RedBear Nano or other boards supported by BLEPeripheral. The peripheral increments a counter and sets the characteristic value. Since the characteristic is marked as broadcast, the advertising data is updated whenever the value changes. This allows a my phone to get the counter value when scanning. I don't need to connect to get the data.

// Broadcast Characteristic Value
// Simple counter that broadcasts a value
#include <BLEPeripheral.h>

uint8_t value = 0;

BLEPeripheral peripheral;
BLEService service = BLEService("EEE0");
BLEShortCharacteristic characteristic = BLEShortCharacteristic("EEE1", BLERead | BLENotify | BLEBroadcast);

void setup() {
  Serial.begin(9600);

  peripheral.setLocalName("BLEBroadcast");
  peripheral.setAdvertisedServiceUuid(service.uuid());

  peripheral.addAttribute(service);
  peripheral.addAttribute(characteristic);

  characteristic.setValue(value);

  peripheral.begin();
  characteristic.broadcast();

  Serial.println(F("BLE Broadcast Count"));
}

void loop() {
    peripheral.poll();
    characteristic.setValue(value);    
    delay(1000);
    value++;
}

https://gist.github.com/don/536d9f1d605d9bfffcd99b5716a72cb4
eee0_framed

@SidLeung
Copy link
Contributor

SidLeung commented Feb 2, 2017

Have created a Jira ticket internally to look into BLE broadcasting in the 101 stack. Will post any result here.

@don
Copy link
Author

don commented Feb 2, 2017

@SidLeung thanks!

@sgbihu
Copy link
Contributor

sgbihu commented Feb 13, 2017

@don
I test your code on CurieBLE lib. Just change the include head file, the program can works.

Please change this line
#include <BLEPeripheral.h>
as
#include <CurieBLE.h>

The sketch can works.

@SidLeung
Copy link
Contributor

@don , is it possible to use your sketch as an example as part of the coreLibs release? If so, please add an licensing header and we will pull it into the next release. Thanks.

@calvinatintel
Copy link
Contributor

Hi @don. Thank you for your contribution. We love your sample code and have created a PR #437 with it. We need your written approval that we can include your code in our package, in the form of a software license. Arduino 101 CoreLibs is distributed under LGPLv2.1+ license and you can choose any software license that is compatible with LGPLv2.1+. According to Wikiepedia, it can be

  • Public domain
  • MIT / X11
  • BSD (revised)
  • Apache 2.0
  • or LGPL 2.1+ itself

Please let me know once you've decided on a license. I can help you apply it onto the code. Thank you.

@kitsunami kitsunami assigned don and unassigned SidLeung Feb 24, 2017
@ElliotMebane
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants