Modul für Lidl/Aldi Internetradio Basis Silvercrest Sird 14A2 "FSAPI"

Begonnen von AK-868, 12 Januar 2015, 17:06:17

Vorheriges Thema - Nächstes Thema

schroediman

#15
Hallo zusammen, ich hab das Modul auch mal getestet.
Zuerst hatte ich keine Chance überhaupt von dem Radio eine SessionID zubekommen. Dann hab ich den Sourcecode mal mit dem Browsertest aus dem Beitrag von AK-868 verglichen und mir ist aufgefallen, das zumindest bei mir der Port in den http-Zugriffen fehlte. Nach dem ich dann aus z.B.

my $xmlre = CustomGetFileFromURL($hash, "http://".$hash->{IP}."/fsapi/CREATE_SESSION?pin=".$hash->{PASSWORD}, 2, "", 0, $logLevel);

folgendes gemacht habe:

my $xmlre = CustomGetFileFromURL($hash, "http://".$hash->{IP}.":80/fsapi/CREATE_SESSION?pin=".$hash->{PASSWORD}, 2, "", 0, $logLevel);

,natürlich bei jeder Abfrage, konnte ich mein Radio auch fernbedienen. Ich habs übrigens über WLAN "angeschlossen".

Generell kann ich nur sagen weiter so.

Wenns ums Testen geht bin ich dabei.

Ich hab noch ein paar BrowserTests gemacht:

Achtung IP und SID anpassen  8) :o

Dies sollte den vergebenen Namen aus der Webseite zurückliefern
http://192.168.1.32:80/fsapi/GET/netRemote.sys.info.friendlyName?pin=1234&sid=xxxxxxxx

Die Radio-Id
http://192.168.1.32:80/fsapi/GET/netRemote.sys.info.radioId?pin=1234&sid=xxxxxxx

Die aktuelle Lautstärke
http://192.168.1.32:80/fsapi/GET/netRemote.sys.audio.volume?pin=1234&sid=xxxxxx

Abspielstatus
http://192.168.1.32:80/fsapi/GET/netRemote.play.status?pin=1234&sid=xxxxxxxx  0=IDLE;1=BUFFERING;2=PLAYING;3=PAUSED

Im DAB-Modus der Sendername
http://192.168.1.32:80/fsapi/GET/netRemote.play.info.name?pin=1234&sid=xxxxxxxx

Eigentlich selbst erklärend:
http://192.168.1.32:80/fsapi/GET/netRemote.play.info.text?pin=1234&sid=xxxxxxxx

ich mach mal morgen (heute) weiter

MfG

Schroediman 8)

automatisierer

#16
Hi schroediman,
in diesem Post ist eine Seite verlinkt auf der schon einige Steuerkomandos aufgelistet sind.
http://forum.fhem.de/index.php/topic,31430.msg242811.html#msg242811

Ich bin auch die ganze Zeit schon am rum Basteln, hab allerdings mal noch keinen dollen Plan von Perl. Somit gestaltet sich die Fehlersuche für mich ein wenig schwierig. Aber ich bleib dran...

Gruß
Ingo


schroediman

#17
Hi Ingo,

durch die Post in diesem Thread, hab ich zumindest schon einmal  die Befehle in der Android-App gefunden. Ich hatte die mal in java-sourcecode umgewandelt und war bis jetzt etwas etwas überfordert, da ich dachte ich muss das Radio über upnp ansteuern.

Dadurch denke ich ich schick Dir mal meine Daten als PN. 8)

Kann man da überhaupt was anhängen?

automatisierer

Hallöchen,
das Problem das meine Befehle nicht durch gehen hab ich (zumindest bei mir) gelöst.

Ich bin auf der Suche nach Lösungen über folgenden Thread gestolpert:

http://forum.fhem.de/index.php/topic,26246.msg192553.html#msg192553

Das hab ich mal eben in meine 17_SIRD.pm eingebaut und nun funzt alles.

CustomGetFileFromURL($hash, "http://".$hash->{IP}.":80/fsapi/SET/netRemote.sys.power?pin=".$hash->{PASSWORD}."&sid=".$hash->{SESSIONID}."&value=1", 2, "", 1, $logLevel);

den Wert für noshutdown hab ich von 0 auf 1 gesetzt.

Gruß
Ingo


schroediman

#19


HI,
ich hab mal ein bischen weiter getüfftelt. Der Weg ist noch sehr lang aber son bischen geht jetzt.



package main;

use strict;
use warnings;
use HttpUtils;
use XML::Simple qw(:strict);

sub
SIRD_Initialize($)
{
  my ($hash) = @_;
  $hash->{Clients}   = ":EGPM:";
  $hash->{GetFn}     = "SIRD_Get";
  $hash->{SetFn}     = "SIRD_Set";
  $hash->{DefFn}     = "SIRD_Define";
  $hash->{AttrList}  = ""
}

###################################
sub
SIRD_Get($@)
{
    my ($hash, @a) = @_;
    my $what;

    return "argument is missing" if(int(@a) != 2);
   
    $what = $a[1];
   
    if($what =~ /^(STATE|lastcommand)$/)
    {
      if(defined($hash->{READINGS}{$what}))
      {
   return $hash->{READINGS}{$what}{VAL};
  }
      else
  {
   return "reading not found: $what";
  }
    }
    else
    {
  return "Unknown argument $what, choose one of STATE:noArg lastcommand:noArg ".(exists($hash->{READINGS}{output})?" output:noArg":"");
    }
}

