Xbee terminal output to txt file ?

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['node_id']), " : ", str(device['rssi']), " dBm, ", str(distance), " m"])
    print(string)

def LocateDevice(self):
    for dev in xbee.discover():
        if dev['node_id'] in self.device_dict:
            dist = self.ComputeDistance(dev['rssi'])
            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()

See http://cms.digi.com/resources/documentation/digidocs/90002219/#reference/r_access_data.htm?Highlight=writing%20to%20a%20file

1 Like

Xbee acts as a flash drive it can’t write to the pc directly. I am not sure how’d implement this in my code

No, not quite. The XBee acts as a CABLE and not a flash drive. So you would have to adjust your application code to do what you want.