Hallo zusammen,
passend zum Thread https://forum.fhem.de/index.php/topic,12606.15.html (https://forum.fhem.de/index.php/topic,12606.15.html)
ich möchte genau das gleiche tun, nur bei mir ist es eine Telefonanlage deren Relais ich mit Telnet-Befehlen schalten kann.
Bei mir sieht das so aus:
Datei 99_myUtils.pm
Zitat
Hipath_MP12_Kanal_3_einschalten()
use Net::Telnet();
my $tab = new Net::Telnet (Timeout => 50,Port => 5012);
#my $fh1 = $tab->dump_log("telnetclient.txt"); <-- macht zum debuggen Sinn.
#my $fh2 = $tab->input_log("telnetclient_input.txt"); <-- macht zum debuggen Sinn.
#my $fh3 = $tab->output_log("telnetclient_output.txt"); <-- macht zum debuggen Sinn.
$tab->open("192.168.79.10");
$tab->print("*903");
Es kommt eine Fehlermeldung:
Zitat
"use" not allowed in expression at ./FHEM/99_myUtils.pm line 3, at end of line syntax error at ./FHEM/99_myUtils.pm line 3, near ") use Net::Telnet"
Wo ist mein Denkfehler?
Danke für Eure Gedanken!
Wenn das wirklich der Inhalt Deiner myUtils ist, dann ist sie schlicht mehrfach verkehrt :)
https://wiki.fhem.de/wiki/99_myUtils_anlegen
Hi Otto,
Danke für den Hinweis, so hatte ich es auch schon mal, in dem anderen Thread stand halt "...alles löschen..".
Es kommt eine neue Fehlermeldung:
Zitat"use" not allowed in expression at ./FHEM/99_myUtils.pm line 20, at end of line syntax error at ./FHEM/99_myUtils.pm line 20, near ") use Net::Telnet"
Datei 99_myUtils.pm:
Zitat
##############################################
# $Id: myUtilsTemplate.pm 21509 2020-03-25 11:20:51Z rudolfkoenig $
#
# Save this file as 99_myUtils.pm, and create your own functions in the new
# file. They are then available in every Perl expression.
package main;
use strict;
use warnings;
sub
myUtils_Initialize($$)
{
my ($hash) = @_;
}
# Enter you functions below _this_ line.
Hipath_MP12_Kanal_3_einschalten()
use Net::Telnet();
my $tab = new Net::Telnet (Timeout => 50);
#my $fh1 = $tab->dump_log("telnetclient.txt"); <-- macht zum debuggen Sinn.
#my $fh2 = $tab->input_log("telnetclient_input.txt"); <-- macht zum debuggen Sinn.
#my $fh3 = $tab->output_log("telnetclient_output.txt"); <-- macht zum debuggen Sinn.
$tab->open("192.168.79.10");
$tab->print("*903");
1;
Es kann bzw wird so sein dass ich die Zusammenhänge nicht verstehe bin aber auch lernwillig und würde mich über einen Tipp / Link zu den Grundstrukturen wirklich freuen (vielleicht mit Beispielen). Danke!
Es steht doch aber in dem Wiki Artikel wie man es macht? :o
Du musst eine Perl sub (https://perldoc.perl.org/functions/sub)erstellen:
sub
NameDerSub {
hier steht Dein Perlcode
}
Du schreibst stattdessen einfach nur Text in eine Datei ::) - ok nicht ganz. Dir fehlen jetzt noch die {Klammern} um den Perlblock ;) und das Schlüsselwort vorweg.
use Net::Telnet();
use Net::Telnet;
Und wie Otto schon schrieb du musst eine Perlsub schreiben.