Hi so I'm using the XBee to do some indoor tracking, Im pinging 3 routers using a transmitter and using the RSSI values to estimate the distances. The distances are printed out in the terminal. Is there a way for me to get this output printed into a txt file? My code is shown below, thank you for your help.
import xbee
A = -33.874
N = -17.27
EULER = 2.718281828
class Transmitter:
def __init__(self, device_dict):
self.device_dict = device_dict
def ComputeDistance(self, rssi):
return EULER**((rssi-A)/N)
# Display date in the form
# node id : rssi dBm, distance m
def DisplayData(self, device, distance):
string = ''.join([str(device), " : ", str(device), " dBm, ", str(distance), " m"])
print(string)
def LocateDevice(self):
for dev in xbee.discover():
if dev in self.device_dict:
dist = self.ComputeDistance(dev)
self.DisplayData(dev, dist)
device_dict = {
'RECEIVER_A': 'RECEIVER_A',
'RECEIVER_B': 'RECEIVER_B',
'RECEIVER_C': 'RECEIVER_C'
}
TX = Transmitter(device_dict)
for i in range(5):
TX.LocateDevice()