2

enter image description hereI’m going to preface this by saying that I am still learning Python so please be kind and patient. My code goes as follows:

  • Client on the network sends a text file (stats.txt) every ~5 seconds to an SCP server. Python code sits on the server.

Code below begins:

import matplotlib.pyplot as pltimport csvimport datetimex = []y = []rssi_val = []def animate(i):    with open('stats.txt', 'r') as searchfile:        time = (searchfile.read(5))        for line in searchfile:            if 'agrCtlRSSI:' in line:                rssi_val = line[16:20]    y = [rssi_val]    x = [time for i in range(len(y))]    plt.xlabel('Time')    plt.ylabel('RSSI')    plt.title('Real time signal strength seen by client X')    #plt.legend()    plt.plot(x,y)    ani = FuncAnimation(plt.gcf(), animate, interval=5000)    plt.tight_layout()    #plt.gcf().autofmt_xdate()    plt.show()
  • SCP server opens the file every 5 seconds and plots the values that are parsed from the file. Time gets plotted on the X axis and the RSSI value gets plotted on the Y axis.

I understand that the code and methods used are not efficient at this point and will be modified in the future. For now I simply want the the plot values to show up and the chart to be animated with the plot (line) every 5 or so seconds.

Running it produces nothing.

askedJan 10, 2020 at 20:32
wiwinut's user avatar
1
  • Does each new file contain a single RSSI value?CommentedJan 10, 2020 at 21:44

1 Answer1

1

You need to have the line

ani = FuncAnimation(plt.gcf(), animate, interval=5000)

Outside of the functionanimate, then assuming the data are received and read in properly you should see the plot updating. You may also need to putplt.show() after theFuncAnimation() line depending on how you are executing the script.


Edit

You may want to try something like this instead

import matplotlib.pyplot as pltimport csvimport datetimex = []y = []rssi_val = []def animate(i):    with open('stats.txt', 'r') as searchfile:        time = (searchfile.read(5))        for line in searchfile:            if 'agrCtlRSSI:' in line:                rssi_val = line[16:20]    y.append(rssi_val)    x.append(time)    plt.cla()    plt.plot(x,y)    plt.xlabel('Time')    plt.ylabel('RSSI')    plt.title('Real time signal strength seen by client X')    plt.tight_layout()ani = FuncAnimation(plt.gcf(), animate, interval=5000)plt.show()
answeredJan 10, 2020 at 20:46
William Miller's user avatar
Sign up to request clarification or add additional context in comments.

8 Comments

Edit: Chart is now updating with the time but plots are not appearing.
@wiwinut The update should be taken care of byFuncAnimation, I would expect the issue is with reading the data if it is not updated. I would check thatrssi_val is non-empty
Update: After monitoring it I see that both X and Y values are now appearing on the outsides of the box X & Y. No trend lines are appearing INSIDE however. Not sure if that's clear and I don't have the possibility of posting an image in the comments. I'm trying to illustrate that at time X, RSSI value was Y. Thanks for your help thus far BTW!
@wiwinut You can edit the question to add an image of the output and I'll try to help you figure out what the issue is. It would also be useful if you could include some of the data
@wiwinut Take a look at the approach in my edit, if I'm understanding correctly what you're trying to do that should be a better way to go about it. Unless you are reading in multiple RSSI values per iteration
|

Your Answer

Sign up orlog in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to ourterms of service and acknowledge you have read ourprivacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.