Community discussions

MikroTik App
 
miro10hr
Member Candidate
Member Candidate
Topic Author
Posts: 101
Joined: Fri Nov 11, 2011 3:03 pm

Print in file on specific interfval - help

Mon Oct 22, 2012 5:25 pm

Hi,

I'm not very familiar in scripting, it seems to me this shouldn't be hard to do, but I didn't manage to find similar items.

I need to print in file signal strenght of specific wireless client, for example, every second.

This is the command:

/interface wireless registration-table print brief interval=1s where mac-address=xxxxxx

The result of this command is:

# INTERFACE RADIO-NAME MAC-ADDRESS AP SIGNAL... TX-RATE
0 wlan1 xxxxxxxxxxxxxxxxxxx no -61dBm... 5.5Mbps

If i put file in command:
/interface wireless registration-table print brief file="name_1" where mac-address=xxxxxxxxxxxxx

and put scheduler to 1s, it is no good.

The script is writing repeatedly in the same file and file is corrupted (it has /r/n in it's name when I issue file print in terminal).

Can someone help me about this. How should I write the script?
 
miro10hr
Member Candidate
Member Candidate
Topic Author
Posts: 101
Joined: Fri Nov 11, 2011 3:03 pm

Re: Print in file on specific interfval - help

Tue Oct 23, 2012 3:38 pm

OK,

I played a little bit, but the only thing I could get is to print one line in the file. Every new line is erasing the previous one.

I tried to copy some lines of code from others, but I really don't have too much understanding of this.

This is my code:
#Global variable
:global fileContent "";
#this commands puts the output of this print command in the file (it erases previous entry in the file)
/interface wireless registration-table print file=Test1.txt brief where mac-address="xx:xx:xx:xx:xx:xx";
#the content of the files i copied to variable
:set fileContent [/file get Test1.txt content];
#variable is copied to new file, each entry in new line
/file set Signal.txt contents=($fileContent."\n");

So this was my logic, but it doesn't work. I can't add new row, so every new entry is put in the new row.

What am I doing wrong?
 
User avatar
skot
Long time Member
Long time Member
Posts: 584
Joined: Wed Nov 30, 2011 3:05 am

Re: Print in file on specific interfval - help

Thu Nov 22, 2012 1:37 am

You could save signal strength to a variable and append this data every second. Then, this variable can be saved to a file:
{
# check if file exists, if not create it and set contents to nothing
:if ([:len [/file find name="Signal.txt"]] != 1) do={
	/file print file=Signal
	:delay 2s;
	/file set Signal.txt contents="";
}
# set variables
:local fileContent;
:local signal;
# get signal from specific MAC
:set signal [/interface wireless registration-table get [find where mac-address="xx:xx:xx:xx:xx:xx"] signal-strength];
# get file content
:set fileContent [/file get Signal.txt content];
# append signal to fileContent
:set fileContent ($fileContent . $signal);
# re-write file content
/file set Signal.txt contents=($fileContent . "\r\n");
}
However, writing to a file every second may not be advisable as it will shorten the life of the flash memory... You could save the signal to a variable every second and then every few minutes write this data to a file (using a couple scripts and the scheduler). However, the main problem with this method is file size. You can't create a file larger than 4096 bytes (http://forum.mikrotik.com/viewtopic.php ... 36#p213405), so you will quickly hit that limit.

Using the Dude would be a good solution. It can log signal and much more: http://www.mikrotik.com/thedude.php

But, I still wonder, what do you want to do with the data? How do you want to use it? This might help determine the best solution for you.

Who is online

Users browsing this forum: GoogleOther [Bot] and 58 guests