fehler im eigenen Modul

Begonnen von thp.privat, 08 Juli 2014, 14:43:49

Vorheriges Thema - Nächstes Thema

thp.privat

Hallo,

ich werde noch wahnsinnig. Ich habe mir ein kleines Modul geschrieben, um auf einer Webseite etwas auszulesen. Der im folgenden gepostete Code ist weit davon entfernt fertig zu sein. Mein Problem dreht sich um die folgende Fehlermeldung:

Undefined subroutine &main::DISCOVERGY_Set called at fhem.pl line 2857.

Ich verzweifle noch daran. Ich habe den Hash $hash->{SetFn} entsprechend gesetzt und die sub definiert (s. Code)

anbei der Code:


package main;

use strict;
use warnings;
use Blocking;
use POSIX;
use IO::Socket::INET;
use IO::Socket::SSL;
use MIME::Base64;

# Vereinbarungsteil
sub DISCOVERGY_Initialize($);
sub DISCOVERGY_Define($$);
sub DISCOVERGY_Set($@);
sub DISCOVERGY_Get($@);
sub DISCOVERGY_GetUpdate($);
sub DISCOVERGY_getFilefromURL($);
sub DISCOVERGY_ParseJsonFile($);
sub DISCOVERGY_UpdateAborted($);


# Modulversion
my $modulVersion = "2014-04-29";

sub ##########################################################################
DISCOVERGY_Initialize($)
{
my ($hash) = @_;


$hash->{DefFn} = "DISCOVERGY_Define";
$hash->{UndefFn}  = "DISCOVERGY_Undefine";
$hash->{SetFn}    = "DISCOVERGY_Set";
  $hash->{GetFn}    = "DISCOVERGY_Get";

$hash->{AttrFn} = "DISCOVERGY_Attr";
$hash->{AttrList} = "encUser ".
  "encPassword ".
  $readingFnAttributes;

}

sub ##########################################################################
DISCOVERGY_Define($$)
{
# Paramter aus Übergabehash extrahieren
my ($hash, $def) = @_;
  my @args = split("[ \t][ \t]*", $def);
  my $test = substr $args[2], 0, 10;

#alle Pflichtparamter gefüllt?
return "Usage: define <name> DISCOVERGY <MeterID> <interval:300-900>" if (@args != 4);
return "$test seems not to be a valid Discovergy-MeterID. <MeterID> should start with 'EASYMETER_'" if ($test ne "EASYMETER_");
return "invalid Value for <interval>, please specify a value between 300 and 900" if (int($args[3]) < 300 || int($args[3]) > 900);

# Paramter aus Übergabe füllen
my $name = $args[0];
my $meterID = $args[2];
my $interval = $args[3];



# Rückgabe an FHEM

$hash->{NAME} = $name;
$hash->{STATE} = "Initializing...";
$hash->{NOTIFYDEV}  = "global";
$hash->{INTERVAL}   = $interval;
$hash->{meterID} = $meterID;

RemoveInternalTimer($hash);
  #Get first data after 13 seconds
  #InternalTimer(gettimeofday() + 13, "DISCOVERGY_GetUpdate", $hash, 0) if $interval > 0;

$hash->{fhem}{modulVersion} = $modulVersion;
  Log3 $hash,5,"$name: 70_DISCOVERGY.pm version is $modulVersion.";

return undef;
} #end DISCOVERGY_Define

sub ##########################################################################
DISCOVERGY_Undefine($$)
{
my ( $hash, $arg ) = @_; 
# evtl hier Dateien löschen     
return undef;                 
} #end DISCOVERGY_Undefine   

sub ##########################################################################
DISCOVERGY_Attr(@)
{
my ($cmd,$name,$aName,$aVal) = @_;
  # $cmd can be "del" or "set"
# $name is device name
# aName and aVal are Attribute name and value





return undef;         
} #end DISCOVERGY_Attr



