Add install script

This commit is contained in:
Julien Lazarewicz 2024-06-25 00:37:17 +02:00
parent b96ecd0605
commit 01053ffad3
4 changed files with 62 additions and 1 deletions

12
com.fup_anemometer.plist Normal file
View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.fup_anemometer</string>
<key>ProgramArguments</key>
<array><string>XXXX/fup_anamometer/start_fup_anemometer.sh</string></array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>

View File

@ -93,6 +93,7 @@ def main(meteobridge_url, meteobridge_user, meteobridge_passwd, max_host, max_po
except urllib.error.HTTPError as e:
if debug_urllib_print:
print('HTTP Error code: ', e.code)
logging.error("Get sensor datas from : " + meteobridge_url + " - HTTP Error code: " + str(e.code))
error_counter += 1
send_osc_message(oscSender, osc_error_addr, OSC_meteobridge_http_error)
@ -100,6 +101,15 @@ def main(meteobridge_url, meteobridge_user, meteobridge_passwd, max_host, max_po
# msg.add_arg(OSC_meteobridge_http_error)
# oscSender.send(msg.build())
# Sleep 5 seconds if error
if isinstance(e.reason, socket.timeout):
if debug_urllib_print:
print('HTTP Error reason: ', str(e.reason))
logging.error("Socket timed out from : " + meteobridge_url + " - URL Error Reason: " + str(e.reason))
error_counter += 1
send_osc_message(oscSender, osc_error_addr, OSC_meteobridge_url_error)
time.sleep(5)
except urllib.error.URLError as e:
@ -122,6 +132,13 @@ def main(meteobridge_url, meteobridge_user, meteobridge_passwd, max_host, max_po
# Sleep 5 seconds if error
time.sleep(5)
except :
if debug_urllib_print:
print('URL Unknown Error')
logging.error("URL Unknown Error")
error_counter += 1
else:
try:
data_json = json.loads(response.read())
@ -177,6 +194,7 @@ def main(meteobridge_url, meteobridge_user, meteobridge_passwd, max_host, max_po
logging.debug("OSC datas sent")
# Sleep 2 seconds if no errors
time.sleep(2)
# Self restart
if error_counter >= errors_restart:
send_osc_message(oscSender, osc_error_addr, OSC_meteobridge_restart)
@ -197,7 +215,7 @@ if __name__ == "__main__":
parser.add_argument('-u', '--user-meteobridge', default='meteobridge')
parser.add_argument('-p', '--passwd-meteobridge',default='meteobridge')
parser.add_argument('-mh', '--max-host', default='localhost')
parser.add_argument('-mp','--max-port', default=2222, type=int)
parser.add_argument('-mp','--max-port', default=8001, type=int)
parser.add_argument('-e', '--errors-restart', default=20, type=int)
args = parser.parse_args()

19
install.sh Normal file
View File

@ -0,0 +1,19 @@
#!/bin/sh
INSTALL_DIR="fup_anamometer"
mkdir $HOME/$INSTALL_DIR
cp fup-anemometer-user.py $HOME/$INSTALL_DIR/fup-anemometer.py
chmod +x $HOME/$INSTALL_DIR/fup-anemometer.py
cp start_fup_anemometer.sh $HOME/$INSTALL_DIR/start_fup_anemometer.sh
chmod +x $HOME/$INSTALL_DIR/start_fup_anemometer.sh
if [ ! -d $HOME/Library/LaunchAgents ]
then
mkdir -p $HOME/Library/LaunchAgents
fi
sed -i -e "s%XXXX%$HOME%g" com.fup_anemometer.plist
cp com.fup_anemometer.plist $HOME/Library/LaunchAgents/com.fup_anemometer.plist
python3 -m venv $HOME/$INSTALL_DIR
# copy python file to venv
cd $HOME/$INSTALL_DIR
source $HOME/$INSTALL_DIR/bin/activate
pip install python-osc

12
start_fup_anemometer.sh Normal file
View File

@ -0,0 +1,12 @@
#!/bin/sh
INSTALL_DIR="fup_anamometer"
METEOBRIDGE_URL="http://192.168.0.39/"
METEOBRIDGE_USER="meteobridge"
METEOBRIDGE_PASSWD="meteobridge"
MAX_HOST="localhost"
MAX_PORT=2222
cd $HOME/$INSTALL_DIR
source $HOME/$INSTALL_DIR/bin/activate
cd $HOME/$INSTALL_DIR
./fup-anemometer.py -url $METEOBRIDGE_URL -u $METEOBRIDGE_USER -p $METEOBRIDGE_PASSWD -mh $MAX_HOST -mp $MAX_PORT