Puck.js, exposing Sensor Data to Google Science Journal

Posted on
  • Hi Gordon,

    I would like Google Science Journal to be able to record sensor data from my Puck.je over BLE.

    Can you point me to an example that would be relevant please?

    Here are the details, from a user who had a similar problem, visa vi, the Micro:Bit

    "As I understand it the Science Journal app is looking for Bluetooth advertising a service with the UUID "555a0001-0aaa-467a-9538-01f0652c74e8" and sends the value of the sensor on a characteristic with the UUID of "555a0003-0aaa-467a-9538-01f0652c74e8.

    If you use online tools, such as https://pxt.microbit.org/, to program the micro:bit then it will use the UUIDs as specified in the default micro:bit profile as specified at https://lancaster-university.github.io/m­icrobit-docs/resources/bluetooth/bluetoo­th_profile.html

    You would need to use the mbed platform (https://developer.mbed.org/platforms/Mic­robit/) to expose the sensors with the right UUIDs."

    I'm looking to translate that logic to Espruino code. I guess temperature would be good place to start. Note, I'm not trying to create a BLE temperature sensor with the expected temp sensor profile, but rather this particualr flavor the the Science Journal requires.

    Thanks,

    R.

  • It looks like you need to port the arduino code here:

    https://github.com/google/science-journa­l-arduino/blob/master/src/arduino101/sci­ence-journal-arduino.cpp

    You should be able to take a puck.js sample, and change the service Id's like you have identified.

  • Using the link above, it looks like:

    NRF.setServices({
      '555a0001-0aaa-467a-9538-01f0652c74e8' : {
        '555a0003-0aaa-467a-9538-01f0652c74e8' : {
          value : [0],
          maxLen : 20,
          readable : true,
          notify : true, 
        }
      }
    }, { advertise : ['555a0001-0aaa-467a-9538-01f0652c74e8']­ });
    
    // then every so often call:
    NRF.updateServices({
      '555a0001-0aaa-467a-9538-01f0652c74e8' : {
        '555a0003-0aaa-467a-9538-01f0652c74e8' : {
          value : [your_value_here],
          notify : true, 
        }
      }
    });
    

    I guess you might need to add the config characteristic, but it might work as-is

  • Thank you! I think that's exactly what I need...

  • As luck has it, I do have an Arduino 101 in my lab to test this further.

  • This turned out to be quite an adventure.

    https://productforums.google.com/forum/#­!topic/sciencejournal/1C6YI1erycU;contex­t-place=forum/sciencejournal

    Can anyone share if a vanilla Micro:Bit running the 16k ram version of the nRF51822, have the horse power to run a simple ble peripheral with a custom UUID, and a couple of characteristics?

    I wish my Puck had an accelerometer, to go with the magnetometer. Maybe a IMU is in order for next spin?

  • Just checked - looks like there's a crash if you do:

    NRF.setServices({
      '555a0001-0aaa-467a-9538-01f0652c74e8' : {
        '555a0003-0aaa-467a-9538-01f0652c74e8' : {
          value : [0],
          maxLen : 20,
          readable : true,
          notify : true, 
        }
      }
    }, { advertise : ['555a0001-0aaa-467a-9538-01f0652c74e8']­ });
    

    But try this one instead:

    NRF.setServices({
      '555a0001-0aaa-467a-9538-01f0652c74e8' : {
        '555a0003-0aaa-467a-9538-01f0652c74e8' : {
          value : [0],
          maxLen : 20,
          readable : true,
          notify : true, 
        }
      }
    }, { advertise : ['555a0001-0aaa-467a-9538-01f0652c74e8']­, uart:false });
    

    The issue was that it was trying to advertise two 128 bit UUIDs (the UART and the Google one). If you disable the BLE UART it should be fine.

    You could also manually specify the advertising payload to remove the name and put the UUID in the main packet with:

    NRF.setServices({
      '555a0001-0aaa-467a-9538-01f0652c74e8' : {
        '555a0003-0aaa-467a-9538-01f0652c74e8' : {
          value : [0],
          maxLen : 20,
          readable : true,
          notify : true, 
        }
      }
    }, { });
    NRF.setAdvertising([2,1,5,17,7,0xe8,0x74­,0x2c,0x65,0xf0,0x01,0x38,0x95,0x7a,0x46­,0xaa,0x0a,0x01,0x00,0x5a,0x55])
    

    But that's probably overkill :)

  • Time to take another look at this!

  • Hi Gordon!

    Sorry it took me so long to evaluate your excellent suggestion, I had to wait until the semester was over ...

    Giving it a try...

  • Hi Gordon!

    Voila! You sir are a star!

    Works like a champ, I just dumped the latest appropriate binary from the Espruino repo onto an Nordic DK-52 and then used the Windows 10 binary IDE to upload the code you suggested in your kind response.

    Now I need to think about what I2C peripherals would make sense to evaluate...

    Thanks again.

    Ps. Your software solution was in conclusion, hand's down the easiest! I tried quite a list of technologies.


    1 Attachment

    • Screenshot_20181214-123712.png
  • And there seems to be some opportunity to share this solution with the Micro:Bit, albeit with the concerns regarding memory. All the correct services, and characteristics are there.

  • nRF Connect ...


    1 Attachment

    • Screenshot_20181214-182816.png
  • OK on memory for the nRF51822 Micro:Bit, only 70 var used ...

  • Great! Thanks for letting me know.

    I hadn't come across Science Journal before, but it looks like it'd be something well worth doing a tutorial on for the Espruino site.

    If you get some code to send sensor readings, please could you post it up here?

  • Of course, plenty of time to look at this after the New Year ...

  • Waiting to get my new Pixel.js in post for UK. Also update/fix profile to have more consistent presence, than my rand userXXXXX moniker.

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

Puck.js, exposing Sensor Data to Google Science Journal

Posted by Avatar for Rando2 @Rando2

Actions