Skip to content

(support) Cannot write to BLE characteristic with vector #369

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

Closed
MaxMyzer opened this issue Oct 1, 2024 · 3 comments
Closed

(support) Cannot write to BLE characteristic with vector #369

MaxMyzer opened this issue Oct 1, 2024 · 3 comments
Assignees
Labels
type: support OT: Request for help using the project

Comments

@MaxMyzer
Copy link

MaxMyzer commented Oct 1, 2024

System: ESP32 C3
ArduinoBLE 1.3.7

I have a system where I would like to write and read from another device. I am currently using nRF Connect to test functionality.

When I check if I canWrite, it always returns false - if I do anyway, it only seems to work for a 0 value.

I have created a sketch to demonstrate my issue:

#include <Arduino.h>
#include <ArduinoBLE.h>
#include <float16.h>
#include <vector>
void setup() {
  Serial.begin(115200);  // [DEBUG] start serial w/ Baud 115200
  while (!Serial.available())
    ;  // [DEBUG] wait for serial to connect...

  Serial.println("Initializing BLE service");
  BLEService* service = new BLEService("1810");
  BLETypedCharacteristic<std::vector<char>>* characteristic = new BLETypedCharacteristic<std::vector<char>>("2A35", BLERead | BLENotify | BLEIndicate | BLEWriteWithoutResponse | BLEWrite);
  BLEDescriptor* descriptor = new BLEDescriptor("2901", "test_descriptor");
  BLELocalDevice* device = new BLELocalDevice();
  if (device->begin()) Serial.println("BLE device started");
  else Serial.println("BLE device failed to start");
  if (device->setLocalName("test_name")) Serial.println("BLE name set");
  else Serial.println("BLE name failed to set");
  device->setDeviceName("test_name");
  if (device->setAdvertisedService(*service)) Serial.println("BLE service advertised");
  else Serial.println("BLE service failed to advertise");
  device->setEventHandler(BLEConnected, ([](BLEDevice central) {
                            Serial.printf("Connected to %s\n", central.address().c_str());
                          }));
  device->setEventHandler(BLEDisconnected, ([](BLEDevice central) {
                            Serial.println("Disconnected");
                          }));
  characteristic->addDescriptor(*descriptor);
  service->addCharacteristic(*characteristic);
  device->addService(*service);
  device->advertise();

  Serial.println("BLE service started");
  Serial.println("trying to write:");
  std::vector<char> data = { 0x04, 0x50, 0x54, (char)0x90, 0x5E, 0x40, 0x4D, 0x00, 0x55 };
  if (characteristic->canWrite()) characteristic->writeValue(data);
  else Serial.println("Cannot write to characteristic");


  Serial.print("done");
  exit(0);
}
void loop() {}

I am not quite sure what it is I am doing wrong, any help would be appreciated.

@MaxMyzer
Copy link
Author

MaxMyzer commented Oct 1, 2024

A quick update, with a string, I can actually write, but canWrite still returns false

@per1234 per1234 self-assigned this Oct 5, 2024
@per1234 per1234 added the type: support OT: Request for help using the project label Oct 5, 2024
@per1234
Copy link
Contributor

per1234 commented Oct 5, 2024

Hi @MaxMyzer. Thanks for your interest in this open source project. This issue tracker is only to be used to report bugs or feature requests specific to the project. This topic is more appropriate for the Arduino Forum. I'm sure we will be able to help you out over there:

https://forum.arduino.cc/

@per1234 per1234 closed this as not planned Won't fix, can't repro, duplicate, stale Oct 5, 2024
@MaxMyzer
Copy link
Author

MaxMyzer commented Oct 5, 2024

I have created a forum topic (in case anyone else has this issue) here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: support OT: Request for help using the project
Projects
None yet
Development

No branches or pull requests

2 participants