##SET#################################
sub
SIRD_Set($@)
{
  my ($hash, @a) = @_;

  return "no set value specified" if(int(@a) < 2);
  return "Unknown argument $a[1], choose one of Power:On,Off volume:slider,0,1,20 Mode:InternetRadio,NetworkPlayer,DAB-Radio,FM-Radio,AUX RemoteState:On,Off clearreadings:noArg FriendlyNameRequest:noArg VersionRequest:noArg InfoTextRequest:noArg InfoNameRequest:noArg ".
         "FrequencyRequest:noArg SignalStrengthRequest:noArg" if($a[1] eq "?");

  my $name = shift @a;
  my $setcommand = shift @a;
  my $params = join(" ", @a);
  my $helper = 0;
  my $logLevel = GetLogLevel($name,4);
  Log $logLevel, "SIRD set $name (". $hash->{IP}. ") $setcommand $params";

   eval{ CustomGetFileFromURL($hash, "http://".$hash->{IP}.":80/fsapi/GET_NOTIFIES?pin=".$hash->{PASSWORD}."&sid=".$hash->{SESSIONID}, 2, "", 1, $logLevel);
   };
   
  if ($@){
  ### catch block
  SIRD_Login($hash, $logLevel);
  };
 
  if($setcommand eq "Power")
  {
if ($params eq "On")
{
$helper = 1;
}
elsif ($params eq "Off")
{
$helper = 0;
}
else
{
Log 1, "SIRD Command POWER wrong Parameter: ".$params;
return 0;
}
eval{
CustomGetFileFromURL($hash, "http://".$hash->{IP}.":80/fsapi/SET/netRemote.sys.power?pin=".$hash->{PASSWORD}."&sid=".$hash->{SESSIONID}."&value=".$helper, 2, "", 1, $logLevel);

  };
  if ($@){
  ### catch block
  Log 1, "SIRD Login error: $@";
  return 0;
  };
  SIRD_GetPower($hash, $logLevel);
  } 
 
  elsif($setcommand eq "Mode")
  {
if ($params eq "InternetRadio")
{
$helper = 0;
}
elsif ($params eq "NetworkPlayer")
{
$helper = 1;
}
elsif ($params eq "DAB-Radio")
{
$helper = 2;
}
elsif ($params eq "FM-Radio")
{
$helper = 3;
}
elsif ($params eq "AUX")
{
$helper = 4;
}
else
{
Log 1, "SIRD Command Mode wrong Parameter: ".$params;
return 0;
}
eval{
CustomGetFileFromURL($hash, "http://".$hash->{IP}.":80/fsapi/SET/netRemote.sys.mode?pin=".$hash->{PASSWORD}."&sid=".$hash->{SESSIONID}."&value=".$helper, 2, "", 1, $logLevel);
  };
 
  if ($@){
  ### catch block
  Log 1, "SIRD Login error: $@";
  return 0;
  };

SIRD_GetInput($hash, $logLevel);
 
  } 
  elsif($setcommand eq "volume")
  {
eval{ 
CustomGetFileFromURL($hash, "http://".$hash->{IP}.":80/fsapi/SET/netRemote.sys.audio.volume?pin=".$hash->{PASSWORD}."&sid=".$hash->{SESSIONID}."&value=".$params, 2, "", 1, $logLevel);
  };

  ## Lautstärke zurücklesen
SIRD_GetVolume($hash,$logLevel);
if ($@){
  ### catch block
  Log 1, "SIRD Login error: $@";
  return 0;
  };
  }
  elsif($setcommand eq "RemoteState")
  {
if ($params eq "On")
{
$helper = 1;
}
elsif ($params eq "Off")
{
$helper = 0;
}
else
{
Log 1, "SIRD Command RemoteState wrong Parameter: ".$params;
return 0;
}
eval{ 
CustomGetFileFromURL($hash, "http://".$hash->{IP}.":80/fsapi/SET/netRemote.nav.state?pin=".$hash->{PASSWORD}."&sid=".$hash->{SESSIONID}."&value=".$helper, 2, "", 1, $logLevel);
  };
  if ($@){
  ### catch block
  Log 1, "SIRD Login error: $@";
  return 0;
  };
  SIRD_GetRemoteState($hash, $logLevel);
  }
 
   elsif($setcommand eq "FriendlyNameRequest" )
  {
   SIRD_GetFriendlyName($hash, $logLevel);
  }
  elsif($setcommand eq "VersionRequest")
  {
   SIRD_GetVersion($hash, $logLevel);
  }

elsif($setcommand eq "InfoTextRequest")
  {
   SIRD_GetInfoText($hash, $logLevel);
  }
  elsif($setcommand eq "InfoNameRequest")
  {
   SIRD_GetInfoName($hash, $logLevel);
  }
  elsif($setcommand eq "FrequencyRequest")
  {
   SIRD_GetFrequency($hash, $logLevel);
  }
  elsif($setcommand eq "SignalStrengthRequest")
  {
   SIRD_GetSignalStrength($hash, $logLevel);
  }
  elsif($setcommand eq "clearreadings")
  {
   delete $hash->{READINGS};
  }
  else
  {
     return "unknown argument $setcommand, choose one of on, off, toggle, statusrequest, clearreadings";
  }
 
  SIRD_Logoff($hash, $logLevel);

  $hash->{CHANGED}[0] = $setcommand;
  $hash->{READINGS}{lastcommand}{TIME} = TimeNow();
  $hash->{READINGS}{lastcommand}{VAL} = $setcommand." ".$params;
 
  return undef;
}

