Folgende Warnungen sind aufgetreten:
Warning [2] Undefined variable $unreadreports - Line: 34 - File: global.php(961) : eval()'d code PHP 8.2.2 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/global.php(961) : eval()'d code 34 errorHandler->error_callback
/global.php 961 eval
/showthread.php 28 require_once
Warning [2] Undefined property: MyLanguage::$thread_modes - Line: 43 - File: showthread.php(1621) : eval()'d code PHP 8.2.2 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/showthread.php(1621) : eval()'d code 43 errorHandler->error_callback
/showthread.php 1621 eval




Themabewertung:
  • 2 Bewertung(en) - 5 im Durchschnitt
  • 1
  • 2
  • 3
  • 4
  • 5
Wohnmobil Raspicar
#41
(09.07.2018, 23:28)Bergstern schrieb: An ein script mit einer while schleife die einen gpio überwacht und bei low/high den shutdown ausführt meinst du?
Eine Anleitung wäre super!!! Danke. Dass script muss dann ja in den autostart und da müsste ich mich erst noch reinlesen.

Nein, keine while-Schleife. Das Skript wartet nur auf einen Interrupt (wait_for_edge). Das beschäftigt den Pi nicht so sehr. Es wird der interne Pull-up des Pins verwendet, ein externer Pull-up ist also nicht notwendig. Und für den Start des Skripts beim Boot ist auch schon gesorgt.

Bevor du loslegst, sei es empfohlen vorher ein Backup zu machen. Es sollte zwar nichts passieren aber sicher ist sicher!

Und so geht das:

Datei erstellen:
Code:
sudo nano listen-for-shutdown.py

mit folgendem Inhalt (unter der Annahme dass GPIO26 verwendet wird – falls ein anderer GPIO verwendet wird, dann ändern!):
Code:
#!/usr/bin/env python


import RPi.GPIO as GPIO
import subprocess


GPIO.setmode(GPIO.BCM)
GPIO.setup(26, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.wait_for_edge(26, GPIO.FALLING)

subprocess.call(['shutdown', '-h', 'now'], shell=False)

Nach /usr/local/bin bewegen und ausführbar machen:
Code:
sudo mv listen-for-shutdown.py /usr/local/bin/
sudo chmod +x /usr/local/bin/listen-for-shutdown.py


Weitere Datei erstellen:
Code:
sudo nano listen-for-shutdown.sh

Diesen Inhalt infügen:
Code:
#! /bin/sh

### BEGIN INIT INFO
# Provides:          listen-for-shutdown.py
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
### END INIT INFO

# If you want a command to always run, put it here

# Carry out specific functions when asked to by the system
case "$1" in
 start)
   echo "Starting listen-for-shutdown.py"
   /usr/local/bin/listen-for-shutdown.py &
   ;;
 stop)
   echo "Stopping listen-for-shutdown.py"
   pkill -f /usr/local/bin/listen-for-shutdown.py
   ;;
 *)
   echo "Usage: /etc/init.d/listen-for-shutdown.sh {start|stop}"
   exit 1
   ;;
esac

exit 0

Nach /etc/init.d bewegen und ausführbar machen:
Code:
sudo mv listen-for-shutdown.sh /etc/init.d/
sudo chmod +x /etc/init.d/listen-for-shutdown.sh

Um das Skript beim Start auszuführen:
Code:
sudo update-rc.d listen-for-shutdown.sh defaults

Du kannst jetzt das Skript starten mit:
Code:
sudo /etc/init.d/listen-for-shutdown.sh start

Das sollte es gewesen sein.
Zitieren


