Writting string in à BLE caractéristiques using CurieBLE lib

Hello everyone,

I encounter a problem on an Arduino 101 communicating with a smartphone application, over BLE with CurieBLE library. I'm using several Services and typed Characteristics sucessfully, but for one of them, I need to exchange a data string (array of char) in both direction.

I could find how to write (from Arduino side) using the "BLECharacteristic()" method without type declaration, and adding a lenght parameter. Then I write using "setValue()" specifiyng the lenght. That is Ok.

But I tried several similar methods to perform the opposite operation : Reading a string from the Characteristic.... I couldn't find any solution to be able to compile without any error. I tried severai type declarations, pointer, ... nothing is right !

My problem is on Arduino side, not with smartphone application.

Do someone already experiment this and have the solution ??

Some code extracts :
unsigned char MyString[16] ;
BLECharacteristic MyChar("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", BLERead | BLEWrite,16);
MyChar.setValue(MyString,16) ;

Thank you in advance for your help.

My problem is on Arduino side, not with smartphone application.

Your problem is that you posted no code and no links to any libraries.

Hi,

Finally, my problem is solved !
I was extracting main lines codes from my application to post here, and had some ideas....
In fact, since Characterostics are only "unsigned char *" type when using for a string, it's obliged to cast variables used to write from or to.

Here is my simplified example.

//-------------------------------------------- Includes for BLE
#include <BLEAttribute.h>
#include <BLECentral.h>
#include <BLECharacteristic.h>
#include <BLECommon.h>
//#include <BLEDescriptor.h>
#include <BLEPeripheral.h>
#include <BLEService.h>
#include <BLETypedCharacteristic.h>
#include <BLETypedCharacteristics.h>
#include <BLEUuid.h>
#include <CurieBLE.h>

//----------------------------------------------------------- BLE declaring
BLEPeripheral blePeripheral;
BLEService InitAdmin("41300000-EB90-09D7-0001-413031360000");
BLECharacteristic Ssid("41300001-EB90-09D7-0001-413031360000", BLERead | BLEWrite,16);

//---------------------------------------------------------------------- Global Variables
int i;
char SsidLocal[32] ;

//----------------------------------------------------------------- Initialisation

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

// Set advertised local name and service UUID:
blePeripheral.setLocalName("ASE_A016");
blePeripheral.setDeviceName("ASE_A016");
blePeripheral.setAppearance(true);

// No visible service ?
//blePeripheral.setAdvertisedServiceUuid(InitAdmin.uuid());

// Add Service & Caracteristic
blePeripheral.addAttribute(InitAdmin);
blePeripheral.addAttribute(Ssid);

// Write into the SSID characteristic
sprintf(SsidLocal,"AZERTYUIOPQSDFGH");
Ssid.setValue((unsigned char *)SsidLocal,16) ; // Needs to cast because setValue accepts only unsigned char *

// begin advertising BLE service:
blePeripheral.begin();

Serial.println("A016 peripheral running...");
Serial.println("");

}

//----------------------------------------------------------------------- Main loop
void loop()
{
// listen for BLE peripherals to connect:
BLECentral central = blePeripheral.central();

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

// while the central is still connected to peripheral:
while (central.connected())
{
if (Ssid.written()) // le SSID
{
Serial.print("Admin : SSID recu ");
sprintf(SsidLocal,(char *)Ssid.value()); // Needs to cast because Value is unsigned char *
Serial.println(SsidLocal);
}
delay(250);
}

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

}
}

If this may help someone !

Regards.