sub ##########################################################################
DISCOVERGY_Set($@);
{
  my ($hash, @a) = @_;
  my $name = $hash->{NAME};
  my $cmd = $a[1];
  my $val = $a[2];
  my $resultStr = "";
 
  if($cmd eq 'statusRequest')
  {
    $hash->{LOCAL} = 1;
    DISCOVERGY_GetUpdate($hash);
    $hash->{LOCAL} = 0;
    return undef;
  }elsif($cmd eq 'INTERVAL' && int(@_)==4 ) {
      $val = 10 if( $val < 10 );
      $hash->{INTERVAL}=$val;
      return "$name: Polling interval set to $val seconds.";
   }
 
 
  my $list = "statusRequest:noArg"
  ." INTERVAL:slider,300,600,900";
 
 
  return "Unknown argument $cmd, choose one of $list";
 



} #end sub DISCOVERGY_Set

sub ##########################################################################
DISCOVERGY_Get($@)
{
  my ($hash, $name, $cmd) = @_;
  my $result;
  my $message;
 
 



my $list = "jsonFile:noArg";
           
  return "Unknown argument $cmd, choose one of $list";


} #end DISCOVERGY_Get


sub ##########################################################################
DISCOVERGY_getUpdate($)
{
my ($hash) = @_;
my $name = $hash->{NAME};




$hash->{helper}{RUNNING_PID} = BlockingCall("DISCOVERGY_getFilefromURL", $name,
                                          #"DISCOVERGY_ParseJsonFile",
                                          " ",
                                          10,
                                          "DISCOVERGY_UpdateAborted", $hash)
                                unless(exists($hash->{helper}{RUNNING_PID}));


return undef;         
} #end DISCOVERGY_getUpdate

sub ##########################################################################
DISCOVERGY_getFilefromURL($)
{
my($hash) = @_;
my $name = $hash->{NAME};
my $encUser = $attr{$name}{"encUser"};
my $encPassword = $attr{$name}{"encPassword"};
my $meterID = $hash->{meterID};
my $interval = $hash->{INTERVAL};
my $pathString  = "/json/Api.getLive?user=".decode_base64($encUser)."&password=".decode_base64($encPassword)."&meterId=".$meterID."&numOfSeconds=".$interval;
my $message = "";
my $buf = "";



my $client = IO::Socket::SSL->new('my.discovergy.com:443');
       
    if (!$client)
    {
    Log3 $name, 1, "$name Error: Could not open connection to my.discovergy.com:443";
      return "$name|0|Can't connect to my.discovergy.com:443";
    }
   
    if (defined ($client) and $client and $client->connected())
   {
      print $client "GET /$pathString HTTP/1.0\r\n\r\n";
      Log3 $name, 4, "$name: Get json file from https://my.discovergy.com:443";
      $client->autoflush(1);
      while ((read $client, $buf, 1024) > 0)
      {
         $message .= $buf;
      }
      Log3 $name, 5, "$name: received:\n $message";
      $client->close();
      Log3 $name, 4, "$name: Socket closed";
      if ($message =~ /^HTTP\/1.\d 404 Not Found/) {
           return "$name|0|Error: URL 'https://my.discovergy.com:443' returned 'Error 404: Page Not Found'";
      }

      #$message = encode_base64($message,"");

      return "$name|1|$message" ;
   }
   




} #end DISCOVERGY_getFilefromURL

sub ##########################################################################
DISCOVERGY_UpdateAborted($)
{
my ($hash) = @_;
  delete($hash->{helper}{RUNNING_PID});
  my $name = $hash->{NAME};

Log3 $hash, 1, "$name Error: Timeout when connecting to host https://my.discovergy.com:443";


} #end DISCOVERGY_UpdateAborted



1;



Wie gesagt, das Modul ist lange noch nicht fertig, aber wenn ich schon beim Set scheitere brauche ich gar nicht weiter zu machen.

Vielen Dank an alle, die sich da reinlesen!

vbs

sub ##########################################################################
DISCOVERGY_Set($@);
{

Entferne mal das Semikolon in der zweiten Zeile. Durch das Semikolon fehlt im IMHO die Implementierung der Funktion.

thp.privat

ja, das wird es sein! Ich teste das dann heute mal.

Vielen Dank!