Cleanup Script File
- GPIO Pins wurden in Variablen umgesetzt, damit bei Änderungen nicht das gesamte Script angepasst werden muss. - Zeile 9 bis 16 beinhaltet die GPIO Pins, welche benutzt werden. Hier können diese nun konfiguriert werden. - Die SIP Zugangs daten werden nun unter /boot/sip.txt hinterlegt, damit auch Windows User ohne EXT3/4 Support dieses File bearbeiten können. Das Python Script liest die jeweilige Zeilen ein. In Zeile 1 kommt der Benutzername (z.b. die Rufnummer) in Zeile 2 kommt der Server/Proxy (hg.eventphone) und in Zeile 3 kommt das Passwort. Beispiel: 6011 hg.eventphone.de foobar2000 - Die Wecker funktion wurde verkürzt und in ein Repeat gesetzt. Die Anzahl der Schläge können unter Hits definiert werden. - Unter HitsSleep kann die dauer zwischen den Schlägen definiert werden. - Mit Dialcountdown kann jetzt die Zeit eingestellt werden, wie lange man warten muss, bis nach der Wahl der der Nummern der Rufaufbau statt findet. - RINGCHECK wurde gefixt, da awk in Spalte 5 den Wert IncomingReceived erwartet hat, aber dort ein Pipe kam. IncomingReceived ist in Spalte 6.
This commit is contained in:
parent
772989185a
commit
c9e5be5048
1 changed files with 45 additions and 63 deletions
108
run.py
108
run.py
|
|
@ -1,4 +1,4 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python3
|
||||||
import RPi.GPIO as GPIO
|
import RPi.GPIO as GPIO
|
||||||
import time
|
import time
|
||||||
import os
|
import os
|
||||||
|
|
@ -6,77 +6,59 @@ import sys
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
GPIO.setmode(GPIO.BCM)
|
PinForkIn = 12
|
||||||
GPIO.setup(26,GPIO.IN, pull_up_down = GPIO.PUD_UP)
|
PinForkOut = 20
|
||||||
GPIO.setup(21,GPIO.OUT)
|
PinDialIn = 26
|
||||||
GPIO.setup(6,GPIO.IN, pull_up_down = GPIO.PUD_UP)
|
PinDialOut = 21
|
||||||
GPIO.setup(20,GPIO.OUT)
|
PinWecker = 17 # Command Pin to turn on/off the relay.
|
||||||
GPIO.setmode(GPIO.BCM)
|
Hits = 10 # How many times should the bell be hit by the hammer?
|
||||||
GPIO.setup(17, GPIO.OUT)
|
HitsSleep = 0.06 # Sleep between every hit.
|
||||||
|
Dialcountdown = 500 # time until to dial the call in ms
|
||||||
|
|
||||||
os.system('linphonecsh exit')
|
|
||||||
|
GPIO.setmode(GPIO.BCM)
|
||||||
|
GPIO.setup(PinDialIn,GPIO.IN, pull_up_down = GPIO.PUD_UP)
|
||||||
|
GPIO.setup(PinDialOut,GPIO.OUT)
|
||||||
|
GPIO.setup(PinForkOut,GPIO.OUT)
|
||||||
|
GPIO.setup(PinForkIn,GPIO.IN, pull_up_down = GPIO.PUD_UP)
|
||||||
|
GPIO.setmode(GPIO.BCM)
|
||||||
|
GPIO.setup(PinWecker, GPIO.OUT)
|
||||||
|
|
||||||
|
os.system('/usr/bin/linphonecsh exit')
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
os.system('linphonecsh init')
|
os.system('/usr/bin/linphonecsh init')
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
os.system('linphonecsh soundcard playback')
|
os.system('/usr/bin/linphonecsh soundcard playback')
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
os.system('linphonecsh soundcard ring')
|
os.system('/usr/bin/linphonecsh soundcard ring')
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
os.system('linphonecsh register --username <Nummer> --host hg.eventphone.de --password <password>')
|
os.system('linphonecsh register --username $(sed -n 1p /boot/sip.txt) --host $(sed -n 2p /boot/sip.txt) --password $(sed -n 3p /boot/sip.txt)')
|
||||||
|
|
||||||
def wecker():
|
def wecker():
|
||||||
GPIO.output(17, 1)
|
for _ in range(Hits):
|
||||||
time.sleep(0.04)
|
GPIO.output(PinWecker, 1)
|
||||||
GPIO.output(17, 0)
|
time.sleep(HitsSleep)
|
||||||
time.sleep(0.04)
|
GPIO.output(PinWecker, 0)
|
||||||
GPIO.output(17, 1)
|
time.sleep(HitsSleep)
|
||||||
time.sleep(0.04)
|
|
||||||
GPIO.output(17, 0)
|
|
||||||
time.sleep(0.04)
|
|
||||||
GPIO.output(17, 1)
|
|
||||||
time.sleep(0.04)
|
|
||||||
GPIO.output(17, 0)
|
|
||||||
time.sleep(0.04)
|
|
||||||
GPIO.output(17, 1)
|
|
||||||
time.sleep(0.04)
|
|
||||||
GPIO.output(17, 0)
|
|
||||||
time.sleep(0.04)
|
|
||||||
GPIO.output(17, 1)
|
|
||||||
time.sleep(0.04)
|
|
||||||
GPIO.output(17, 0)
|
|
||||||
time.sleep(0.04)
|
|
||||||
GPIO.output(17, 1)
|
|
||||||
time.sleep(0.04)
|
|
||||||
GPIO.output(17, 0)
|
|
||||||
time.sleep(0.04)
|
|
||||||
GPIO.output(17, 1)
|
|
||||||
time.sleep(0.04)
|
|
||||||
GPIO.output(17, 0)
|
|
||||||
time.sleep(0.04)
|
|
||||||
GPIO.output(17, 1)
|
|
||||||
time.sleep(0.04)
|
|
||||||
GPIO.output(17, 0)
|
|
||||||
time.sleep(0.04)
|
|
||||||
|
|
||||||
|
|
||||||
def hangup():
|
def hangup():
|
||||||
FORK = GPIO.input(6)
|
FORK = GPIO.input(PinForkIn)
|
||||||
if FORK == 1:
|
if FORK == 1:
|
||||||
os.system('linphonecsh generic terminate')
|
os.system('linphonecsh generic terminate')
|
||||||
time.sleep(0.0001)
|
time.sleep(0.0001)
|
||||||
else:
|
else:
|
||||||
GPIO.input(6)
|
GPIO.input(PinForkIn)
|
||||||
|
|
||||||
def answer():
|
def answer():
|
||||||
FORK = GPIO.input(6)
|
FORK = GPIO.input(PinForkIn)
|
||||||
if FORK == 1:
|
if FORK == 1:
|
||||||
os.system("linphonecsh generic \"answer $(linphonecsh generic 'calls' | sed -n 4p | awk '{print $1}')\"")
|
os.system("linphonecsh generic \"answer $(linphonecsh generic 'calls' | sed -n 4p | awk '{print $1}')\"")
|
||||||
time.sleep(0.0001)
|
time.sleep(0.0001)
|
||||||
else:
|
else:
|
||||||
GPIO.input(6)
|
GPIO.input(PinForkIn)
|
||||||
|
|
||||||
def dialnumber():
|
def dialnumber():
|
||||||
DIAL = GPIO.input(26)
|
DIAL = GPIO.input(PinDialIn)
|
||||||
NOM = 0
|
NOM = 0
|
||||||
timeout = False
|
timeout = False
|
||||||
countdown = 100
|
countdown = 100
|
||||||
|
|
@ -85,7 +67,7 @@ def dialnumber():
|
||||||
countdown = countdown -1
|
countdown = countdown -1
|
||||||
if DIAL != 1:
|
if DIAL != 1:
|
||||||
if NOM == 0:
|
if NOM == 0:
|
||||||
DIAL = GPIO.input(26)
|
DIAL = GPIO.input(PinDialIn)
|
||||||
else:
|
else:
|
||||||
if NOM == 10:
|
if NOM == 10:
|
||||||
print("0", end='')
|
print("0", end='')
|
||||||
|
|
@ -96,27 +78,27 @@ def dialnumber():
|
||||||
elif DIAL == 1:
|
elif DIAL == 1:
|
||||||
NOM = NOM +1
|
NOM = NOM +1
|
||||||
time.sleep(0.109)
|
time.sleep(0.109)
|
||||||
DIAL = GPIO.input(26)
|
DIAL = GPIO.input(PinDialIn)
|
||||||
countdown = 500
|
countdown = Dialcountdown
|
||||||
timeout = True
|
timeout = True
|
||||||
|
|
||||||
def CALL():
|
def CALL():
|
||||||
FORK = GPIO.input(6)
|
FORK = GPIO.input(PinForkIn)
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
if FORK == 1:
|
if FORK == 1:
|
||||||
FORK = GPIO.input(6)
|
FORK = GPIO.input(PinForkIn)
|
||||||
time.sleep(0.0001)
|
time.sleep(0.0001)
|
||||||
RINGCHECK = 'linphonecsh generic \'calls\' | sed -n 4p | awk \'{print $5}\''
|
RINGCHECK = 'linphonecsh generic \'calls\' | sed -n 4p | awk \'{print $6}\''
|
||||||
RINGVALUE = subprocess.check_output(['bash', '-c', RINGCHECK ]).decode().strip()
|
RINGVALUE = subprocess.check_output(['bash', '-c', RINGCHECK ]).decode().strip()
|
||||||
if RINGVALUE == 'IncomingReceived':
|
if RINGVALUE == 'IncomingReceived':
|
||||||
wecker()
|
wecker()
|
||||||
FORK = GPIO.input(6)
|
FORK = GPIO.input(PinForkIn)
|
||||||
time.sleep(0.0001)
|
time.sleep(0.0001)
|
||||||
else:
|
else:
|
||||||
FORK = GPIO.input(6)
|
FORK = GPIO.input(PinForkIn)
|
||||||
time.sleep(0.0001)
|
time.sleep(0.0001)
|
||||||
else:
|
else:
|
||||||
FORK = GPIO.input(6)
|
FORK = GPIO.input(PinForkIn)
|
||||||
CMD = 'linphonecsh generic "answer $(linphonecsh generic \'calls\' | sed -n 4p | awk \'{print $1}\')"'
|
CMD = 'linphonecsh generic "answer $(linphonecsh generic \'calls\' | sed -n 4p | awk \'{print $1}\')"'
|
||||||
VALUE = subprocess.check_output(['bash', '-c', CMD ]).decode().strip()
|
VALUE = subprocess.check_output(['bash', '-c', CMD ]).decode().strip()
|
||||||
if VALUE == 'There are no calls to answer.':
|
if VALUE == 'There are no calls to answer.':
|
||||||
|
|
@ -129,13 +111,13 @@ def CALL():
|
||||||
f.close()
|
f.close()
|
||||||
os.system('linphonecsh dial $(cat dial.txt)')
|
os.system('linphonecsh dial $(cat dial.txt)')
|
||||||
else:
|
else:
|
||||||
FORK = GPIO.input(6)
|
FORK = GPIO.input(PinForkIn)
|
||||||
answer()
|
answer()
|
||||||
while FORK == 0:
|
while FORK == 0:
|
||||||
FORK = GPIO.input(6)
|
FORK = GPIO.input(PinForkIn)
|
||||||
time.sleep(0.001)
|
time.sleep(0.001)
|
||||||
else:
|
else:
|
||||||
FORK = GPIO.input(6)
|
FORK = GPIO.input(PinForkIn)
|
||||||
hangup()
|
hangup()
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue