How do you avoid "trying to issue command mid state"?
Opened this issue · 0 comments
NSExceptional commented
(This is an API usage question, not a bug report or anything)
So I want to do this:
- Scan for characteristics
- Set characteristic A to notify
- Write value to characteristic B
When I try to do the last step, I run into this error. I'm doing those two steps inside the setup_standard_scan
callback as I find each characteristic. What should I do instead? Loop on is_idle()
inside the callback before I write...?
Here is my (pseudo)code:
BLEGATTStateMachine gatt;
std::function<void(const PDUNotificationOrIndication&)> notifyCallback =
[&](const PDUNotificationOrIndication& n) {
// ...
};
std::function<void()> servicesAndCharsCallback = [&gatt, ¬ifyCallback]() {
for (auto& service: gatt.primary_services) {
for (auto& chara: service.characteristics) {
if (chara.uuid == UUID("ABCD")) {
chara.cb_notify_or_indicate = notifyCallback;
chara.set_notify_and_indicate(true, false);
}
else if (chara.uuid == UUID("WXYZ")) {
uint8_t buffer[5];
// ...
chara.write_command(buffer);
}
}
}
};
gatt.setup_standard_scan(servicesAndCharsCallback);
gatt.connect_blocking("myaddress");
for (;;) {
gatt.read_and_process_next();
}
Thanks in advance for taking the time to help if you do :)