Closed Skizy closed 1 year ago
Please use Arc::clone
.
See https://doc.rust-lang.org/book/ch16-03-shared-state.html#atomic-reference-counting-with-arct for details.
If it still doesn't work, please paste the source code.
Something like this for example does not compile. BLECharacteristic doesn't implement Sync and Send because Vec
use esp32_nimble::*;
use std::sync::Arc;
let ble_dev = BLEDevice::take();
let server = ble_dev.get_server();
let service = server.create_service(utilities::BleUuid::from_uuid16(9234u16));
let notify_characteristic = service.lock().create_characteristic(
utilities::BleUuid::from_uuid16(1642u16),
NimbleProperties::NOTIFY | NimbleProperties::READ,
);
notify_characteristic.lock().set_value(&[125]);
let char_clone = Arc::clone(¬ify_characteristic);
std::thread::spawn(move || {
char_clone.lock().notify();
});
Sorry for the lack of confirmation.
I marked BLECharacteristic
as Send
.
This change should resolve the issue.
Thanks a lot! You should also mark BLEService
as Send
, as it has the same problem.
Hey, I was trying to create a separate thread to send notifications as a server, but was unable to, because BLECharacteristic is not Send and not Sync. Hence I have a question: what is the point of wrapping characteristics in Arc Mutex if you can't share them between threads?