Created
April 13, 2020 11:47
-
-
Save danyanya/0e5684379455cfec66e059b76acef2e7 to your computer and use it in GitHub Desktop.
golang client distance from rssi and mhz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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