Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save artificemm/3f9121acf50ade980d0c0b38bdb78d4e to your computer and use it in GitHub Desktop.
Save artificemm/3f9121acf50ade980d0c0b38bdb78d4e to your computer and use it in GitHub Desktop.

Revisions

  1. Erik Klimczak created this gist Dec 15, 2014.
    17 changes: 17 additions & 0 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    function calculateDistance(rssi) {

    var txPower = -59 //hard coded power value. Usually ranges between -59 to -65

    if (rssi == 0) {
    return -1.0;
    }

    var ratio = rssi*1.0/txPower;
    if (ratio < 1.0) {
    return Math.pow(ratio,10);
    }
    else {
    var distance = (0.89976)*Math.pow(ratio,7.7095) + 0.111;
    return distance;
    }
    }