Display Puck data in Android Application

Posted on
  • Hi,
    I want to display my Puck's data (temperature and brightness) every 30 minutes in my Android Application.
    Can anyone tell me the exact steps to do that?
    I have tried this example: https://github.com/googlesamples/android­-BluetoothAdvertisements
    but nothing is being displayed..

  • Sorry for the delay - I was out at an exhibition all last week.

    Are you still connected to the Puck.js with another device? That tends to stop advertising.

    I'd install nRF Connect on your Android phone and check that the Puck really is advertising the correct information - then you can narrow down where the problem lies.

  • Thanks for your response Gordon.. I downloaded nRF Connect and i used the presses example..
    Where should i see the number of presses though?? Also if i want to display temp and brightness every so often, what my code should be like??

  • Ok,

    • Put this on Puck.js:

    function updateAdv() {
      var data = [Puck.light()*255, Math.round(E.getTemperature())];
      NRF.setAdvertising({},{manufacturer: 0x0590, manufacturerData:data});
    updateAdv(); // start off right now
    setInterval(updateAdv, 30000); // update every 30 seconds
    • Disconnect from Puck.js, so it starts Advertising
    • Run nRF Connect
    • Go to the Scanner tab, click Scan in the top right
    • Find your Puck.js device, and tap on it (not on the connect button, just the text)
    • In the data there, you should see 'Manufacturer data', a company ID 0x0590, and a hex code like 0xCA14.
    • In 0xCA14, 0xCA is the light value (between 0 and 255) and 0x14 is the temperature in degrees C

    Hopefully when that works, you can start to figure out about writing your own Android app to receive the data too.

  • I think it works.. but the other question is how to display in the right format the brightness and temperature values into my Android app?
    I tried to use the bluetooth advertisements example https://github.com/googlesamples/android­-BluetoothAdvertisements
    but what exactly i have to do in order to achieve my goal??
    What UUID do i need to include in my Constants class?

  • I'd make sure that you're not filtering the advertisements based on anything at all

    Basically you should be getting callbacks with a bunch of ScanResult entries: https://github.com/googlesamples/android­-BluetoothAdvertisements/blob/master/App­lication/src/main/java/com/example/andro­id/bluetoothadvertisements/ScannerFragme­nt.java#L202-L228

    Then you can do ScannerFragment.getScanRecord(). getManufacturerSpecificData(0x0590) - the same ID as used in the code I posted above.

    If you get null, it's not one of your devices. If it is, you should have an array of 2 bytes. First is the light value between 0 and 255, the second is the temperature in degrees C.

  • Unfortunately can't manage to get it work.. Could you please provide me with more specific info?? I know I'm a bit annoying but i want to get it done.. Where do i have to add the ScannerFragment.getScanRecord(). getManufacturerSpecificData(0x0590) line??

    Thanks in advance!

  • Yes - but then obviously you have to do something with the array of byte values that function returns - even if it's only printing them to a log file.

    edit: also - you just filed that bug? I'd avoid doing that on people's GitHub - especially Google's one. Just upload the screenshot to the forum :)

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

Display Puck data in Android Application

Posted by Avatar for sn0wpow @sn0wpow