void setup() {
  wait_for_serial();

  // set the local name peripheral advertises
  blePeripheral.setLocalName("Initial");
  // set the UUID for the service this peripheral advertises:
  blePeripheral.setAdvertisedServiceUuid(whistlepunkService.uuid());

  // add service and characteristics
  blePeripheral.addAttribute(whistlepunkService);
  blePeripheral.addAttribute(valueCharacteristic);
  blePeripheral.addAttribute(configCharacteristic);
  blePeripheral.addAttribute(versionCharacteristic);
  versionCharacteristic.setValue(version);

  // assign event handlers for connected, disconnected to peripheral
  blePeripheral.setEventHandler(BLEConnected, blePeripheralConnectHandler);
  blePeripheral.setEventHandler(BLEDisconnected, blePeripheralDisconnectHandler);
  valueCharacteristic.setEventHandler(BLESubscribed, bleNotificationSubscribeHandler);
  valueCharacteristic.setEventHandler(BLEUnsubscribed, bleNotificationUnsubscribeHandler);
  configCharacteristic.setEventHandler(BLEWritten, bleConfigChangeHandler);

  ble_addr_t _local_bda;
  char       _device_name[BLE_MAX_DEVICE_NAME+1];
  ble_client_get_factory_config(&_local_bda, _device_name);
  sprintf(BleLongName, "Sci%02x%02x", _local_bda.addr[0], _local_bda.addr[1]);
  DEBUG_PRINT("Address is: ");
  DEBUG_PRINTLN(BleLongName);
  blePeripheral.setLocalName(BleLongName);

  // advertise the service
  blePeripheral.begin();
}
Exemplo n.º 2
0
BLEPeripheral::BLEPeripheral(void) :
    _state(BLE_PERIPH_STATE_NOT_READY),
    _advertise_service_uuid(NULL),
    _local_name(NULL),
    _service_data_uuid(NULL),
    _service_data(NULL),
    _service_data_length(0),
    _appearance(0),
    _min_conn_interval(DEFAULT_MIN_CONN_INTERVAL),
    _max_conn_interval(DEFAULT_MAX_CONN_INTERVAL),
    _central(this),
    _attributes(NULL),
    _num_attributes(0),
    _last_added_characteritic(NULL)
{
    memset(_event_handlers, 0x00, sizeof(_event_handlers));

    ble_client_get_factory_config(&_local_bda, _device_name);
}