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

Add new BLEStringCharacateristic type #5

Merged
merged 1 commit into from Dec 17, 2018

Conversation

sandeepmistry
Copy link
Contributor

Resolves #4.

Example usage sketch:

#include <ArduinoBLE.h>

BLEService stringService("19B10000-0001-537E-4F6C-D104768A1214"); // BLE String Service
BLEStringCharacteristic stringCharacteristic("19B10001-0001-537E-4F6C-D104768A1214", BLERead | BLEWrite, 512);

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

  // begin initialization
  if (!BLE.begin()) {
    Serial.println("starting BLE failed!");

    while (1);
  }

  // set advertised local name and service UUID:
  BLE.setLocalName("String");
  BLE.setAdvertisedService(stringService);

  // add the characteristic to the service
  stringService.addCharacteristic(stringCharacteristic);

  // add service
  BLE.addService(stringService);

  // set the initial value for the characeristic:
  stringCharacteristic.writeValue("hello");

  // start advertising
  BLE.advertise();

  Serial.println("BLE String Peripheral");
}

void loop() {
  // listen for BLE peripherals to connect:
  BLEDevice central = BLE.central();

  // if a central is connected to peripheral:
  if (central) {
    Serial.print("Connected to central: ");
    // print the central's MAC address:
    Serial.println(central.address());

    // while the central is still connected to peripheral:
    while (central.connected()) {
      if (stringCharacteristic.written()) {
        Serial.println("stringCharacteristic written, new value = ");

        String value = stringCharacteristic.value();

        Serial.println(value);
      }
    }

    // when the central disconnects, print it out:
    Serial.print(F("Disconnected from central: "));
    Serial.println(central.address());
  }
}

@agdl agdl merged commit 7d8b9ee into arduino-libraries:master Dec 17, 2018
@alex-taffe
Copy link

This seems to not be documented here yet

mmaciej2 pushed a commit to mmaciej2/ArduinoBLE that referenced this pull request Jan 22, 2022
@per1234
Copy link
Contributor

per1234 commented Feb 2, 2024

This seems to not be documented here yet

The deficiency is now tracked here: #349

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

Successfully merging this pull request may close these issues.

BLEStringCharacteristic
4 participants