As far as I understand it, HID works a bit like this:
Device wakes, starts advertising
PC/Mac sees it some time after
PC/Mac connects
It requests a list of services
It does interesting things with those services and remembers stuff about them
It requests to be notified to some of them
That all takes a bunch of time though, so even if you get the connected event I guess the HID might not have been initialised enough that a call to the NRF HID function would actually work.
What happens if you leave a reasonable delay (5 seconds?) between connecting and trying to send any HID packets?
Also, when you're getting that error, is your Mac actually showing the device as a HID device? Or does it show it as a normal serial device?
Are you calling setServices or setAdvertising more than once at all? I guess that could mess things up too - if the services change then the CCCD numbers might change, and that could confuse the computer.
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
As far as I understand it, HID works a bit like this:
That all takes a bunch of time though, so even if you get the
connected
event I guess the HID might not have been initialised enough that a call to the NRF HID function would actually work.What happens if you leave a reasonable delay (5 seconds?) between connecting and trying to send any HID packets?
Also, when you're getting that error, is your Mac actually showing the device as a HID device? Or does it show it as a normal serial device?
Are you calling
setServices
orsetAdvertising
more than once at all? I guess that could mess things up too - if the services change then the CCCD numbers might change, and that could confuse the computer.