Hello,
I'm trying to achieve a very task:
Read a string via BLE, write it to the Serial connection (my pc in this example), and then write a new string ("TEST") to BLE.
I'm using my phone's BLE via terminal apps to achieve it (Serial Bluetooth & BleTerm). The issue is that unlike other devices, the Write & Read characteristics are not set by default, so in order to create a terminal connection, I'm asked to either pick one, or write it manually.
Screenshot from my phone:
How can I set these characteristics by default like other BLE devices are behaving?
My Code:
/*
* Copyright (c) 2016 Intel Corporation. All rights reserved.
* See the bottom of this file for the license terms.
*/
#include <CurieBLE.h>
//----------------------------------------------------------- BLE declaring
BLEPeripheral blePeripheral;
BLEService InitAdmin("41300000-EB90-09D7-0001-413031360000");
BLECharacteristic ATTOBLE("41300001-EB90-09D7-0001-413031360000", BLERead | BLEWrite | BLENotify,16);
//---------------------------------------------------------------------- Global Variables
char BLEString[32] ;
//----------------------------------------------------------------- Initialisation
void setup()
{
Serial.begin(9600);
// Set advertised local name and service UUID:
blePeripheral.setLocalName("ATTO BLE");
// Add Service & Caracteristic
blePeripheral.addAttribute(InitAdmin);
blePeripheral.addAttribute(ATTOBLE);
// BLE Events
ATTOBLE.setEventHandler(BLEWritten, switchCharacteristicWritten);
// begin advertising BLE service:
blePeripheral.begin();
}
void loop()
{
blePeripheral.poll();
}
void switchCharacteristicWritten(BLEDevice central, BLECharacteristic characteristic) {
sprintf(BLEString,"%16c",NULL);
strncpy(BLEString,(char*)ATTOBLE.value(),ATTOBLE.valueLength());
Serial.println(BLEString);
ATTOBLE.setValue("TEST");
}