###############################
sub SIRD_Switch($$$$) {
  my ($hash, $state, $port, $logLevel) = @_;
  $state = ($state eq "on" ? "1" : "0");
 
  my $fritz = 0; #may be important for FritzBox-users
  my $data = "cte1=" . ($port == "1" ? $state : "") . "&cte2=" . ($port == "2" ? $state : "") . "&cte3=" . ($port == "3" ? $state : "") . "&cte4=". ($port == "4" ? $state : "");
  Log $logLevel, "SIRD $data";
  eval {                 
    CustomGetFileFromURL($hash ,"http://".$hash->{IP}."/",10 ,$data ,$fritz ,$logLevel);
  };
  if ($@){
    ### catch block
    Log $logLevel, "SIRD error: $@";
  };

  return 1;
}
###############################
sub SIRD_Login($$) {
  my ($hash, $logLevel) = @_;

  Log $logLevel,"SIRD try to Login @".$hash->{IP};

  eval{
    my $response = CustomGetFileFromURL($hash, "http://".$hash->{IP}.":80/fsapi/CREATE_SESSION?pin=".$hash->{PASSWORD}, 2, "", 1, $logLevel);
my $ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);

if ($ref->{status} == 'FS_OK')
{
$hash->{SESSIONID} = $ref->{sessionId};
Log $logLevel,"SIRD Login successful!";
};
};
if ($@) {
      ### catch block
      Log 1, "SIRD Login error: $@";
      return 0;
};   
return 1;
}
###############################
sub SIRD_GetStatus($$) {
  my ($hash, $local) = @_;
  my $name = $hash->{NAME};
  my $IP = $hash->{IP};
  my $logLevel = GetLogLevel($name);
 
  #if $local is set to 1 just fetch informations from device without interrupting InternalTimer
  $local = 0 unless(defined($local));
  InternalTimer(gettimeofday()+$hash->{INTERVAL}, "SIRD_GetStatus", $hash,0) unless($local == 1);
 
  return "" if(!defined($hash->{IP}) or !defined($hash->{INTERVAL}));
   
  eval{ CustomGetFileFromURL($hash, "http://".$hash->{IP}.":80/fsapi/GET_NOTIFIES?pin=".$hash->{PASSWORD}."&sid=".$hash->{SESSIONID}, 2, "", 1, $logLevel);
  };
   
  if ($@){
  ### catch block
  SIRD_Login($hash, $logLevel);
  };
  SIRD_GetPower($hash, $logLevel);
  if ($hash->{STATE} eq 'on')
  {
 
SIRD_GetVolume($hash, $logLevel);
SIRD_GetInput($hash, $logLevel);
SIRD_GetInfoName($hash, $logLevel);
SIRD_GetInfoText($hash, $logLevel);
SIRD_GetRemoteState($hash, $logLevel);
SIRD_GetPlayStatus($hash, $logLevel);

  }
else
{
  delete $hash->{READINGS};
}
 
  return undef;
}
###############################
sub SIRD_GetPower($$) {
  my ($hash, $logLevel) = @_;
  my $name = $hash->{NAME};
  my $response = CustomGetFileFromURL($hash, "http://".$hash->{IP}.":80/fsapi/GET/netRemote.sys.power?pin=".$hash->{PASSWORD}."&sid=".$hash->{SESSIONID}, 2, "", 1, $logLevel);
  my $ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);

  ## Überprüfen ob Abfrage in Ordnung war
  if ($ref->{status} == 'FS_OK')
  {
if (int($ref->{value}->{u8}) == 1)
{
$hash->{STATE} = 'on';
}
else
{
$hash->{STATE} = 'off';
}
  }
   return undef;
}
###############################
sub SIRD_GetVolume($$) {
  my ($hash, $logLevel) = @_;
  my $name = $hash->{NAME};
  my $response = CustomGetFileFromURL($hash, "http://".$hash->{IP}.":80/fsapi/GET/netRemote.sys.audio.volume?pin=".$hash->{PASSWORD}."&sid=".$hash->{SESSIONID}, 2, "", 1, $logLevel);
  my $ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);

  ## Überprüfen ob Abfrage in Ordnung war
  if ($ref->{status} == 'FS_OK')
  {
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "volume", $ref->{value}->{u8}, 1);
readingsEndUpdate($hash, 0);
  }
   return undef;
}
###############################
sub SIRD_GetFriendlyName($$) {
  my ($hash, $logLevel) = @_;
  my $name = $hash->{NAME};
  my $response = CustomGetFileFromURL($hash, "http://".$hash->{IP}.":80/fsapi/GET/netRemote.sys.info.friendlyName?pin=".$hash->{PASSWORD}."&sid=".$hash->{SESSIONID}, 2, "", 1, $logLevel);
  my $ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
 
  if ($ref->{status} == 'FS_OK')
  {
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "friendlyName", $ref->{value}->{c8_array}, 1);
readingsEndUpdate($hash, 0);
  }
   return undef;
}
###############################
sub SIRD_GetVersion($$) {
  my ($hash, $logLevel) = @_;
  my $name = $hash->{NAME};
  my $response = CustomGetFileFromURL($hash, "http://".$hash->{IP}.":80/fsapi/GET/netRemote.sys.info.version?pin=".$hash->{PASSWORD}."&sid=".$hash->{SESSIONID}, 2, "", 1, $logLevel);
  my $ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
 
  if ($ref->{status} == 'FS_OK')
  {
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "Version", $ref->{value}->{c8_array}, 1);
readingsEndUpdate($hash, 0);
  }
  return undef;
}
###############################
sub SIRD_GetInfoName($$) {
  my ($hash, $logLevel) = @_;
  my $name = $hash->{NAME};
  my $response = CustomGetFileFromURL($hash, "http://".$hash->{IP}.":80/fsapi/GET/netRemote.play.info.name?pin=".$hash->{PASSWORD}."&sid=".$hash->{SESSIONID}, 2, "", 1, $logLevel);
  my $ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
 
  if ($ref->{status} == 'FS_OK')
  {
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "InfoName", $ref->{value}->{c8_array}, 1);
readingsEndUpdate($hash, 0);
  }
  return undef;
}
###############################
sub SIRD_GetInfoText($$) {
  my ($hash, $logLevel) = @_;
  my $name = $hash->{NAME};
  my $response = CustomGetFileFromURL($hash, "http://".$hash->{IP}.":80/fsapi/GET/netRemote.play.info.text?pin=".$hash->{PASSWORD}."&sid=".$hash->{SESSIONID}, 2, "", 1, $logLevel);
  my $ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
   
  if ($ref->{status} == 'FS_OK')
  {   
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "InfoText", $ref->{value}->{c8_array}, 1);
readingsEndUpdate($hash, 0);
  }
  return undef;
}
###############################
sub SIRD_GetFrequency($$) {
  my ($hash, $logLevel) = @_;
  my $name = $hash->{NAME};
  my $response = CustomGetFileFromURL($hash, "http://".$hash->{IP}.":80/fsapi/GET/netRemote.play.frequency?pin=".$hash->{PASSWORD}."&sid=".$hash->{SESSIONID}, 2, "", 1, $logLevel);
  my $ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
   
  if ($ref->{status} == 'FS_OK')
  {
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "Frequency", $ref->{value}->{u32}, 1);
readingsEndUpdate($hash, 0);
  }
   return undef;
}
###############################
sub SIRD_GetSignalStrength($$) {
  my ($hash, $logLevel) = @_;
  my $name = $hash->{NAME};
  my $response = CustomGetFileFromURL($hash, "http://".$hash->{IP}.":80/fsapi/GET/netRemote.play.signalStrength?pin=".$hash->{PASSWORD}."&sid=".$hash->{SESSIONID}, 2, "", 1, $logLevel);
  my $ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
   
  if ($ref->{status} == 'FS_OK')
  {
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "Signalstrength", $ref->{value}->{u8}, 1);
readingsEndUpdate($hash, 0);
  }
   return undef;
}
###############################
sub SIRD_GetRemoteState($$) {
  my ($hash, $logLevel) = @_;
  my $name = $hash->{NAME};
  my $response = CustomGetFileFromURL($hash, "http://".$hash->{IP}.":80/fsapi/GET/netRemote.nav.state?pin=".$hash->{PASSWORD}."&sid=".$hash->{SESSIONID}, 2, "", 1, $logLevel);
  my $ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
 
  if ($ref->{status} == 'FS_OK')
  {
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "RemoteState", $ref->{value}->{u8}, 1);
readingsEndUpdate($hash, 0);
  }
 
   return undef;
}
###############################
sub SIRD_GetInput($$) {
  my ($hash, $logLevel) = @_;
  my $name = $hash->{NAME};
  my $response = CustomGetFileFromURL($hash, "http://".$hash->{IP}.":80/fsapi/GET/netRemote.sys.mode?pin=".$hash->{PASSWORD}."&sid=".$hash->{SESSIONID}, 2, "", 1, $logLevel);
  my $ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
   
  if ($ref->{status} == 'FS_OK')
  {
readingsBeginUpdate($hash);
if (int($ref->{value}->{u32}) == 0)
{
readingsSingleUpdate($hash, "input", "InternetRadio", 1);
}
elsif (int($ref->{value}->{u32}) == 1)
{
readingsSingleUpdate($hash, "input", "NetzworkPlayer", 1);
}
elsif (int($ref->{value}->{u32}) == 2)
{
readingsSingleUpdate($hash, "input", "DAB-Radio" , 1);
}
elsif (int($ref->{value}->{u32}) == 3)
{
readingsSingleUpdate($hash, "input", "FM-Radio", 1);
}
elsif (int($ref->{value}->{u32}) == 4)
{
readingsSingleUpdate($hash, "input", "AUX", 1);
}
else
{
readingsSingleUpdate($hash, "input", "Unknown", 1);
}

readingsEndUpdate($hash, 0);
  }
  return undef;
}
###############################
sub SIRD_GetNotify($$){
my ($hash, $logLevel) = @_;
  my $name = $hash->{NAME};
  my $response = CustomGetFileFromURL($hash, "http://".$hash->{IP}.":80/fsapi/GET_NOTIFIES?pin=".$hash->{PASSWORD}."&sid=".$hash->{SESSIONID}, 2, "", 1, $logLevel);
  my $ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
   
  if ($ref->{status} == 'FS_OK')
  {
# to be done
  }
  return undef;
}
###############################
sub SIRD_GetPlayStatus($$){
my ($hash, $logLevel) = @_;
  my $name = $hash->{NAME};
  my $response = CustomGetFileFromURL($hash, "http://".$hash->{IP}.":80/fsapi/GET/netRemote.play.status?pin=".$hash->{PASSWORD}."&sid=".$hash->{SESSIONID}, 2, "", 1, $logLevel);
  my $ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);

  if ($ref->{status} == 'FS_OK')
  {
readingsBeginUpdate($hash);
if (int($ref->{value}->{u8}) == 0)
{
readingsSingleUpdate($hash, "PlayStatus", "IDLE", 1);
}
elsif (int($ref->{value}->{u8}) == 1)
{
readingsSingleUpdate($hash, "PlayStatus", "BUFFERING", 1);
}
elsif (int($ref->{value}->{u8}) == 2)
{
readingsSingleUpdate($hash, "PlayStatus", "PLAYING", 1);
}
elsif (int($ref->{value}->{u8}) == 3)
{
readingsSingleUpdate($hash, "PlayStatus", "PAUSED", 1);
}
elsif (int($ref->{value}->{u8}) == 4)
{
readingsSingleUpdate($hash, "PlayStatus", "REBUFFERING", 1);
}
elsif (int($ref->{value}->{u8}) == 5)
{
readingsSingleUpdate($hash, "PlayStatus", "ERROR", 1);
}
else
{
readingsSingleUpdate($hash, "PlayStatus", "Unknown", 1);
}

readingsEndUpdate($hash, 0);
  }
  return undef;
}
###############################
sub SIRD_Logoff($$) {
  my ($hash, $logLevel) = @_;

  #$quiet, $url, $timeout, $data, $noshutdown, $loglevel
  CustomGetFileFromURL($hash, "http://".$hash->{IP}.":80/login.html", 10, "", 1, $logLevel);
  return 1;
}
###############################
sub SIRD_Define($$) {
  my ($hash, $def) = @_;
  my @a = split("[ \t][ \t]*", $def);

  my $u = "wrong syntax: define <name> SIRD IP Password [interval]";
  return $u if(int(@a) < 3);
   
  $hash->{IP} = $a[2];
  if(int(@a) == 5 || int(@a) == 4)
  {
    $hash->{PASSWORD} = $a[3]; 
  }
  else
  {
    $hash->{PASSWORD} = "";
  }
  my $result = SIRD_Login($hash, 3);
  if($result == 1)
  {
    $hash->{STATE} = "initialized";
   
  }
  if(defined($a[4]) and $a[4] > 10) {
    $hash->{INTERVAL}=$a[4];
  }
  else{
    $hash->{INTERVAL}=30;
  }
  InternalTimer(gettimeofday()+10, "SIRD_GetStatus", $hash,0);
  return undef;
}

