Skip to content
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

Added setValue for strings #210

Closed
wants to merge 0 commits into from
Closed

Added setValue for strings #210

wants to merge 0 commits into from

Conversation

agdl
Copy link
Member

@agdl agdl commented Jun 10, 2016

This fix allows to use setValue() for const char* variables

@kitsunami kitsunami added this to the Castor milestone Jun 13, 2016
@kitsunami
Copy link

Can you provide the context for this?

@agdl
Copy link
Member Author

agdl commented Jun 14, 2016

Yes of course:

BLECharacteristic stringCharacteristic("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", BLERead | BLEWrite | BLENotify, MAX_LENGTH);
...
...
...
void myTestFunction(){
  char testString[] = "This is a test";
  stringCharacteristic.setValue(testString);
}

or something like:

BLECharacteristic stringCharacteristic("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", BLERead | BLEWrite | BLENotify, MAX_LENGTH);
...
...
...
void myTestFunction(){
 String testString = "Value is: " + thisValue;
  stringCharacteristic.setValue(testString.c_str());
}

@SidLeung
Copy link
Contributor

The BLE library is undergo improvement. Will add in this change as part of the modification. Please note that "notification" is limited to 20 byte long. If the string you are sending out is longer than 20 byte, you may have to send it out in 20 byte segments. In that case, you can consider using an index pointer to walk down the string and specify the segment size for each setValue() call. You definitely do not want to just call setValue( myLongString );

@eriknyquist
Copy link
Contributor

The change looks fine to me, but I'm not sure if it's a necessary one. @SidLeung the BLE master what do you think?

@sandeepmistry
Copy link
Contributor

This is one of the API's that I forgot to port from BLEPeripheral. It makes it much nicer for setting a string value for the characteristic vs characteristic.setValue(str, strlen(str)). @agdl noticed it and created this PR to port it over.

More info. at: https://github.com/sandeepmistry/arduino-BLEPeripheral/blob/master/API.md#set-value

@kitsunami kitsunami modified the milestones: Deneb, Castor Aug 22, 2016
SidLeung added a commit to SidLeung/corelibs-arduino101 that referenced this pull request Mar 2, 2017
Feature added:
  - This is directly pulled from Arduino community PR arduino#210.
    Overloading the setValue() method to take in a string
    as the only input parameter, instead of a pointer
    and its size.
@SidLeung
Copy link
Contributor

SidLeung commented Mar 3, 2017

PR #461 addresses this issue. Will be in the next release. Please review and close.

@SidLeung SidLeung assigned agdl and unassigned SidLeung Mar 3, 2017
@agdl agdl closed this Mar 30, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants