ble.serial()

Description

Initializes the serial service. The BLE serial service implements the Stream interface like the [hardware (USB) serial library](https://energia.nu/reference/serial/) does, so it’s used in the same manner. Note that an equivalent of Serial.begin() and Serial.end() are not needed or provided for BLE serial. If serial has not been enabled or there is no device connected with BLE, calls that read data will behave as if there is no data to read, and calls that write data will succeed, but nothing will transmit.

Syntax

ble.serial();

Parameters

Nothing

Returns

Example

    #include <BLE.h>

    void setup() {
      Serial.begin(115200);
      ble.begin();
      ble.serial();
      ble.setAdvertName("Energia Serial");
      ble.startAdvert();
    }

    void loop() {
      ble.handleEvents();
      if (Serial.available())
      {
        ble.print(Serial.readString());
      }
      if (ble.available())
      {
        /* All the Serial functions are available with BLE serial. */
        Serial.println(ble.readString());
      }
    }
Guide Home