1;

automatisierer

#20
Moin,

ich habs leider grad erst gesehen. Ich hab den CODE grad mal eingefügt, danach stürzte mein FHEM ab. Ich probiere mal weiter, allerdings nicht vor Dienstag.

Gruß
Ingo

EDIT:
habs nochmal versucht. Erst mal kamen beim Start von FHEM ein paar Fehlermeldungen. hab an ein paar Stellen das == in ein eq geändert.
Dann nochmal gestartet. Die Steuerung ging für einen kurzen Moment, danach stürzte FHEM dann wieder ab...



schroediman

Hi,

ich habe vergessen zu schreiben das jetzt das folgende Perl Modul gebraucht wird: XML::Simple
bei debian mal als root "apt-get install libxml-simple-perl" eingeben.

Wenn hinterher Listen abgeholt werden erspart das einiges an Code um die Senderlisten / Dateilisten aus dem XML einzulesen.

MfG

Sebastian

automatisierer

#22
daran lags nicht... 8)
ich mache mir grad mal ne "saubere" FHEM Installation...

EDIT:
auf der FHEM neuinstallation läuft alles ganz fein!! hut ab!!

2.EDIT:
nachdem es auf der Neuinstallation lief, hab ich es nochmal auf meinem "lebenden" FHEM versucht.
Ich habe alle Radios bis auf eins deaktiviert, dann lief es. Mit dem zweiten Radio gings auch noch.
Als ich dann alle vier aktiviert hab, stürzte das System nach nem rereadcfg ab.
Tippe mal, dass da nen bissl viel arbeit für den kleinen bananapi entsteht...

steht bei apptime auch mal ganz oben auf der Liste:


                                name             function    max  count    total  average maxDly
                  tmr-SIRD_GetStatus      HASH(0x2e81320)   2679     10    22093  2209.30     16 HASH(Kueche_Radio)



So, für mehr hab ich aber nu wirklich keine Zeit, muss mich jetzt mal wieder zum Arbeiten zwingen...


3.EDIT:

Ich kann die Finger doch nicht davon lassen...

Mein versuchs FHEM (auf Raspi) ist zwischenzeitlich auch schon einmal abgschmiert.

Das ist immer der letzte Log-Eintrag:
2015.02.02 15:15:52 2: CustomGetFileFromURL <hidden>: Can't connect(1) to http://192.168.170.170:80: IO::Socket::INET: connect: timeout


4.EDIT:
ich verbinde mich per ssh zum raspi mit dem versuchs FHEM, wenn ich da weg FHEM neu starte, kommt folgende Fehlermeldung vor dem Absturz:

Could not find fhem.xml in ./ at ./FHEM/17_SIRD.pm line 330

Und in der Line 330 Steht:

  my $ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);

Gleiche Meldung kam mit verschiedenen line Angaben (z.B. 397) immer der gleiche Zeileninhalt.


schroediman

#23
HI Ingo,

zum 2. EDIT.
   Evtl spielen da die 2 sekunden timeout in den HttPabfragen mit rein. werd das mal bei mir prüfen, lieg da auch bei ähnlichen Werten.

zum 3. Edit
  hat das Radio immer die gleiche IP ? 
  Das Radio scheint nicht am Netz zu sein.
  wenn die HTTP-Kommunikation gestört ist dann keine Werte für die xMLin und dann die Meldung.
muss noch abgefangen werden.


Ich bin noch meilenweit davon entfernt dass das vernünftig funzt!
MfG

Sebastian

automatisierer

Hallo Sebastian,

die Radios haben immer die gleiche IP und sind auch so eingestellt, dass sie die WLAN Verbindung halten auch wenn sie aus sind (also Standby).

Ich überprüfe grad mal meine Perl Installation, nicht das da der Fehler liegt...


Ich bin von dem was du da geschaffen hast schon mal völlig überwältigt, dafür das du "nur testen" wolltest... weiter so!! Ich werd mich mal in deinen Code einlesen, vielleicht verstehe ich ihn ja... ::)

Gruß
Ingo

AK-868

Hallo zusammen,

ich bin jetzt auch wieder einigermaßen auf dem Damm und kann auch wieder was machen.

Ich werde mal euren Code ausprobieren.

Bin gespannt.

Donnerstag kommt die neue Version in den LIDL.

Hardware FHEM:
Neue Fritzbox 7390 keine Labor von AVM
Konfigurationsadapter Lan
Funk-Schließerkontaktschnittstellen
Funk-Fenster/Türkontakt
Funk-Schaltaktoren UP ein und zweifach
Funk-Jalousieaktoren
Funk-Rauchmelder


AK-868

@Schroediman

volumeStraight müssen wir wieder einbauen.
Volume muss dann in % eingebaut werden.


Oder generell an dem  halten:

http://www.fhemwiki.de/wiki/DevelopmentGuidelinesAV

Studiere weiter den Code ;)
Hardware FHEM:
Neue Fritzbox 7390 keine Labor von AVM
Konfigurationsadapter Lan
Funk-Schließerkontaktschnittstellen
Funk-Fenster/Türkontakt
Funk-Schaltaktoren UP ein und zweifach
Funk-Jalousieaktoren
Funk-Rauchmelder


AK-868

Das mit den Variablen hatte ich auch noch vor.

Get Notifys da bin ich schon bei was rauszubekommen.

Ich weiß nicht wie weit du schon damit bist. Ganz schlau werd ich aus der Seite nicht.

Bei mir füllt sich die XML nur wenn aktionen am Radio getätigt werden. Lade ich die Seit neu ist Sie wieder leer. Zumindest bei mir.

