Skip to content

Instantly share code, notes, and snippets.

@danyanya
Created April 13, 2020 11:47
Show Gist options
  • Save danyanya/0e5684379455cfec66e059b76acef2e7 to your computer and use it in GitHub Desktop.
Save danyanya/0e5684379455cfec66e059b76acef2e7 to your computer and use it in GitHub Desktop.
golang client distance from rssi and mhz
package rssi
import (
"math"
)
const (
// from wiki original formula: https://en.wikipedia.org/wiki/Free-space_path_loss
fsplConstant = 27.55
)
// GetDistance function to get estimated distance from MHz and RSSI
func GetDistance(mhz, rssi float64) float64 {
if mhz == 0 {
mhz = 2412
}
return math.Pow(10, 1-20.0/fsplConstant*math.Log10(mhz)-rssi/fsplConstant)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment