Hallo Leute,
hier noch mal ein Problem an dem ich momentan nicht so richtig weiter komme.
Ich versuche ja eine Torsteuerung zu schreiben, die wenn ein Anruf auf einem Huawei e173 Stick eingeht, in einer Datenbank nachschaut ob der Anrufende berechtigt ist und dann auf einen PiFace 2 Modul ein Relais schaltet dass letztlich das Tor öffnet.
Ich bin das auch schon soweit wie in meinem anderen Beitrag geschrieben, das ich SMS bekommen kann, die ich aber eher zur Steuerung des Programms verwende, also zum Beispiel wenn ich neue Benutzer anlegen möchte, Benutzer sperren möchte das Tor auf offen setze oder die Steuerung aussetze, so das keiner das Tor öffnen kann.
Zum Öffnen des Tores möchte ich einen Anruf interpretieren (Mit Prüfung der Telefonnummer um herauszufinden, ob der Anrufende überhaupt berechtigt ist das Tor zu öffnen)
Dazu habe ich einen Beispielcode gefunden:
#!/usr/bin/env python
import gammu
import time
def Callback(sm, type, data):
'''
This callback receives notification about incoming event.
@param sm: state machine which invoked action
@type sm: gammu.StateMachine
@param type: type of action, one of Call, SMS, CB, USSD
@type type: string
@param data: event data
@type data: hash
'''
print 'Received incoming event type %s, data:' % type
print data
# Create state machine
sm = gammu.StateMachine()
# Read gammurc
sm.ReadConfig()
# Initialize state machine and connect to phone
sm.Init()
# Set callback handler for incoming notifications
sm.SetIncomingCallback(Callback)
# Enable notifications from calls
try:
sm.SetIncomingCall()
except gammu.ERR_NOTSUPPORTED:
print 'Incoming calls notification is not supported.'
# Enable notifications from cell broadcast
try:
sm.SetIncomingCB()
except gammu.ERR_NOTSUPPORTED:
print 'Incoming CB notification is not supported.'
except gammu.ERR_SOURCENOTAVAILABLE:
print 'Cell broadcasts support not enabled in Gammu.'
# Enable notifications from incoming SMS
try:
sm.SetIncomingSMS()
except gammu.ERR_NOTSUPPORTED:
print 'Incoming SMS notification is not supported.'
# Enable notifications for incoming USSD
try:
sm.SetIncomingUSSD()
except gammu.ERR_NOTSUPPORTED:
print 'Incoming USSD notification is not supported.'
# Just a busy waiting for event
# We need to keep communication with phone to get notifications
print 'Press Ctrl+C to interrupt'
while 1:
q = sm.GetSignalQuality()
print 'Signal is at %d%%' % q['SignalPercent']
time.sleep(1)
Alles anzeigen
Der funktioniert auch ohne Probleme, will sagen: Er gibt in der Shell die aus der while Schleife kommenden Meldungen aus:
Press Ctrl+C to interrupt
Signal is at 21%
Signal is at 18%
Signal is at 15%
Signal is at 15%
Signal is at 18%
Aber wenn ein Anruf kommt passiert bis auf ein kurzes Zucken am Bildschirm (In der Shell ruckt es kurz) nix. Ich habe aber ein Freizeichen, und der Stick blinkt, der Anruf liegt also an. Was ich absolut nicht verstehe ist:
Wo in diesem Code wird denn das Event "gemeldet"? Denn in der while Schleife am Ende wird ja nur das Signal gemeldet..
Anscheinend ist dafür ja die Funktion "Callback" zuständig. Aber wie rufe ich die Funktion Callback auf und bekomme mein Event "Anruf" identifiziert?
Wäre da für Hilfe sehr dankbar.
Liebe Grüße
Ralf