Ich habe die pm aus der Startseite mal aktualisiert und volumeStraight wieder eingebaut... nontestet..

Werde mich morgen abend mal an das Volume in % machen.

Ebenso versuch ich rauszufinden wie man durch die Radios navigiert.
Hardware FHEM:
Neue Fritzbox 7390 keine Labor von AVM
Konfigurationsadapter Lan
Funk-Schließerkontaktschnittstellen
Funk-Fenster/Türkontakt
Funk-Schaltaktoren UP ein und zweifach
Funk-Jalousieaktoren
Funk-Rauchmelder


schroediman

#28
Hallo zusammen,

1. ja das mit den Guidelines hab ich auch schon gemerkt.

2. Ich hoffe ich hab die Probleme von Automatisierer behoben, in dem ich schaue ob die Antwort vom Radio wie xml aussieht. Erkennen ob das Radio unter der IP-verfügbar ist sollte er auch ohne Absturz.

3. notify bin ich noch dran, aber das funktioniert so: in der XML sind alle Werte der Notifyfähigen Nodes die sich seit dem letzten Notify-abruf geändert haben. Ändert sich nichts ist die xml sehr uninformativ.  : 8)


MfG

Schroedimann










package main;

use strict;
use warnings;
use HttpUtils;
use XML::Simple qw(:strict);
use Time::HiRes qw(gettimeofday sleep);

sub
SIRD_Initialize($)
{
  my ($hash) = @_;
  $hash->{Clients}   = ":EGPM:";
  $hash->{GetFn}     = "SIRD_Get";
  $hash->{SetFn}     = "SIRD_Set";
  $hash->{DefFn}     = "SIRD_Define";
  $hash->{AttrList}  = ""
}

###################################
sub SIRD_Get($@)
{
    my ($hash, @a) = @_;
    my $what;
my $helper= "";

    return "argument is missing" if(int(@a) != 2);
   
    $what = $a[1];
   
    if($what =~ /^(lastcommand|power|presence|volume|volumeStraight|mute|repeat|shuffle|input|currentArtist|currentAlbum|currentTitle|playStatus|state)$/)
    {
if(defined($hash->{READINGS}{$what}))
{
   return $hash->{READINGS}{$what}{VAL};
}
else
{
if ($what eq "state")
{
if ($hash->{READINGS}{"presence"}{VAL} ne "absent")
{
$helper = $hash->{READINGS}{"power"}{VAL};
}
else
{
$helper = $hash->{READINGS}{"presence"}{VAL};
}
return $helper;
}
else
{
return "reading not found: $what";
}

}
}
   
   
return "Unknown argument $what, choose one of lastcommand:noArg power:noArg presence:noArg volume:noArg volumeStraight:noArg mute:noArg repeat:noArg shuffle:noArg "
   ."input:noArg currentArtist:noArg currentAlbum:noArg currentTitle:noArg playStatus:noArg state:noArg ".(exists($hash->{READINGS}{output})?" output:noArg":"");

}

##SET#################################
sub SIRD_Set($@)
{
  my ($hash, @a) = @_;

  return "no set value specified" if(int(@a) < 2);
  return "Unknown argument $a[1], choose one of on:noArg off:noArg play:noArg pause:noArg stop:noArg next:noArg previous:noArg ".
"volume:slider,0,1,100 volumeStraight:slider,0,1,20 mute:on,off,toggle input:InternetRadio,MediaPlayer,DAB-Radio,FM-Radio,AUX ".
"statusRequest:noArg RemoteState:on,off clearreadings:noArg FriendlyNameRequest:noArg VersionRequest:noArg InfoTextRequest:noArg InfoNameRequest:noArg ".
         "FrequencyRequest:noArg SignalStrengthRequest:noArg" if($a[1] eq "?");

  my $name = shift @a;
  my $setcommand = shift @a;
  my $params = join(" ", @a);
  my $helper = 0;
  my $logLevel = GetLogLevel($name);
  Log $logLevel, "SIRD set $name (". $hash->{IP}. ") $setcommand $params";

  $helper=SIRD_GetPower($hash);
   
  if (!$helper){
  ### catch block
  SIRD_Login($hash);
  };
 
  if($setcommand eq "on")
  {
eval{
SIRD_Com ($hash,"netRemote.sys.power?pin=",2,1);
};
  if ($@){
  ### catch block
  Log 1, "SIRD Login error: $@";
  return 0;
  };
  SIRD_GetPower($hash);
  }
 
  elsif($setcommand eq "off")
  {
eval{
SIRD_Com ($hash,"netRemote.sys.power?pin=",2,0);
};
  if ($@){
  ### catch block
  Log 1, "SIRD Login error: $@";
  return 0;
  };
  SIRD_GetPower($hash);
  } 
 
  elsif($setcommand eq "input")
  {
if ($params eq "InternetRadio")
{
$helper = 0;
}
elsif ($params eq "MediaPlayer")
{
$helper = 1;
}
elsif ($params eq "DAB-Radio")
{
$helper = 2;
}
elsif ($params eq "FM-Radio")
{
$helper = 3;
}
elsif ($params eq "AUX")
{
$helper = 4;
}
else
{
Log 1, "SIRD Command Mode wrong Parameter: ".$params;
return 0;
}
eval{
SIRD_Com ($hash,"netRemote.sys.mode",2,$helper);
  };
 
  if ($@){
  ### catch block
  Log 1, "SIRD Login error: $@";
  return 0;
  };

SIRD_GetInput($hash);
 
  } 
 
  elsif($setcommand eq "volume")
  {
my $helper = int($params/5);
eval{ 
SIRD_Com ($hash,"netRemote.sys.audio.volume",2,$helper);
  };
if ($@){
  ### catch block
  Log 1, "SIRD Login error: $@";
  return 0;
  };
    ## Lautstärke zurücklesen
SIRD_GetVolume($hash);
  }
 
  elsif($setcommand eq "volumeStraight")
  {
my $helper = int($params);
eval{ 
SIRD_Com ($hash,"netRemote.sys.audio.volume",2,$helper);
  };
  ## Lautstärke zurücklesen

if ($@){
  ### catch block
  Log 1, "SIRD Login error: $@";
  return 0;
  };
  SIRD_GetVolume($hash);
  }
  elsif($setcommand eq "mute")
  {
if ($params eq "on")
{
$helper = 1;
}
elsif ($params eq "off")
{
$helper = 0;
}
elsif ($params eq "toggle")
{
if (ReadingsVal($name, "mute", "0") eq "on")
{
$helper = 0;
}
elsif (ReadingsVal($name, "mute", "0") eq "off")
{
$helper = 1;
}
}
else
{
Log 1, "SIRD Command Mute wrong Parameter: ".$params;
return 0;
}
eval{
SIRD_Com ($hash,"netRemote.sys.audio.mute",2,$helper);

  };
  if ($@){
  ### catch block
  Log 1, "SIRD Login error: $@";
  return 0;
  };
  SIRD_GetMute($hash);
  } 
  elsif($setcommand eq "stop")
  {
eval{
SIRD_Com ($hash,"netRemote.play.control",2,0);
};
if ($@){
  ### catch block
  Log 1, "SIRD Login error: $@";
  return 0;
};
  }
  elsif($setcommand eq "play")
  {
eval{
SIRD_Com ($hash,"netRemote.play.control",2,1);
};
if ($@){
  ### catch block
  Log 1, "SIRD Login error: $@";
  return 0;
};
  }
  elsif($setcommand eq "pause")
  {
eval{
SIRD_Com ($hash,"netRemote.play.control",2,2);
};
if ($@){
  ### catch block
  Log 1, "SIRD Login error: $@";
  return 0;
};
  }
  elsif($setcommand eq "next")
  {
eval{
SIRD_Com ($hash,"netRemote.play.control",2,3);
};
if ($@){
  ### catch block
  Log 1, "SIRD Login error: $@";
  return 0;
};
  }
  elsif($setcommand eq "previous")
  {
eval{
SIRD_Com ($hash,"netRemote.play.control",2,4);
};
if ($@){
  ### catch block
  Log 1, "SIRD Login error: $@";
  return 0;
};
  }
  elsif($setcommand eq "statusRequest" )
  {
   SIRD_GetStatus($hash,1);
  }
  elsif($setcommand eq "RemoteState")
  {
if ($params eq "on")
{
$helper = 1;
}
elsif ($params eq "off")
{
$helper = 0;
}
else
{
Log 1, "SIRD Command RemoteState wrong Parameter: ".$params;
return 0;
}
eval{ 
SIRD_Com ($hash,"netRemote.nav.state",2,$helper);
  };
  if ($@){
  ### catch block
  Log 1, "SIRD Login error: $@";
  return 0;
  };
  SIRD_GetRemoteState($hash);
  }
  elsif($setcommand eq "FriendlyNameRequest" )
  {
   SIRD_GetFriendlyName($hash);
  }
  elsif($setcommand eq "VersionRequest")
  {
   SIRD_GetVersion($hash);
  }
elsif($setcommand eq "InfoTextRequest")
  {
   SIRD_GetInfoText($hash);
  }
  elsif($setcommand eq "InfoNameRequest")
  {
   SIRD_GetInfoName($hash);
  }
  elsif($setcommand eq "FrequencyRequest")
  {
   SIRD_GetFrequency($hash);
  }
  elsif($setcommand eq "SignalStrengthRequest")
  {
   SIRD_GetSignalStrength($hash);
  }
  elsif($setcommand eq "clearreadings")
  {
   delete $hash->{READINGS};
  }
  else
  {
     return "unknown argument $setcommand, choose one of on, off, toggle, statusrequest, clearreadings";
  }
 
  #SIRD_Logoff($hash);

  $hash->{CHANGED}[0] = $setcommand;
  $hash->{READINGS}{lastcommand}{TIME} = TimeNow();
  $hash->{READINGS}{lastcommand}{VAL} = $setcommand." ".$params;
 
  return undef;
}
###############################
sub SIRD_Login($) {
  my ($hash) = @_;
  my $ref;
  Log $hash->{logLevel},"SIRD try to Login @".$hash->{IP};

 
    my $response = SIRD_Com($hash,"CREATE_SESSION?pin=".$hash->{PASSWORD},0,0);
if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);

