Puck button integration with android device. #1975
Replies: 16 comments
-
Posted at 2017-01-04 by Ollie I think something similar has been asked and I think emulating a keyboard was the advice offered. There's a tutorial on that here: |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-01-04 by @gfwilliams As @ollie says, keyboard emulation is probably the best bet - unless you are writing an app. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-01-12 by user72040 Thanks Ollie/Gordan, Sorry for being bit unclear in my query. I think I'm looking to build an app. Let me clarify bit more if it helps. I need this button to work as below: Someone who is visually impaired wants to call an emergency number[say a family member] from his Android phone. Instead of dialling number/searching in phone book, he could just do a single click to call number a, double click call number b from such button which is paired with his phone. Your guidance on this will be appreciated. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-01-12 by @gfwilliams I think an app is the safest solution then. What I'd suggest is:
Advertising is just something that's broadcast - you're not guaranteed to receive it on the phone - so I'd suggest using a 'buttonPresses' variable that just increments. On the phone, if that's different from the last time you got an advertising packet you know that the button has been pressed between times. It beats using something that's set to 1 and then returns to 0, since you could potentially miss all the advertising packets sent while it was 1. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-01-17 by user72040 Thanks Gordon. I agree about app being the solution. I tried your suggestion but nothing seem to work right now for me. I started by trying very simple implementation i.e. send temperature on each click. I put following code in Puck: setWatch(function(e) Now, android side I tried to get this advertised data when Puck button is pressed but there is nothing there. Can you please point me to a sample/link on Android side which can do this? Also if anything done wrong here. Regards, |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-01-17 by @gfwilliams Did you disconnect the Web IDE from the Puck first? Bluetooth LE devices don't advertise while something is connecting to them. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-01-18 by user72040 Yes, I disconnected it with Web IDE, then paired it with android device, and then ran the Android App. I doubt its the Android code, I could scan the device but do not have the listener method for advertising data I guess. Any pointer regarding this? Regards |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-01-18 by @gfwilliams
To receive advertising data you don't need to pair. In fact, pairing usually creates a connection, which then stops the device from advertising. That could be your issue? First, I'd try making sure you can receive the advertising data using |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-01-19 by user72040 Hi Gordon, Thanks, for the reply. I have found the solution to receive advertising data without pairing puck button with android device but I am not sure if I'll need to run a background thread to keep looking for this advertisement OR is there a way to listen to this? One more thing, how ca I decode the data currently I am receiving to make sure that the data is sent from my button? Regards |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-01-19 by @gfwilliams I'm not entirely sure about how it works on Android I'm afraid - maybe you could ask on stackoverflow or similar. Looks like it's already been asked: http://stackoverflow.com/questions/19914244/creating-background-services-for-bluetooth-low-energy-on-android It's worth googling - there seem to be a bunch of other posts about it too. I'm not quite sure what you mean about decoding the data? could you give an example? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-01-19 by user72040 I was getting some data on Android side which I assumed needed decoding. Since I'm now advertising using NRF.setAdvertising({
So currently I do not have paired button and am accessing bluetooth info of Puck in Android code, I get some data in array but not sure how to interpret it. Regards, |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-01-19 by @gfwilliams
No, it keeps advertising every 350ms (or however long you specified in
The Puck's name and the advertised data are sent in the same packet, so should arrive in Android together. I'm not 100% sure if they're exposed that way, but it seems like it.
This might help? http://stackoverflow.com/questions/22016224/ble-obtain-uuid-encoded-in-advertising-packet?answertab=active#tab-top |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-01-23 by user72040 Hi Gordon, I have revisited this and think for my requirement I would want to work it after device is paired with phone, otherwise device will read advert from all buttons. While looking I came across NRF.setServices() which sends data only when device is paired. I hope it work like below [see Js code below for Puck]. I now hope I'll find code which will read this service data in android code. Can you suggest your views on this? var C = { setWatch(function(e) // first time Regards |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-01-23 by @gfwilliams On Android, why not just do something like:
The code you have posted above will work, but maintaining a connection will drain the Puck's batteries at 10x the normal rate (you can use In addition, Android phones can only maintain 7 active Bluetooth LE connections - if you're thinking of having multiple devices (and the user may have their own devices as well) you might find that you hit that limit |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-02-01 by Dave_Smart Hi Guys, You can easily do this in DroidScript with the BLE plugin Here is the Puck.js code:-
And Here is the DroidScript code:-
You could optionally put the DroidScript code inside a DroidScript service and have it always running in the background on your phone too :) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-02-02 by @gfwilliams Thanks - that's a really neat example! |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-01-04 by user72040
Hi support, My puck button is just delivered to me. I want to pair it with my Android mobile device and perform a simple task of calling a number when I press the button. Can you please guide/point me to where/how to start?
Beta Was this translation helpful? Give feedback.
All reactions