RSSI-Distance calculation help
I am not sure why are you using such a complex formula. In general, there are so many unknowns that all existing systems have to use empirical calibration to get mapping. 

Conveniently enough, the rssi&lt;->distance mapping is one of the favorite projects for university students who want to work with WiFi, so google returns a number of academic papers of varying quality. Here are my first two results for "using rssi for distance measurement", both of them assume that RSSI is proprotional to log of distance squared and calibrate using emprical data. Both of them have a pretty good fit for their model, but with wildly different coefficents.

"Distance Measurement Model Based on RSSI in WSN"
http://www.scirp.org/journal/PaperDownload.aspx?paperID=2348
This one has a nice explanation of the model they are using, together with the derivation of the formula.

"Outdoor Localization System Using RSSI Measurement of ..."
http://www.ijitee.org/attachments/File/v2i2/A0359112112.pdf
This one is a very basic one, which just illustrates that a different equipment will produce completely different RSSI values.