if ($ref->{status} eq 'FS_OK')
{
$hash->{SESSIONID} = $ref->{sessionId};
Log $hash->{logLevel},"SIRD Login successful!";
};
};
return 1;
}
###############################
sub SIRD_GetStatus($$) {
  my ($hash, $local) = @_;
  my $name = $hash->{NAME};
  my $helper;
  $hash->{logLevel} = GetLogLevel($name);
 
  #if $local is set to 1 just fetch informations from device without interrupting InternalTimer
  $local = 0 unless(defined($local));
  InternalTimer(gettimeofday()+$hash->{INTERVAL}, "SIRD_GetStatus", $hash,0) unless($local == 1);
 
  return "" if(!defined($hash->{IP}) or !defined($hash->{INTERVAL}));
   
  # Prüfen ob SID gültig
  $helper = SIRD_GetPower($hash);

   
  if (!$helper ){
  ### catch block
  SIRD_Login($hash);
  };
  SIRD_GetPower($hash);

  if ($hash->{STATE} eq "on")
  {
 
SIRD_GetVolume($hash);
SIRD_GetMute($hash);
SIRD_GetInput($hash);
SIRD_GetInfoName($hash);
SIRD_GetInfoText($hash);
SIRD_GetRemoteState($hash);
SIRD_GetPlayStatus($hash);
SIRD_GetShuffle($hash);
SIRD_GetRepeat($hash);
SIRD_GetInfoAlbum($hash);
SIRD_GetInfoArtist($hash);
SIRD_GetPlayRate($hash);
SIRD_GetPlayPos($hash);
SIRD_GetInfoDur($hash);
SIRD_GetInfoGraphicURI($hash);
SIRD_GetSignalStrength($hash);


  }
else
{
  #delete $hash->{READINGS};
}
 
  return undef;
}
###############################
sub SIRD_GetPower($) {
#  cachable
#  notifying
  my ($hash) = @_;
  my $response = SIRD_Com($hash,"netRemote.sys.power",1,0);
 
  my $ref;
  my $helper = 'off';
  my $presence = 'absent';
 
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
if ($ref->{value}->{u8} == 1)
{
$helper = 'on';
$presence = 'present';
}
else
{
$helper = 'off';
$presence = 'present';
}
}
    }
