• Hi friends,

    I am working on some project in which we have to measure the distance between two nearby device using puck.js . if distance is less then a meter . we need to emit LED.

    One device is puck.js and other one is ESP32.
    Help me to figure out this.

  • Assuming the ESP32 is advertising, you should be able to use something like:

    NRF.setScan(function(d) {
      if (d.addr=="...") LED.write(d.rssi>-70);
    });
    

    You'll need to change the address and probably the RSSI value as well, but that should be a good start :)

  • Thanks its working

  • Just a quick note that doing this does use a lot of power (as the radio is always receiving) so will run the battery down quite quickly - so you might want a way of only enabling it when you need it.

  • Hello, I am trying to do something similar but I have two puck.js how would this programming change? I am actually trying to get the signal and turn it into a distance, or just display the strength to eventually turn it into a distance?

  • The code should be exactly the same... You can just use setScan/requestDevice/etc and look at the rssi value in what's returned.

    Or, if you've got an active connection between the two devices you can use setRSSIHandler (https://www.espruino.com/Reference#l_BluetoothRemoteGATTServer_setRSSIHandler) - with the active connection it is a lot more power efficient than constantly scanning for advertisments.

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

Measuring distance between two devices using puck.js

Posted by Avatar for Saurabh @Saurabh

Actions