Nachrichten in diesem Thema
Wohnmobil Raspicar - von Bergstern - 05.06.2018, 19:39
RE: Wohnmobil Raspicar - von frankie0815 - 05.06.2018, 20:54
RE: Wohnmobil Raspicar - von Peziman - 06.06.2018, 07:57
RE: Wohnmobil Raspicar - von Bergstern - 25.06.2018, 21:31
RE: Wohnmobil Raspicar - von Bergstern - 05.07.2018, 07:59
RE: Wohnmobil Raspicar - von frankie0815 - 05.07.2018, 11:53
RE: Wohnmobil Raspicar - von harryberlin - 05.07.2018, 21:11
RE: Wohnmobil Raspicar - von Bergstern - 05.07.2018, 22:29
RE: Wohnmobil Raspicar - von frankie0815 - 06.07.2018, 04:00
RE: Wohnmobil Raspicar - von Bergstern - 06.07.2018, 13:10
RE: Wohnmobil Raspicar - von Bergstern - 06.07.2018, 22:46
RE: Wohnmobil Raspicar - von frankie0815 - 07.07.2018, 09:14
RE: Wohnmobil Raspicar - von Jack - 07.07.2018, 10:19
RE: Wohnmobil Raspicar - von frankie0815 - 07.07.2018, 11:32
RE: Wohnmobil Raspicar - von Jack - 07.07.2018, 14:00
RE: Wohnmobil Raspicar - von Bergstern - 07.07.2018, 17:22
RE: Wohnmobil Raspicar - von Der kleine Punky - 09.07.2018, 16:05
RE: Wohnmobil Raspicar - von frankie0815 - 09.07.2018, 16:20
RE: Wohnmobil Raspicar - von Bergstern - 09.07.2018, 16:58
RE: Wohnmobil Raspicar - von Jack - 09.07.2018, 18:03
RE: Wohnmobil Raspicar - von frankie0815 - 09.07.2018, 18:16
RE: Wohnmobil Raspicar - von Bergstern - 09.07.2018, 18:30
RE: Wohnmobil Raspicar - von Jack - 09.07.2018, 18:56
RE: Wohnmobil Raspicar - von Bergstern - 09.07.2018, 20:07
RE: Wohnmobil Raspicar - von Jack - 09.07.2018, 21:16
RE: Wohnmobil Raspicar - von Bergstern - 09.07.2018, 21:19
RE: Wohnmobil Raspicar - von Bergstern - 09.07.2018, 22:36
RE: Wohnmobil Raspicar - von Jack - 09.07.2018, 23:20
RE: Wohnmobil Raspicar - von Bergstern - 09.07.2018, 23:28
RE: Wohnmobil Raspicar - von Jack - 10.07.2018, 19:29
RE: Wohnmobil Raspicar - von maju - 10.07.2018, 14:17
RE: Wohnmobil Raspicar - von B.C. - 10.07.2018, 14:45
RE: Wohnmobil Raspicar - von Bergstern - 10.07.2018, 15:07
RE: Wohnmobil Raspicar - von Jack - 10.07.2018, 15:35
RE: Wohnmobil Raspicar - von frankie0815 - 10.07.2018, 15:38
RE: Wohnmobil Raspicar - von Jack - 10.07.2018, 17:29
RE: Wohnmobil Raspicar - von maju - 10.07.2018, 17:52
RE: Wohnmobil Raspicar - von Jack - 10.07.2018, 18:02
RE: Wohnmobil Raspicar - von maju - 10.07.2018, 18:35
RE: Wohnmobil Raspicar - von frankie0815 - 10.07.2018, 18:59
RE: Wohnmobil Raspicar - von Jack - 10.07.2018, 19:15
RE: Wohnmobil Raspicar - von Bergstern - 11.07.2018, 10:13
RE: Wohnmobil Raspicar - von maju - 11.07.2018, 14:16
RE: Wohnmobil Raspicar - von Bergstern - 11.07.2018, 15:12
RE: Wohnmobil Raspicar - von Jack - 11.07.2018, 15:29
RE: Wohnmobil Raspicar - von Bergstern - 11.07.2018, 15:53
Wohnmobil Raspicar - von Peziman - 11.07.2018, 16:23
RE: Wohnmobil Raspicar - von Bergstern - 11.07.2018, 22:31
RE: Wohnmobil Raspicar - von frankie0815 - 12.07.2018, 05:05
Wohnmobil Raspicar - von Peziman - 12.07.2018, 05:31
RE: Wohnmobil Raspicar - von maju - 12.07.2018, 09:15
RE: Wohnmobil Raspicar - von Peziman - 12.07.2018, 11:08
RE: Wohnmobil Raspicar - von Bergstern - 14.07.2018, 10:04
RE: Wohnmobil Raspicar - von maju - 14.07.2018, 10:58
RE: Wohnmobil Raspicar - von Bergstern - 20.07.2018, 03:31
RE: Wohnmobil Raspicar - von Bergstern - 26.07.2018, 04:03
RE: Wohnmobil Raspicar - von frankie0815 - 26.07.2018, 05:25
RE: Wohnmobil Raspicar - von Bergstern - 26.07.2018, 06:17
RE: Wohnmobil Raspicar - von frankie0815 - 26.07.2018, 06:23
RE: Wohnmobil Raspicar - von Bergstern - 29.07.2018, 00:04
RE: Wohnmobil Raspicar - von Jack - 30.07.2018, 22:10
RE: Wohnmobil Raspicar - von Bergstern - 31.07.2018, 01:51
RE: Wohnmobil Raspicar - von RSSB123 - 18.10.2018, 17:14
RE: Wohnmobil Raspicar - von Der kleine Punky - 01.11.2019, 08:55
RE: Wohnmobil Raspicar - von Astraracer87 - 24.05.2020, 07:42
RE: Wohnmobil Raspicar - von Der kleine Punky - 25.05.2020, 05:24

Gehe zu:


Benutzer, die gerade dieses Thema anschauen: 1 Gast/Gäste
RasPiCarProjekt