Reset ttyUSB

Da MeteoNetwork Wiki.
Jump to navigation Jump to search

Con questo script bash è possibile controllare e, nel caso, resettare udev in modo che il terminale usb a cui è connessa la Davis Vantage Pro/Pro2.


Lo script è compatibile con sistemi Linux (testato su Fedora 9/10/11/12) e, tramite lievi modifiche, altre macchine Unix (MacOS X).


E' necessario eseguirlo ogni 5 minuti, in crontab.

*/5 * * * * /directory/restore_ws.sh



Lo script è protetto sotto licenza GPLv2 - Associazione MeteoNetwork

#!/bin/bash
# Restore a Davis Weather Station on Linux, when WAKEUP fail.



#   Copyright (C) 1992, 1998, 2001 Free Software Foundation, Inc.

#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2, or (at your option)
#   any later version.

#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.

#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
#   02111-1307, USA.


DIR_DEV=/dev
cd $DIR_DEV

LOG=/var/log/wviewmnt
echo " " >> $LOG
date >> $LOG


# Se esiste ttyUSB1 allora e' partito...
if [ -e /dev/ttyUSB1 ]; then 
    echo "Ok.. qualcosa non va.. procedo" >> $LOG

	# Controllo che ttyUSB0 sia un symlink, se lo e' allora dovrebbe essere a pposto
	if [ -h /dev/ttyUSB0 ]; then
		echo "C'e' un link simbolico... E' tutto a posto.." >> $LOG
		exit
	else	

		echo "Cancello sia ttyUSB0 che 1" >> $LOG
		rm ttyUSB0
		rm ttyUSB1

		echo "Riavvio udev" >> $LOG
		/sbin/start_udev >> $LOG

		echo "Se si e' creata ttyUSB0 allora tutto a posto, altrimenti devo fare un symlink a ttyUSB1"
		if [ -e /dev/ttyUSB1 ]; then 
			echo "ttyUSB1 esiste.. faccio il symlink" >> $LOG
			ln -s ttyUSB1 ttyUSB0
		else 
			echo "ttyUSB1 non esiste, quindi tutto a posto" >> $LOG
		fi

	echo "Riavvio wview" >> $LOG
	/etc/init.d/wview restart >> $LOG

	fi

else 
    echo "Sembra tutto a posto" >> $LOG
fi

exit