else
{
$helper ='off';
$presence = 'absent';
$response =0;
}
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "presence", $presence , 1);
readingsSingleUpdate($hash, "power", $helper , 1);
readingsEndUpdate($hash, 0);
$hash->{STATE} = $helper;


  return $response;
}
###############################
sub SIRD_GetVolume($) {
#  cachable
#  notifying
  my ($hash) = @_;
  my $response = SIRD_Com($hash,"netRemote.sys.audio.volume",1,0);
  my $ref;
  ## Überprüfen ob Abfrage in Ordnung war
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
if ($ref->{status} eq 'FS_OK')
{
readingsBeginUpdate($hash);
# volumeStraight 0 ... 20
readingsSingleUpdate($hash, "volumeStraight", $ref->{value}->{u8}, 1);
# volume 0 ... 100
readingsSingleUpdate($hash, "volume", 5*$ref->{value}->{u8}, 1);
readingsEndUpdate($hash, 0);
}
}
   return undef;
}
###############################
sub SIRD_GetMute($) {
#  cachable
#  notifying
  my ($hash) = @_;
  my $response = SIRD_Com($hash,"netRemote.sys.audio.mute",1,0);
  my $ref ;
  my $helper = 'off';
 
if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
if ($ref->{value}->{u8} == 1)
{
$helper = "on";
}
else
{
$helper = "off";
}
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "mute", $helper , 1);
readingsEndUpdate($hash, 0);
}
}
   return undef;
}
###############################
sub SIRD_GetShuffle($) {

#  notifying
  my ($hash) = @_;
  my $response = SIRD_Com($hash,"netRemote.play.shuffle",1,0);
  my $ref ;
  my $helper = 'off';
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
if ($ref->{value}->{u8} == 1)
{
$helper = 'on';
}
else
{
$helper = 'off';
}
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "shuffle", $helper , 1);
readingsEndUpdate($hash, 0);
}
  }
   return undef;
}
###############################
sub SIRD_GetRepeat($) {

#  notifying
  my ($hash) = @_;
  my $response = SIRD_Com($hash,"netRemote.play.repeat",1,0);
  my $ref ;
  my $helper = 'off';
 
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
if ($ref->{value}->{u8} == 1)
{
$helper = 'on';
}
else
{
$helper = 'off';
}
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "repeat", $helper , 1);
readingsEndUpdate($hash, 0);
}
  }
   return undef;
}
###############################
sub SIRD_GetFriendlyName($) {
  my ($hash) = @_;
  my $response = SIRD_Com($hash,"netRemote.sys.info.friendlyName",1,0);
  my $ref ;
  my $helper = ' ';
 
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
if ( !ref $ref->{value}->{c8_array}) { $helper = $ref->{value}->{c8_array};};
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "friendlyName", SIRD_xml2txt($helper), 1);
readingsEndUpdate($hash, 0);
}
}

  return undef;
}
###############################
sub SIRD_GetVersion($) {
  my ($hash) = @_;
  my $response = SIRD_Com($hash,"netRemote.sys.info.version",1,0);
  my $ref ;
  my $helper = ' ';
 
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
if ( !ref $ref->{value}->{c8_array}) { $helper = $ref->{value}->{c8_array};};
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "version", SIRD_xml2txt($helper), 1);
readingsEndUpdate($hash, 0);
}
}
  return undef;
}
###############################
sub SIRD_GetInfoName($) {
  my ($hash) = @_;
  my $response = SIRD_Com($hash,"netRemote.play.info.name",1,0);
  my $ref ;
  my $helper = ' ';
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
if ( !ref $ref->{value}->{c8_array}) { $helper = $ref->{value}->{c8_array};};
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "currentTitle", SIRD_xml2txt($helper) , 1);
readingsEndUpdate($hash, 0);
}
}
  return undef;
}
###############################
sub SIRD_GetInfoText($) {
  my ($hash) = @_;
  my $response = SIRD_Com($hash,"netRemote.play.info.text",1,0);
  my $ref ;
  my $helper = ' ';
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
if ( !ref $ref->{value}->{c8_array}) { $helper = $ref->{value}->{c8_array};};
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "InfoText", SIRD_xml2txt($helper), 1);
readingsEndUpdate($hash, 0);
}
}
  return undef;
}
###############################
sub SIRD_GetInfoAlbum($) {
  my ($hash) = @_;
  my $response = SIRD_Com($hash,"netRemote.play.info.album",1,0);
  my $ref ;
  my $helper = ' ';
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
if ( !ref $ref->{value}->{c8_array}) { $helper = $ref->{value}->{c8_array};};
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "currentAlbum", SIRD_xml2txt($helper), 1);
readingsEndUpdate($hash, 0);
}
}
  return undef;
}
###############################
sub SIRD_GetInfoArtist($) {
  my ($hash) = @_;
  my $response = SIRD_Com($hash,"netRemote.play.info.artist",1,0);
  my $ref ;
  my $helper = ' ';
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
if ( !ref $ref->{value}->{c8_array}) { $helper = $ref->{value}->{c8_array};};
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "currentArtist", SIRD_xml2txt($helper), 1);
readingsEndUpdate($hash, 0);
}
}
  return undef;
}
##############################
sub SIRD_GetInfoGraphicURI($) {
  my ($hash) = @_;
  my $response = SIRD_Com($hash,"netRemote.play.info.graphicUri",1,0);
  my $ref ;
  my $helper = ' ';
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
if ( !ref $ref->{value}->{c8_array}) { $helper = $ref->{value}->{c8_array};};
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "graphicUri", SIRD_xml2txt($helper), 1);
readingsEndUpdate($hash, 0);
}
}
  return undef;
}
##############################
sub SIRD_GetPlayPos($) {
  my ($hash) = @_;
  my $response = SIRD_Com($hash,"netRemote.play.position",1,0);
  my $ref ;
  my $helper = ' ';
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')

#Zeit von 1000stel Sekunden in Minuten umwandeln xx:yy
$helper = " ".int( $ref->{value}->{u32} / 60000).":".sprintf("%02d", (int( $ref->{value}->{u32} / 1000)-(int( $ref->{value}->{u32} / 60000)*60)));
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "currentPosition", SIRD_xml2txt($helper), 1);
readingsEndUpdate($hash, 0);
}
}
  return undef;
}
##############################
sub SIRD_GetInfoDur($) {
  my ($hash) = @_;
  my $response = SIRD_Com($hash,"netRemote.play.info.duration",1,0);
  my $ref ;
  my $helper = ' ';
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
#Zeit von 1000stel Sekunden in Minuten umwandeln xx:yy
$helper = " ".int( $ref->{value}->{u32} / 60000).":".sprintf("%02d", (int( $ref->{value}->{u32} / 1000)-(int( $ref->{value}->{u32} / 60000)*60)));
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "currentDuration", $helper, 1);
readingsEndUpdate($hash, 0);
}
}
  return undef;
}
###############################
sub SIRD_GetPlayRate($) {
  my ($hash) = @_;
  my $response = SIRD_Com($hash,"netRemote.play.rate",1,0);
  my $ref ;
  my $helper = ' ';
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "playRate", $ref->{value}->{s8}, 1);
readingsEndUpdate($hash, 0);
}
  }
  return undef;
}
###############################
sub SIRD_GetFrequency($) {
  my ($hash) = @_;
  my $response = SIRD_Com($hash,"netRemote.play.frequency",1,0);
  my $ref ;
  my $helper = ' ';
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "Frequency", $ref->{value}->{u32}, 1);
readingsEndUpdate($hash, 0);
}
}
   return undef;
}
###############################
sub SIRD_GetSignalStrength($) {
  my ($hash) = @_;
  my $response = SIRD_Com($hash,"netRemote.play.signalStrength",1,0);
  my $ref ;
  my $helper = ' ';
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "Signalstrength", $ref->{value}->{u8}, 1);
readingsEndUpdate($hash, 0);
}
}
   return undef;
}
###############################
sub SIRD_GetRemoteState($) {
  my ($hash) = @_;
  my $response = SIRD_Com($hash,"netRemote.nav.state",1,0);
  my $ref ;
  my $helper = ' ';
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "RemoteState", $ref->{value}->{u8}, 1);
readingsEndUpdate($hash, 0);
}
}
   return undef;
}
###############################
sub SIRD_GetInput($) {
  my ($hash) = @_;
  my $response = SIRD_Com($hash,"netRemote.sys.mode",1,0);
  my $ref ;
  my $helper = ' ';
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
readingsBeginUpdate($hash);
if (int($ref->{value}->{u32}) == 0)
{
readingsSingleUpdate($hash, "input", "InternetRadio", 1);
}
elsif (int($ref->{value}->{u32}) == 1)
{
readingsSingleUpdate($hash, "input", "MediaPlayer", 1);
}
elsif (int($ref->{value}->{u32}) == 2)
{
readingsSingleUpdate($hash, "input", "DAB-Radio" , 1);
}
elsif (int($ref->{value}->{u32}) == 3)
{
readingsSingleUpdate($hash, "input", "FM-Radio", 1);
}
elsif (int($ref->{value}->{u32}) == 4)
{
readingsSingleUpdate($hash, "input", "AUX", 1);
}
else
{
readingsSingleUpdate($hash, "input", "Unknown", 1);
}
readingsEndUpdate($hash, 0);
}
}
  return undef;
}
###############################
sub SIRD_GetNotify($){
  my ($hash) = @_;
  my $response = SIRD_Com ($hash,"GET_NOTIFIES?pin=".$hash->{PASSWORD}."&sid=".$hash->{SESSIONID},0,0);
  my $ref ;
  my $helper = ' ';
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
if (exists $ref->{"netRemote.sys.power"})
{
if ($ref->{"netRemote.sys.power"}->{value}->{u8} == 1)
{
$helper = "on";
}
else
{
$helper = "off";
}
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "power", $helper , 1);
readingsEndUpdate($hash, 0);
$hash->{STATE} = $helper;
}


