diff --git a/pi/.gitignore b/pi/.gitignore index c7af37c..8826d9d 100644 --- a/pi/.gitignore +++ b/pi/.gitignore @@ -2,3 +2,4 @@ *.pem *.pyc nohup.out +door-id diff --git a/pi/.gitignore b/pi/.gitignore index c7af37c..8826d9d 100644 --- a/pi/.gitignore +++ b/pi/.gitignore @@ -2,3 +2,4 @@ *.pem *.pyc nohup.out +door-id diff --git a/pi/bathroom.service b/pi/bathroom.service new file mode 100644 index 0000000..2fb4dde --- /dev/null +++ b/pi/bathroom.service @@ -0,0 +1,19 @@ +[Unit] +Description=Monitor bathroom sensors and report to mattermost +After=network.target +After=systemd-user-sessions.service +After=network-online.target + +[Service] +User=pi +WorkingDirectory=/home/pi/bathroom-plugin/pi/ +Type=forking +ExecStart=/home/pi/bathroom-plugin/pi/start-monitor.sh +TimeoutSec=30 +Restart=on-failure +RestartSec=30 +StartLimitInterval=350 +StartLimitBurst=10 + +[Install] +WantedBy=multi-user.target diff --git a/pi/.gitignore b/pi/.gitignore index c7af37c..8826d9d 100644 --- a/pi/.gitignore +++ b/pi/.gitignore @@ -2,3 +2,4 @@ *.pem *.pyc nohup.out +door-id diff --git a/pi/bathroom.service b/pi/bathroom.service new file mode 100644 index 0000000..2fb4dde --- /dev/null +++ b/pi/bathroom.service @@ -0,0 +1,19 @@ +[Unit] +Description=Monitor bathroom sensors and report to mattermost +After=network.target +After=systemd-user-sessions.service +After=network-online.target + +[Service] +User=pi +WorkingDirectory=/home/pi/bathroom-plugin/pi/ +Type=forking +ExecStart=/home/pi/bathroom-plugin/pi/start-monitor.sh +TimeoutSec=30 +Restart=on-failure +RestartSec=30 +StartLimitInterval=350 +StartLimitBurst=10 + +[Install] +WantedBy=multi-user.target diff --git a/pi/setup-pip.sh b/pi/setup-pip.sh deleted file mode 100755 index 2ad2c5c..0000000 --- a/pi/setup-pip.sh +++ /dev/null @@ -1,9 +0,0 @@ -#! /usr/bin/env bash - -if [[ -z "$(which pip2)" ]] -then - curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py - sudo python get-pip.py -fi -sudo apt-get install python-gpiozero -sudo pip install pycryptodomex diff --git a/pi/.gitignore b/pi/.gitignore index c7af37c..8826d9d 100644 --- a/pi/.gitignore +++ b/pi/.gitignore @@ -2,3 +2,4 @@ *.pem *.pyc nohup.out +door-id diff --git a/pi/bathroom.service b/pi/bathroom.service new file mode 100644 index 0000000..2fb4dde --- /dev/null +++ b/pi/bathroom.service @@ -0,0 +1,19 @@ +[Unit] +Description=Monitor bathroom sensors and report to mattermost +After=network.target +After=systemd-user-sessions.service +After=network-online.target + +[Service] +User=pi +WorkingDirectory=/home/pi/bathroom-plugin/pi/ +Type=forking +ExecStart=/home/pi/bathroom-plugin/pi/start-monitor.sh +TimeoutSec=30 +Restart=on-failure +RestartSec=30 +StartLimitInterval=350 +StartLimitBurst=10 + +[Install] +WantedBy=multi-user.target diff --git a/pi/setup-pip.sh b/pi/setup-pip.sh deleted file mode 100755 index 2ad2c5c..0000000 --- a/pi/setup-pip.sh +++ /dev/null @@ -1,9 +0,0 @@ -#! /usr/bin/env bash - -if [[ -z "$(which pip2)" ]] -then - curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py - sudo python get-pip.py -fi -sudo apt-get install python-gpiozero -sudo pip install pycryptodomex diff --git a/pi/setup.sh b/pi/setup.sh new file mode 100755 index 0000000..b3c192d --- /dev/null +++ b/pi/setup.sh @@ -0,0 +1,16 @@ +#! /usr/bin/env bash + +sudo apt-get install python + +if [[ -z "$(which pip2)" ]] +then + curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py + sudo python get-pip.py +fi +sudo apt-get install python-gpiozero +sudo pip install pycryptodomex + +[[ -f private.pem ]] || ./generate-keys.sh + +sudo cp bathroom.service /lib/systemd/system/ +sudo systemctl daemon-reload diff --git a/pi/.gitignore b/pi/.gitignore index c7af37c..8826d9d 100644 --- a/pi/.gitignore +++ b/pi/.gitignore @@ -2,3 +2,4 @@ *.pem *.pyc nohup.out +door-id diff --git a/pi/bathroom.service b/pi/bathroom.service new file mode 100644 index 0000000..2fb4dde --- /dev/null +++ b/pi/bathroom.service @@ -0,0 +1,19 @@ +[Unit] +Description=Monitor bathroom sensors and report to mattermost +After=network.target +After=systemd-user-sessions.service +After=network-online.target + +[Service] +User=pi +WorkingDirectory=/home/pi/bathroom-plugin/pi/ +Type=forking +ExecStart=/home/pi/bathroom-plugin/pi/start-monitor.sh +TimeoutSec=30 +Restart=on-failure +RestartSec=30 +StartLimitInterval=350 +StartLimitBurst=10 + +[Install] +WantedBy=multi-user.target diff --git a/pi/setup-pip.sh b/pi/setup-pip.sh deleted file mode 100755 index 2ad2c5c..0000000 --- a/pi/setup-pip.sh +++ /dev/null @@ -1,9 +0,0 @@ -#! /usr/bin/env bash - -if [[ -z "$(which pip2)" ]] -then - curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py - sudo python get-pip.py -fi -sudo apt-get install python-gpiozero -sudo pip install pycryptodomex diff --git a/pi/setup.sh b/pi/setup.sh new file mode 100755 index 0000000..b3c192d --- /dev/null +++ b/pi/setup.sh @@ -0,0 +1,16 @@ +#! /usr/bin/env bash + +sudo apt-get install python + +if [[ -z "$(which pip2)" ]] +then + curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py + sudo python get-pip.py +fi +sudo apt-get install python-gpiozero +sudo pip install pycryptodomex + +[[ -f private.pem ]] || ./generate-keys.sh + +sudo cp bathroom.service /lib/systemd/system/ +sudo systemctl daemon-reload diff --git a/pi/start-monitor.sh b/pi/start-monitor.sh new file mode 100755 index 0000000..e38fbc8 --- /dev/null +++ b/pi/start-monitor.sh @@ -0,0 +1,3 @@ +#! /usr/bin/env bash + +nohup python monitor.py $(if [[ -f door-id ]]; then cat door-id; else echo -n 2; fi) http://mattermost.djartsgames.ca:8065/plugins/com.mattermost.bathroom/ &