Site Tools


linux:raspberry:wde:scripts:reader

This is an old revision of the document!


Reader

To seperate data to daily files I use 3 scripts which will be executed via cronjobs.

Script 1 - Starter

This will execute socat with daily modified parameters. The logfile parameter will have the date of “today”. It starts at 12:02 am everyday.

#!/bin/bash
 
DATE=`date +%d_%m_%Y`
FILETYPE=.log
 
nohup /usr/bin/perl wde_reader.pl /dev/ttyUSB0 /media/weatherlog/$DATE$FILETYPE </dev/null >/wde/wde1_reader.out &
echo $! >/wde/wde_reader.pid

Script 2 - Reader

This script is a cutted version from tdressler.net. Instead of writing things into 2 files and other things this script will only write 1 file with a single outputline, started with the date and time.

#!/usr/bin/env perl
 
use strict;
use IO::Handle;
use Time::Piece;
 
my $dev=$ARGV[0]||'/dev/ttyUSB0';
my $socat='/usr/bin/socat';
my $cmd="$socat $dev,b9600 STDOUT |";
my $log=$ARGV[1]||"/tmp/wde1.log";
my $date = localtime->strftime('%m.%d.%Y;%H:%M:%S;');
 
$SIG{QUIT}=$SIG{INT}=$SIG{TERM}=\&handler;
$SIG{HUP}=$SIG{PIPE}='IGNORE';
 
$|=1;
 
open (S,$cmd) ||die "Cannot open $dev using $cmd ($!)\n";
open(R,">>","$log") ||die "Cannot open logfile $log!\n";
 
R->autoflush(1);
 
while (<S>) {
	print R "$date$_";
}

Script 3 - Killer

This script is killing socat everyday at 11:58 pm. Remember, it will start again at 12:02 am with a new date.

#!/bin/bash
 
sudo kill -9 `cat /wde/wde1_reader.pid`
sudo rm /wde/wde1_reader.pid

Output

There will be a new logfile with another date everyday.

Examplefile 05_06_2015.log:



linux/raspberry/wde/scripts/reader.1433512355.txt.gz · Last modified: 2017/03/01 12:50 (external edit)