Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BLE valueLength() on a peripheral is always returning 64 #575

Open
foxed-in opened this issue Sep 22, 2017 · 1 comment
Open

BLE valueLength() on a peripheral is always returning 64 #575

foxed-in opened this issue Sep 22, 2017 · 1 comment

Comments

@foxed-in
Copy link

With long writes from a device to the 101: I noticed that valueLength is always returning 64. It is necessary to get the correct length of data to keep from reading garbage at the end. I haven't seen any crashing though. I will attach the peripheral sketch used. I was using nRF connect to send text "0123456789". Ellisys shows "0123456789" in the traces.

This is the output from the serial terminal of the peripheral sketch that is reading the 10 characters sent from the phone.
value length: 64

value: 0123456789K?õßm÷çõðë·�–Pñß�ÿüÿ�ŸˆhÓ�

@foxed-in
Copy link
Author

#include <CurieBLE.h>
#include "CurieTimerOne.h"

#ifndef INTERVAL_TIMER
#define INTERVAL_TIMER 1000
#endif

static bool intervalFireOff = false;

BLEService CloudPrimaryService("bfe433cf-6b5e-4368-abab-b0a59666a402");
BLECharacteristic CloudCredentials("bfe433cf-6b5e-4368-abab-b0a59666a403", BLERead | BLEWrite, 64);
BLECharacteristic CloudNotify("bfe433cf-6b5e-4368-abab-b0a59666a404", BLERead | BLEWrite | BLENotify, 64);

void characteristicSubscribed(BLECentral& central, BLECharacteristic& characteristic) {
// characteristic subscribed event handler
//Serial.println(F("Characteristic event, subscribed"));
}

void characteristicUnsubscribed(BLECentral& central, BLECharacteristic& characteristic) {
// characteristic unsubscribed event handler
//Serial.println(F("Characteristic event, unsubscribed"));
}

void intervalTimerIsr() {
intervalFireOff = true;

}

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

Serial.println("REBOOT");

BLE.begin();
BLE.setLocalName("Test101");
BLE.setAdvertisedServiceUuid(CloudPrimaryService.uuid());
BLE.setDeviceName("Atmosphere Test");
// add service and characteristics

CloudPrimaryService.addCharacteristic(CloudCredentials);
CloudPrimaryService.addCharacteristic(CloudNotify);

BLE.addService(CloudPrimaryService);

CurieTimerOne.start(1000 * INTERVAL_TIMER, &intervalTimerIsr);
BLE.advertise();
}

void doIntervalCheck()
{
if(intervalFireOff)
{
intervalFireOff = false;
Serial.println("I'm alive!");
}
}

void loop() {
doIntervalCheck();

// poll peripheral
BLEDevice central = BLE.central();

if(central)
{
if(central.connected())
{
BLE.stopAdvertise();
while(central.connected())
{
doIntervalCheck();
if (CloudNotify.written())
{
const unsigned char *cvalue = CloudNotify.value();
Serial.print("value length: ");
Serial.println(CloudNotify.valueLength());
Serial.print("value: ");
Serial.println((char *)cvalue);
// Serial.print("Value: ");
// Serial.println(cvalue);
}
delay(5000);
}
BLE.advertise();
}
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant