FHEM Forum

FHEM - Hausautomations-Systeme => Sonstige Systeme => Thema gestartet von: otto am 26 Dezember 2015, 15:10:32

Titel: Anpassung sendWhatsApp , sendTextsecureLog
Beitrag von: otto am 26 Dezember 2015, 15:10:32
Hallo habe immer  Textsecure verwendet will aber nur noch WhatsApp verwenden aber bekomme es einfach nicht hin einen text auszulesen und in zu versenden.

So hatte ich es bei Textsecure:
{ sendTextsecureLog("+49xxxxxxxxxxxxx", "/opt/fhem/log/Seriell.txt", 10) }

99_myUtils.pm:

sub sendTextsecureLog($$$)
{
   my ($nr, $logfile,$numlines) = @_;
   my $dir = getcwd();
   my $Message="BMA Otto";
   my $line;
   chdir "/opt/fhem/ts/";
   my $bw = File::ReadBackwards->new( $logfile ) or return "can't read 'log_file' $!" ;
   while ($numlines >0 and defined($line= $bw->readline ) ) {
     $numlines--;
     $Message=$line.$Message;
   }
   Log 3, "sendTextsecure  Nr: ". $nr . " Message:\x22" . $Message . "\x22 ";
   #Direkter Aufruf
   system("/opt/textsecure/bin/textsecure -to=\"$nr\" -message=\"$Message\"");
   chdir "$dir";
}
So hab ichs bei WhatsApp:
{ sendWhatsApp("49xxxxxxxxxxxxx", "/opt/fhem/log/Seriell.txt") }

99_myUtils.pm:
sub sendWhatsApp($$){
  my ($nr,$Message) = @_;

  my $retWhatsApp = qx(sudo python /opt/yowsup-master/yowsup-cli demos -c /opt/yowsup-config/yowsup.config -s $nr '$Message' 2\>&1 &);

  $retWhatsApp =~ s/\n|\r/ /g; #s,[\r\n]*,,g;        # remove CR from return-string

  Log3 "sendWhatsApp", 3, "sendWhatsApp: $retWhatsApp";

  # restart echo client
  $retWhatsApp = system("sudo python /opt/yowsup-master/yowsup-cli demos -c /opt/yowsup-config/yowsup.config -e &");

  return $retWhatsApp;
}
:-[Ich weiß das die 99_myUtils.pm falsch ist, aber nicht was allems hab schon einiges probiert aber...

Gruß otto
Titel: Antw:Anpassung sendWhatsApp , sendTextsecureLog
Beitrag von: justme1968 am 26 Dezember 2015, 15:16:03
gibt es irgendeinen bestimmten grund das du nicht einfach das yowsup modul verwendest ?

gruss
  andre
Titel: Antw:Anpassung sendWhatsApp , sendTextsecureLog
Beitrag von: otto am 26 Dezember 2015, 16:01:50
wie meinst das ?
mit dem versendet doch WhatsApp ?
(my $retWhatsApp = qx(sudo python /opt/yowsup-master/yowsup-cli demos -c /opt/yowsup-config/yowsup.config -s $nr '$Message' 2\>&1 &);
)
oder versteh ich das Falsch ?

Gruß otto
Titel: Antw:Anpassung sendWhatsApp , sendTextsecureLog
Beitrag von: justme1968 am 26 Dezember 2015, 16:21:03
es gibt ein yowsup modul in FHEM.
Titel: Antw:Anpassung sendWhatsApp , sendTextsecureLog
Beitrag von: otto am 26 Dezember 2015, 16:35:55
OK dacht das wäre es sowiso ?

Aber wie würde das Versenden eines Textes dan gehen , aus einer Datei raus ?

Gruß Otto
Titel: Antw:Anpassung sendWhatsApp , sendTextsecureLog
Beitrag von: justme1968 am 26 Dezember 2015, 17:09:44
ZitatOK dacht das wäre es sowiso ?
was ist was sowieso? du verwendest kein fhem modul. vielleicht schaust du mal hier: http://fhem.de/commandref.html#yowsup (http://fhem.de/commandref.html#yowsup) und hier: http://www.fhemwiki.de/wiki/Yowsup (http://www.fhemwiki.de/wiki/Yowsup).

das senden geht dann zum beispiel so:fhem( "set yowsup send $nr $Message" );oder so fhem( "set xyz send $Message" );

ansonsten musst du dein file natürlich genau so auslesen wie in deiner textsecure routine.

gruss
  andre
Titel: Antw:Anpassung sendWhatsApp , sendTextsecureLog
Beitrag von: otto am 26 Dezember 2015, 17:50:27
Mit dem Befehl:
{ sendWhatsApp("49xxxxxxxxx", "/opt/fhem/log/Seriell.txt",10) }


Und der 99_Utils.pm:

sub sendWhatsApp($$$)
{
  my ($nr, $logfile,$numlines) = @_;
   my $dir = getcwd();
   my $Message="BMA Test";
   my $line;
my $bw = File::ReadBackwards->new( $logfile ) or return "can't read 'log_file' $!" ;
   while ($numlines >0 and defined($line= $bw->readline ) ) {
     $numlines--;
     $Message=$line.$Message;
   }
  my $retWhatsApp = qx(sudo python /opt/yowsup-master/yowsup-cli demos -c /opt/yowsup-config/yowsup.config -s $nr '$Message' 2\>&1 &);

  $retWhatsApp =~ s/\n|\r/ /g; #s,[\r\n]*,,g;        # remove CR from return-string

  Log3 "sendWhatsApp", 3, "sendWhatsApp: $retWhatsApp";
# restart echo client
  $retWhatsApp = system("sudo python /opt/yowsup-master/yowsup-cli demos -c /opt/yowsup-config/yowsup.config -e &");

  return $retWhatsApp;
}

So  funktioniert es !!!



Gruß otto
Titel: Antw:Anpassung sendWhatsApp , sendTextsecureLog
Beitrag von: otto am 30 Dezember 2015, 22:05:12
Tooll  seit heut Abend stürtzt das Ding immer ab beim senden
kommt ein :
sendWhatsApp: INFO:yowsup.demos.sendclient.layer:Message sent  Yowsdown

bei dieser Art zu senden erstellt Yowsup eine datei (  /root/.yowsup/49xxxxx/axolotl.db )
bei der anderen Art zu Senden set 49xxxxxxxxxx send Licht2 ist nun aus
wird die Datei ( /opt/fhem/.yowsup/4xxxxxxxxx/axolotl.db ) erstellt.

an was kann das liegen  ab auch ein Update von Fhem gemacht bring leider auch nichts ?

(Kann das mit irgendwelchen Rechten zu tun haben ,
habe GPiO nachinstalliert da war was mit rechten
Fhem2Fhem und RFHEM hab ich auch noch eingebunden.)

suderos:
root   ALL=(ALL:ALL) ALL
%sudo   ALL=(ALL:ALL) ALL
fhem    ALL=(ALL) NOPASSWD: ALL
pi ALL=(ALL) NOPASSWD: ALL

/boot/config.txt ein:
# activating device tree debugging (use: sudo vcdbg log msg)
dtdebug=on

Gruß Otto
Titel: Antw:Anpassung sendWhatsApp , sendTextsecureLog
Beitrag von: otto am 01 Januar 2016, 03:58:49
Hallo hab mal alles neu installiert,jetzt sendet er schon einmal und bringt dann:
sendWhatsApp: INFO:yowsup.demos.sendclient.layer:Message sent  Yowsdown

"sendWhatsApp" funktioniert jedesmal aber WhatsApp wird dabei jedesmal ausgeschaltet und kann nichts empfangen bzw.
"set 49xxxxxxxxxx send Licht2 ist nun aus"
geht auch nicht ?
warum geht WhatsApp aus ?

Gruß otto
Titel: Antw:Anpassung sendWhatsApp , sendTextsecureLog
Beitrag von: otto am 04 Januar 2016, 00:15:35
Jetzt geht er wieder nicht ??
016.01.03 23:43:29 2: WhatsApp: setting $HOME to /opt/fhem
2016.01.03 23:43:29 2: WhatsApp: starting yoswup-cli: /opt/yowsup-master/yowsup-cli demos -c /opt/yowsup-config/yowsup.config --yowsup
2016.01.03 23:46:27 1: PERL WARNING: Use of uninitialized value $string in substitution (s///) at ./FHEM/99_Utils.pm line 144.

das die Fehlermeldung was soll ich noch tun ?

GRuß otto
Titel: Antw:Anpassung sendWhatsApp , sendTextsecureLog
Beitrag von: otto am 05 Januar 2016, 00:42:11
Ok eines hab ich gefunden warum es jetzt gar nicht mehr gesendet hat war in 99_myUtils.pm zusätzlich:
sub
WhatsAppNotify($) {

  my $CallerNr = shift;

  my $Sender = ReadingsVal("WhatsApp", "Phone", "none");
  my $Message = ReadingsVal("WhatsApp", "Message", "none");

  my $MeldText = "";
  my $ret = "";

  if($Sender eq $CallerNr) {
     Log3 "WhatsAppNotify", 3, "WhatsApp (WhatsAppNotify): Sender $Sender definied: $Message";
     $ret = fhem($Message);
     if($ret) {
       Log3 "WhatsAppNotify", 3, "WhatsApp (WhatsAppNotify): Sender $Sender action: $Message - error action: $ret";
       $MeldText = "WhatsApp (WhatsAppNotify): Sender $Sender action: $Message - error action: $ret";
       sendWhatsApp($CallerNr,$MeldText);
     } else {
       Log3 "WhatsAppNotify", 3, "WhatsApp (WhatsAppNotify): Sender $Sender action: $Message - action: Ok";
       $MeldText = "WhatsApp (WhatsAppNotify): Sender $Sender action: $Message - action: Ok";
      [color=red] sendWhatsApp[/color]($CallerNr,$MeldText);
     }
  } else {
     Log3 "WhatsAppNotify", 3, "WhatsApp (WhatsAppNotify): $CallerNr Sender $Sender not definied: $Message";
  }
}

und hat das [color=red]sendWhatsApp[/color] reagiert und nicht das (sub sendWhatsApp($$$))
aber trotzdem geht WhatsApp Offline nach dem senden  ?
Das steht im log bei verbose 5

2016.01.05 00:34:23 5: Cmd: >{ sendWhatsApp("49xxxxxxxxxxx", "/opt/fhem/log/Seriell.txt",10) }<
Traceback (most recent call last):
  File "/opt/yowsup-master/yowsup-cli", line 323, in <module>
    if not parser.process():
  File "/opt/yowsup-master/yowsup-cli", line 229, in process
    self.startEcho()
  File "/opt/yowsup-master/yowsup-cli", line 265, in startEcho
    stack.start()
  File "/opt/yowsup-master/yowsup/demos/echoclient/stack.py", line 48, in start
    self.stack.loop()
  File "/opt/yowsup-master/yowsup/stacks/yowstack.py", line 195, in loop
    asyncore.loop(*args, **kwargs)
  File "/usr/lib/python2.7/asyncore.py", line 216, in loop
    poll_fun(timeout, map)
  File "/usr/lib/python2.7/asyncore.py", line 156, in poll
    read(obj)
  File "/usr/lib/python2.7/asyncore.py", line 87, in read
    obj.handle_error()
  File "/usr/lib/python2.7/asyncore.py", line 83, in read
    obj.handle_read_event()
  File "/usr/lib/python2.7/asyncore.py", line 449, in handle_read_event
    self.handle_read()
  File "/opt/yowsup-master/yowsup/layers/network/layer.py", line 86, in handle_read
    self.receive(data)
  File "/opt/yowsup-master/yowsup/layers/network/layer.py", line 94, in receive
    self.toUpper(data)
  File "/opt/yowsup-master/yowsup/layers/__init__.py", line 59, in toUpper
    self.__upper.receive(data)
  File "/opt/yowsup-master/yowsup/layers/stanzaregulator/layer.py", line 28, in receive
    self.processReceived()
  File "/opt/yowsup-master/yowsup/layers/stanzaregulator/layer.py", line 51, in processReceived
    self.processReceived()
  File "/opt/yowsup-master/yowsup/layers/stanzaregulator/layer.py", line 48, in processReceived
    self.toUpper(oneMessageData)
  File "/opt/yowsup-master/yowsup/layers/__init__.py", line 59, in toUpper
    self.__upper.receive(data)
  File "/opt/yowsup-master/yowsup/layers/auth/layer_crypt.py", line 63, in receive
    self.toUpper(payload)
  File "/opt/yowsup-master/yowsup/layers/__init__.py", line 59, in toUpper
    self.__upper.receive(data)
  File "/opt/yowsup-master/yowsup/layers/coder/layer.py", line 35, in receive
    self.toUpper(node)
  File "/opt/yowsup-master/yowsup/layers/__init__.py", line 59, in toUpper
    self.__upper.receive(data)
  File "/opt/yowsup-master/yowsup/layers/logger/layer.py", line 14, in receive
    self.toUpper(data)
  File "/opt/yowsup-master/yowsup/layers/__init__.py", line 59, in toUpper
    self.__upper.receive(data)
  File "/opt/yowsup-master/yowsup/layers/axolotl/layer.py", line 126, in receive
    self.toUpper(protocolTreeNode)
  File "/opt/yowsup-master/yowsup/layers/__init__.py", line 59, in toUpper
    self.__upper.receive(data)
  File "/opt/yowsup-master/yowsup/layers/__init__.py", line 169, in receive
    s.receive(data)
  File "/opt/yowsup-master/yowsup/layers/__init__.py", line 105, in receive
    recv(node)
  File "/opt/yowsup-master/yowsup/layers/protocol_receipts/layer.py", line 17, in recvReceiptNode
    self.toUpper(IncomingReceiptProtocolEntity.fromProtocolTreeNode(node))
  File "/opt/yowsup-master/yowsup/layers/__init__.py", line 59, in toUpper
    self.__upper.receive(data)
  File "/opt/yowsup-master/yowsup/layers/interface/interface.py", line 98, in receive
    self.callbacks[entityType](entity)
  File "/opt/yowsup-master/yowsup/demos/echoclient/layer.py", line 31, in onReceipt
    ack = OutgoingAckProtocolEntity(entity.getId(), "receipt", "delivery")
TypeError: __init__() takes at least 5 arguments (4 given)


Kann das irgentwie mit python2.6 /  python2.7 zusammen hängen ?
Gruß otto