if (exists $ref->{"netRemote.sys.audio.volume"})
{
readingsBeginUpdate($hash);
# volumeStraight 0 ... 20
readingsSingleUpdate($hash, "volumeStraigth", $ref->{"netRemote.sys.audio.volume"}->{value}->{u8}, 1);
#  volume 0 ... 100
readingsSingleUpdate($hash, "volume", 5*$ref->{"netRemote.sys.audio.volume"}->{value}->{u8}, 1);
readingsEndUpdate($hash, 0);
}


if (exists $ref->{"netRemote.sys.audio.mute"})
{
if ($ref->{"netRemote.sys.audio.mute"}->{value}->{u8} == 1)
{
$helper = "on";
}
else
{
$helper = "off";
}
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "mute", $helper , 1);
readingsEndUpdate($hash, 0);
}
}
#netRemote.play.repeat
#netRemote.play.shuffle
#netRemote.nav.status
#netRemote.play.status

#to be done
}
  return undef;
}
###############################
sub SIRD_GetPlayStatus($){
  #  cachable
  #  notifying
  my ($hash) = @_;
  my $helper = "unknown";
  my $response = SIRD_Com ($hash,"netRemote.play.status",1,0);
  my $ref ;
  my $helper = ' ';
  if ($response =~ /fsapiResponse/)
{
$ref = XMLin($response, KeyAttr => { }, ForceArray => [ ]);
## Überprüfen ob Abfrage in Ordnung war
if ($ref->{status} eq 'FS_OK')
{
if (int($ref->{value}->{u8}) == 0)
{
$helper = "idle";
}
elsif (int($ref->{value}->{u8}) == 1)
{
$helper = "buffering";
}
elsif (int($ref->{value}->{u8}) == 2)
{
$helper = "playing";
}
elsif (int($ref->{value}->{u8}) == 3)
{
$helper = "paused";
}
elsif (int($ref->{value}->{u8}) == 4)
{
$helper = "rebuffering";
}
elsif (int($ref->{value}->{u8}) == 5)
{
$helper = "error";
}
else
{
$helper =  "unknown";
}
readingsBeginUpdate($hash);
readingsSingleUpdate($hash, "playStatus", $helper, 1);
readingsEndUpdate($hash, 0);
}
}
return undef;
}
###############################
sub SIRD_Logoff($) {
  my ($hash) = @_;

  #$quiet, $url, $timeout, $data, $noshutdown, $loglevel
  #CustomGetFileFromURL($hash, "http://".$hash->{IP}.":80/login.html", 10, "", 0, $hash->{logLevel});
  return 1;
}
###############################
sub SIRD_Define($$) {
  my ($hash, $def) = @_;
  my @a = split("[ \t][ \t]*", $def);

  my $u = "wrong syntax: define <name> SIRD IP Password [interval]";
  return $u if(int(@a) < 3);
   
  $hash->{IP} = $a[2];
  if(int(@a) == 5 || int(@a) == 4)
  {
    $hash->{PASSWORD} = $a[3]; 
  }
  else
  {
    $hash->{PASSWORD} = "";
  }
  $hash->{logLevel} = 3 ;
  my $result = SIRD_Login($hash);
  if($result == 1)
  {
    $hash->{STATE} = "initialized";
   
  }
  if(defined($a[4]) and $a[4] > 10) {
    $hash->{INTERVAL}=$a[4];
  }
  else{
    $hash->{INTERVAL}=30;
  }
  InternalTimer(gettimeofday() + 10, "SIRD_GetStatus", $hash ,0);
  return undef;
}
sub SIRD_Com ($$$$) {

my ($hash, $Command, $mode, $value) = @_;
my $name = $hash->{name};
my $helper ;

my $response = '';
if ($mode==0)  #nonspecific
{
$helper = "http://".$hash->{IP}.":80/fsapi/".$Command;
$response = GetFileFromURL($helper,10,"",1,$hash->{logLevel});
}
elsif($mode==1) # GET
{
$helper = "http://".$hash->{IP}.":80/fsapi/GET/".$Command."?pin=".$hash->{PASSWORD}."&sid=".$hash->{SESSIONID};
$response = GetFileFromURL($helper,2,"",1,$hash->{logLevel});
}
elsif ($mode==2) # SET
{
$helper = "http://".$hash->{IP}.":80/fsapi/SET/".$Command."?pin=".$hash->{PASSWORD}."&sid=".$hash->{SESSIONID}."&value=".$value;
$response = GetFileFromURL($helper,2,"",1,$hash->{logLevel});
}
elsif ($mode==3) # GETLIST
{
$helper = "http://".$hash->{IP}.":80/fsapi/GET/".$Command."?pin=".$hash->{PASSWORD}."&sid=".$hash->{SESSIONID}."&MaxItems=".$value;
$response = GetFileFromURL($helper,2,"",1,$hash->{logLevel});
}
Log3 $hash, $hash->{logLevel}, "SIRD: URL : '$helper' ";
Log3 $hash, $hash->{logLevel}, "SIRD: response from device: '$response' ";
return $response;
}
sub SIRD_xml2txt($)
{
# stolen from   71_YAMAHA_AVR.pm
# sub YAMAHA_AVR_html2txt($)

    my ($string) = @_;
    $string =~ s/&nbsp;/ /g;
    $string =~ s/&amp;/&/g;
    $string =~ s/(\xe4|&auml;)/ä/g;
    $string =~ s/(\xc4|&Auml;)/Ä/g;
    $string =~ s/(\xf6|&ouml;)/ö/g;
    $string =~ s/(\xd6|&Ouml;)/Ö/g;
    $string =~ s/(\xfc|&uuml;)/ü/g;
    $string =~ s/(\xdc|&Uuml;)/Ü/g;
    $string =~ s/(\xdf|&szlig;)/ß/g;
    $string =~ s/<.+?>//g;
    $string =~ s/(^\s+|\s+$)//g;
    return $string;
}
1;



automatisierer

#29
Moin,
habs eingebaut. Läuft mal sauber mit allen vier Radios.

Das LogLevel könnte mal geändert werden, bei 'attr Global verbose 3' wird jede empfangene Nachricht vom Radio geloggt. Und da kommt einiges! :o

Gruß
Ingo


EDIT:

lief gut, auch wenn alle vier Radios an waren,einzig der Seitenaufbau im webif wurde merklich langsamer.

Dann ging mein SatReciever an und das ENIGMA2 Modul kam ins spiel... die Meldungen von 'sudo service fhem start' bis zum Absturz von fhem...

Scalar value @auth[0] better written as $auth[0] at ./FHEM/75_MSG.pm line 147, <$fh> line 196.
Scalar value @auth[1] better written as $auth[1] at ./FHEM/75_MSG.pm line 147, <$fh> line 196.
Use of uninitialized value in localtime at (eval 34) line 1, <> line 269.

"my" variable $helper masks earlier declaration in same scope at ./FHEM/17_SIRD.pm line 975, <> line 3.
No value specified for 'KeyAttr' option in call to XMLin() at ./FHEM/70_ENIGMA2.pm line 1041


Gruß
Ingo