Community discussions

MikroTik App
 
gosha
Member Candidate
Member Candidate
Topic Author
Posts: 154
Joined: Mon Jul 19, 2004 3:14 pm
Location: Tallinn, Estonia

Log serial port with Mikrotik?

Mon Nov 28, 2005 6:37 pm

Hi!

I need to make a PBX's CDR log. Is it possible to simply write everything that came from Serial port to some text file on HDD?
 
jurisv
just joined
Posts: 19
Joined: Thu May 05, 2005 5:27 pm

Tue Nov 29, 2005 12:45 am

you can youse linux and this perl script:
#!/usr/bin/perl                                                                                                                     
#                                                                                                                                   
#       Serial port data receiver (logger)                                                                                          
#       Receives at any speed without data loss and uses practicaly no CPU                                                                                                                                
                                                                                                                                    
use Device::SerialPort;                                                                                                             
use Time::HiRes "usleep";                                                                                                           
my $port = '/dev/ttyS0';                                                                                                            
                                                                                                                                    
my $ob = Device::SerialPort->new ($port);                                                                                           
                                                                                                                                    
$baud = '2400';                                                                                                                     
$parity = 'none';                                                                                                                   
$data = '7';                                                                                                                        
$stop = '1';                                                                                                                        
$hshake = 'none';                                                                                                                   
                                                                                                                                    
$ob->baudrate($baud)    || die "fail setting baud";                                                                                 
$ob->parity($parity)    || die "fail setting parity";                                                                               
$ob->databits($data)    || die "fail setting databits";                                                                             
$ob->stopbits($stop)    || die "fail setting stopbits";                                                                             
$ob->handshake($hshake) || die "fail setting handshake";                                                                            
                                                                                                                                    
# Open the file where all data will be logged                                                                                       
open(LOG, ">>/opt/logger/logs/logfile.log") || die "Cannot open logfile";                                                           
                                                                                                                                    
# Nonbuffered output to file !                                                                                                      
select(LOG), $| = 1;                                                                                                                
                                                                                                                                    
# Endless loop                                                                                                                      
while (1)                                                                                                                           
{                                                                                                                                   
    # Get data from serial port                                                                                                     
    $stream = $ob->input;                                                                                                           
                                                                                                                                    
                                                                                                                                    
    # If the variable contains data, process it else sleep                                                                          
    if ($stream)                                                                                                                    
    {                                                                                                                               
        print LOG $stream;                                                                                                          
    }                                                                                                                               
    else                                                                                                                            
    {                                                                                                                               
        usleep(1);                                                                                                                  
    }                                                                                                                               
                                                                                                                                    
}                                                                                                                                   
But MT could do it, that was greate due routerboard size :)
 
gosha
Member Candidate
Member Candidate
Topic Author
Posts: 154
Joined: Mon Jul 19, 2004 3:14 pm
Location: Tallinn, Estonia

Tue Nov 29, 2005 9:36 pm

yes, i can use linux for it but I don't want to place another comp for it. Is it possible to do it with linux or not?