Open weeteniz opened 7 years ago
OK, I've done a bit more digging and experimenting and I think the issue might be either my controller (Blend Micro) or the BLEPeripheral library.
I also posted my original post on Homebridge-Bluetooth repo here.
I got a response from the developer of the repo saying my code looked fine but got a suggestion to simply put the characteristic.setValue
methods inside the loop()
method as the developer has done with several of his code examples that work.
I've done that but again, had no luck. The Homebridge-Bluetooth developer said it was very strange that my rewritten code doesn't work.
Since then I decided to rewrite my code to capture the results of characteristic.setValue()
and characteristic.canNotify()
methods. The relevant bit of the code now looks like this:
void loop() {
ble.poll();
if (targetUpdate != false) {
if (positionStateCharacteristic.canNotify() != 0) { //code enters the block which means canNotify returns 'true'
unsigned char state = 2;
bool stateSet = positionStateCharacteristic.setValue(state); //capture success/failure of setValue() notification
Serial.print("Current state set? ");
Serial.println(stateSet); //serial returns 0 which means setValue notification fails
Serial.println(" to: ");
Serial.println(positionStateCharacteristic.value());
};
unsigned char newTarget = targetPositionCharacteristic.value();
bool notifiable = currentPositionCharacteristic.canNotify(); //returns 'true'
Serial.print("Can notify? ");
Serial.println(notifiable);
bool changed = currentPositionCharacteristic.setValue(newTarget);
Serial.print("Current position changed? ");
Serial.println(changed); //serial returns 0 which means setValue notification fails
Serial.print("Current position set to: ");
Serial.println(currentPositionCharacteristic.value());
targetUpdate = false;
}
}
This has made absolutely no difference to how my application functions, however I got some interesting results from the two newly implemented methods.
The result of characteristic.canNotify()
comes back as 1 (true).
Crucially, the result of characteristic.setValue()
comes back as 0 (failure) meaning that the characteristic could not notify the central.
I also found the issue Can not notify data to central #4 in this repo where someone else using Blend Micro mentioned that central could not be notified.
That issue resulted in 226c9d3 commit which fixed it. Could I be facing something similar here?
The developer of the Homebridge-Bluetooth repo (mentioned above) has tried my code from the second post on Arduino 101 using CurieBLE library and it worked flawlessly.
It does appear that there’s an issue in how Red Bear Blend Micro communicates with BLEPeripheral library to send notifications.
More details about the results with CurieBLE are posted here https://github.com/vojtamolda/homebridge-bluetooth/issues/13
Hi
I'm trying to develop my own window covering BLE peripheral/accessory for HomeKit using Homebridge.
So far I have:
Set up Homebridge on Raspberry Pi 2 with a bluetooth dongle. Homebridge loads fine and finds the BLEPeripheral (in this case RedBear Blend Micro with Nordic nRF8001) Here's the config.json
This is what happens when I launch Homebridge and start interacting with my iPhone.
I developed the code with two characteristics TargetPosition and CurrentPosition.
When I attempt to open/close the blinds using iOS, the value is written from the central (Homebridge) to the peripheral (RedBear Blend Micro) TargetPosition characteristic as per the first screenshot. Interestingly, TargetPosition characteristic also sends the notification back to the central.
My issue is that whatever I tried, the CurrentPosition characteristic just refuses to send the notification back to the central when its value changes to let the central know that the operation has finished. The central is subscribed to the characteristic because serial prints out some text when the event handler is triggered at the point when the central subscribes.
As the central doesn't get an updated value for the CurrentPosition characteristic, presumably HomeKit has no idea where the blinds are so it simply displays a spinner next to the icon which just doesn't stop spinning (infinite loop).
Where am I going wrong?
Any help at all would be appreciated!