IPCam: SendSnapshot funktioniert nicht, nichtmal Log-Eintrag

Begonnen von heikoh81, 24 April 2014, 21:36:44

Vorheriges Thema - Nächstes Thema

heikoh81

Hallo zusammen,

ich möchte bei Bewegungserkennung per Homematic-Bewegungsmelder, dass von einer IPCam 4 Bilder geschossen und per Mail versendet werden.
Hierzu habe ich versucht, das Modul IPCam & SendSnapshot von Markus Fischer zu implementieren.

Dies funktioniert schon:
IpCam funktioniert, und auf dem Raspi werden die 4 Bilder schön bei notify abgelegt, bzw. ggf. überschrieben, falls von einem früheren notify schon welche vorhanden sind.
define MOTION.not.02 notify IPCamAussen:.*snapshots.* { sendSnapshot("%NAME","%EVTPART1") }

Und das funktioniert überhaupt nicht - nichtmal eine Fehlermeldung kommt im Log.
Da ich mich auf meinem Mailserver per Konto & Passwd anmelden muss, habe ich den ursprünglichen Code von der Website von Markus Fischer leicht angepasst.
Außerdem habe ich die dort mehrfach gezeigten "<br>" entfernt, weil die ja wohl zum HTML-Code gehören und vermutlich in der MyUtils nichts zu suchen haben?

99_myUtils.pm
#####Sende Snapshots von IPCam
sub
sendSnapshot(@)
{
  my ($cam,$snapshots) = @_;
  my $storage = AttrVal($cam,"storage","");
  my $rcpt = "xyz\@xyz";
  my $from = "xyz\@xyz";
my $passwrd = "123456789";
my $provider = "xyz.de";
  my $subj = "FHEM: Kamera $cam hat eine Bewegung aufgezeichnet";
  my $last = ReadingsTimestamp($cam,"last","");
  my $mess = "Kamera $cam hat eine Bewegung am $last aufgezeichnet:";
  if(!-d $storage) {
    Log 1, "IPCAM $cam storagepath does not exists: $storage";
    return "storagepath for $cam does not exists: $storage";
  }
  if(!$last) {
    Log 1, "IPCAM $cam no snapshots available";
    return "no snapshots available for $cam";
  }
  my $cmd  = "sendEmail -f '$from' -t '$rcpt' -u '$subj' -m '$mess' -s '$provider' -xu '$from' -xp '$passwrd' -o tls=no";
     $cmd .= "-o message-content-type=text -o message-charset=utf-8 -a";
  for (my $s=1;$s<$snapshots+1;$s++) {
    $cmd .= " $storage/".ReadingsVal($cam,"snapshot$s","");
  }
  my $ret  = '$cmd';
  $ret =~ s/[\r\n]//g;
  Log 4, "IPCAM sendSnapshot: $ret";
  return undef;
}


Senden mittels einer weiteren Funktion "DebianMail" funktioniert übrigens super:

######## DebianMail  Mail auf dem RPi versenden ############
sub
DebianMail
{
my $rcpt = shift;
my $subject = shift;
my $text = shift;
my $ret = "";
my $sender = "xyz\@xyz.de";
my $konto = "xyz\@xyz.de";
my $passwrd = "123456789";
my $provider = "xyz.de";
Log 1, "sendEmail RCP: $rcpt";
Log 1, "sendEmail Subject: $subject";
Log 1, "sendEmail Text: $text";

$ret .= qx(sendEmail -f '$sender' -t '$rcpt' -u '$subject' -m '$text' -s '$provider' -xu '$konto' -xp '$passwrd' -o tls=no);
$ret =~ s,[\r\n]*,,g;    # remove CR from return-string
Log 1, "sendEmail returned: $ret";
}


Was mache ich jetzt noch falsch?

  • Insbesondere bin ich mir nicht sicher, wie z.B. das @ in der Mail-Adresse korrekt in PERL abgebildet wird.
  • Muss ich die Strings mit deutschen Anführungszeichen "" eingeben oder mit zwei Hochkommas ohne Leerzeichen dazwischen?

Vielen Dank für eure Antworten,
viele Grüße,
Heiko

Jan_H

Hallo Heiko,

versuch mal

my $cmd  = "sendEmail -f '$from' -t '$rcpt' -u '$subj' -m '$mess' -s '$provider' -xu '$from' -xp '$passwrd' -o tls=no";
     $cmd .= "-o message-content-type=text -o message-charset=utf-8 -a";


durch
my $cmd  = "sendEmail -f '$from' -t '$rcpt' -u '$subj' -m '$mess' -s '$provider' -xu '$from' -xp '$passwrd' -o tls=no -o message-content-type=text -o message-charset=utf-8 -a";

zu ersetzen.

Dein Aufruf sollte dann:

define MOTION.not.02 notify IPCamAussen:.*snapshots.* { sendSnapshot("IPCamAussen","4") }

lauten, sofern Du in Deiner E-Mail vier Bilder haben möchtest.

Wenn Du dann noch in der drittletzten Zeile Log 4 durch Log 1 ersetzt, siehst Du auch etwas im FHEM-Log.

Gruß
Jan

Maergsche

Zur Vollständigkeit hier noch der funktionierende Code:


#####Sende Snapshots von IPCam
sub
sendSnapshot(@)
{
  my ($cam,$snapshots) = @_;
  my $storage = AttrVal($cam,"storage","");
  my $rcpt = "xyz\@xyz";
  my $from = "xyz\@xyz";
my $passwrd = "123456789";
my $provider = "xyz.de";
  my $subj = "FHEM: Kamera $cam hat eine Bewegung aufgezeichnet";
  my $last = ReadingsTimestamp($cam,"last","");
  my $mess = "Kamera $cam hat eine Bewegung am $last aufgezeichnet:";
  if(!-d $storage) {
    Log 1, "IPCAM $cam storagepath does not exists: $storage";
    return "storagepath for $cam does not exists: $storage";
  }
  if(!$last) {
    Log 1, "IPCAM $cam no snapshots available";
    return "no snapshots available for $cam";
  }
  my $cmd  = "sendEmail -f '$from' -t '$rcpt' -u '$subj' -m '$mess' -s '$provider' -xu '$from' -xp '$passwrd' -o tls=no";
     $cmd .= " -o message-content-type=text -o message-charset=utf-8 -a";
  for (my $s=1;$s<$snapshots+1;$s++) {
    $cmd .= " $storage/".ReadingsVal($cam,"snapshot$s","");
  }
  my $ret  = `$cmd`;
  $ret =~ s/[\r\n]//g;
  Log 4, "IPCAM sendSnapshot: $ret";
  return undef;
}


Korrekturen:
$cmd .= " -o message-content-type=text -o message-charset=utf-8 -a";
my $ret  = `$cmd`;