-
• #2
Try upgrading the firmware? 1v96 is quite old now.
Tried just now with 2v01 and:
var controls = require("ble_hid_controls"); NRF.setServices(undefined, { hid : controls.report }); setWatch(function() { // Play/stop music controls.playpause(); }, BTN, {repeat:true});
and it works great playing/pausing videos on an iPad mini.
I paste the code, connect to Puck, upload it, disconnect, then attempt to connect from my iPhone.
This is exactly what I did, but do get the pairing message on mine.
It might be worth powering the Puck up with a long-press of the button, as that will clear any pairing info out of it - just in case that was some kind of problem.
Also, I should add that if I'm on the Bluetooth settings screen on the iPad then I do see it when doing
NRF.findDevices(print)
(reporting"manufacturer": 76,
, which is 0x004c - apple's ID. -
• #3
Thanks Gordon, I'll upgrade it, I did check the Stepper video for the firmware and that was 1.94 I think. So I thought I was probably recent enough in that regard.
Also, I should add that if I'm on the Bluetooth settings screen on the iPad then I do see it when doing NRF.findDevices(print) (reporting "manufacturer": 76,, which is 0x004c - apple's ID.
Ah that's interesting, I'd recently discovered exactly the same for Wireless Networks. On later iOS the Wifi Mac address is exposed when looking for networks in the Wifi networks page, but not generally seen. I should have considered that they masked Bluetooth Mac in the same way.
Thanks again, I'll post up how I get on.
-
• #4
Ahh - yes, it was a 1.94.something build in the video I think... But still, new ones will likely be a good deal more reliable :)
-
• #5
Thanks Gordon. With the new firmware, I still had no joy, which led me to look at "clearing any pairing" as you mentioned above.
So I saved the code to the Puck (with added with E.on("init")), and reset the Puck . Now I get the pairing dialog and the media example works for me. Wonder if my Mac is at fault - not had problems before.
I'm now interested in how to detect when this iPhone connects again and if possible grab the RSSI. I've had a look about the forum and can't see how the Puck knows it is now back in control of a device via HID, nor how I can get data back such as RSSI. Are these things feasible?
-
• #6
Wonder if my Mac is at fault - not had problems before.
Probably not - I wonder whether if you pair and unpair then the Mac deletes its pairing key, but the Puck doesn't know it has to so keeps trying to use the old key which might cause problems?
can't see how the Puck knows it is now back in control of a device via HID
You can't easily - you can see it's connected/disconnected via events on
NRF
, and I guess you could try sending a 'null' HID report and see if it throws an exception to see if HID has been enabled?how I can get data back such as RSSI.
It's just this: http://www.espruino.com/Reference#l_NRF_setRSSIHandler
Once there's a handler, it'll get called whenever a device connects to Puck.js with a number which is the connection strength. Job done.
You might also want to look at http://www.espruino.com/Reference#l_NRF_setConnectionInterval - you could set this to something lowish (like 500ms) which reduces the activity on the BLE connection. It'll reduce the rate that the setRSSIHandler callback gets called and will help save the Puck and iOS device's battery
-
• #7
Thanks Gordon there's loads of info to go on there - appreciated. Can I ask one more thing before cracking on with it, can the Puck drop it's HID connection? And if it does, will the pairing mean it is reestablished, or will it kill the pairing?
To be able to act on the RSSI info, I had hoped to be able to communicate with a hub of some form over BLE UART, the ideal flow would be: Detects connection of iPhone > Measures RSSI > determines RSSI is within set range as proxy for proximity > disconnect and inform hub > disconnect from hub >iphone device reconnects > repeat the previous steps? I'm very rusty on Espruino and BLE so apologies for all the questions.
-
• #8
The Puck can drop its connection with
NRF.disconnect()
, but what happens next depends on the device. It'll probably try and reconnect.However... Espruino can have one incoming and one outgoing connection at the same time - if you're planning on connecting to the hub to inform it then actually you have no reason to disconnect from the iOS device at all :)
-
• #9
Superb. Thanks for taking the time Gordon!
-
• #10
I got some way. It's hard to develop with no console for certain.
So far:
- Connect times from IDE seem longer with 2.0.1. Puck is found quickly, but seems to take an age to connect.
- NRF connect and disconnect handlers work as expected - watched on
LED. And the iPhone reliably reconnects. - My
setRSSHandler
readings are out of range - all are positives?
- Connect times from IDE seem longer with 2.0.1. Puck is found quickly, but seems to take an age to connect.
-
• #11
Hi, You could attach serial if you need to... http://www.espruino.com/Puck.js#serial-console
That's interesting - it could be to do with the power saving stuff. I've filed an issue for it at https://github.com/espruino/Espruino/issues/1605
Great
Strange... I just checked with a Pixl and what's reported is an 8 bit unsigned value. Turns out
char
isn't always signed in C - first I knew about it :) I've just fixed this, but for the current build tryif (rssi>127) rssi-=256;
-
• #12
Thanks Gordon. You might be able to close that issue - I tried another Puck and that was much faster. So looking into it, though I didn't specifically pair my Mac with the Puck when it was HID, it seems to have a pairing - I'd just been disconnecting it, not realising. Now, I've actually removed the pairing from my Mac, the connection seems fine. Likely a false alarm. Apologies.
I've been trying to find a way to get a Puck to act as central with iPhone as peripheral. I only want the phone's RSSI, but the iPhone is invisible to my scans for it.
So I then approached it via LightBlue app which allows you to set up virtual peripherals by advertising services, but didn't have any success scanning for the device/service either.
I then saw a comment from Gordon in a related post, suggesting that HID may allow a "no software" implementation as Puck will know when peripheral is connected, but I've had absolutely zero success getting any of the HID examples to work - literally just pasting them in.
I'd concluded maybe HID was Android only - until I saw the stepper machine video which uses Puck/HID with iPad.
I paste the code, connect to Puck, upload it, disconnect, then attempt to connect from my iPhone. The device is there, it does connect, but never displays any sort of pairing modal message as is seen in the stepper video. Needless to say the functionality, say the media player control, does not work either.
The puck is running Espruino v1.96.
The iPhone is on iOS 12.1.2
Is anybody seeing same, or know what I'm doing incorrectly?