int main(){ //pc.wait(1); gatt_characteristics[CHARACTERISTIC_LED] = new GattCharacteristic( nRF51_GATT_CHAR_LED, &gatt_char_value[CHARACTERISTIC_LED], 1, 1, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE); gatt_service = new GattService(nRF51_GATT_SERVICE, gatt_characteristics, CHARACTERISTIC_COUNT); //Initialize BLE Device ble.init(); ble.setDeviceName((uint8_t *)DEVICE_NAME); // configure our advertising type, payload and interval00 ble.accumulateAdvertisingPayload( GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE); ble.accumulateAdvertisingPayload( GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME)); ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); ble.setAdvertisingInterval(160); // 100ms /* led1.write(1); led3.write(1); led2.write(1); led4.write(1); */ for(int i=0; i<10; i++) pc.printf("Hello World\n"); ble.onConnection((Gap::ConnectionEventCallback_t)connectionCallback); ble.onDisconnection(disconnectionCallback); ble.gattServer().onDataWritten(onDataWritten); ble.addService(*gatt_service); ble.startAdvertising(); /* Adding below for scanning */ ble.setScanParams(500 /* scan interval */, 200 /* scan window */); ble.startScan(advertisementCallback); /**END OF PART FOR SCANNING**/ for (;;) { ble.waitForEvent(); } }
int main() { ble.init(); ble.onConnection(onConnection); ble.onDisconnection(onDisconnection); ble.onDataWritten(onDataWritten); ble.accumulateAdvertisingPayload( GapAdvertisingData::BREDR_NOT_SUPPORTED); ble.setAdvertisingType( GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); ble.accumulateAdvertisingPayload( GapAdvertisingData::SHORTENED_LOCAL_NAME, (const uint8_t *)NAME, sizeof(NAME) - 1); ble.accumulateAdvertisingPayload( GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS, (const uint8_t *)UARTServiceUUID_reversed, sizeof(UARTServiceUUID_reversed)); ble.accumulateScanResponse( GapAdvertisingData::SHORTENED_LOCAL_NAME, (const uint8_t *)NAME, sizeof(NAME) - 1); ble.accumulateScanResponse( GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS, (const uint8_t *)UARTServiceUUID_reversed, sizeof(UARTServiceUUID_reversed)); ble.setDeviceName((const uint8_t *)NAME); ble.setAdvertisingInterval(Gap::MSEC_TO_GAP_DURATION_UNITS(1000)); ble.startAdvertising(); UARTService uartService(ble); uartServicePtr = &uartService; while (true) { ble.waitForEvent(); } }