Autor Thema: HTTPMOD/Device für tp-link TL-SG108PE/ TL-SG116E  (Gelesen 1775 mal)

Offline GunterB

  • New Member
  • *
  • Beiträge: 32
HTTPMOD/Device für tp-link TL-SG108PE/ TL-SG116E
« am: 01 Juli 2021, 13:03:24 »
Getestet mit TL-SG108PE 3.0 und TL-SG116E 2.0
[psw] beim Attribut sid01Data inklusive der eckigen Klammern durch das richtige Passwort ersetzen!

defmod SWITCH3 HTTPMOD http://192.168.0.100/

attr SWITCH3 enableCookies 1
attr SWITCH3 get01Name PortSettingRpm
attr SWITCH3 get01Poll 1
attr SWITCH3 get01PollDelay 300
attr SWITCH3 get01URL http://192.168.0.100/PortSettingRpm.htm
attr SWITCH3 get02Name SystemInfoRpm
attr SWITCH3 get02Poll 1
attr SWITCH3 get02PollDelay 300
attr SWITCH3 get02URL http://192.168.0.100/SystemInfoRpm.htm
attr SWITCH3 get03Name PortStatisticsRpm
attr SWITCH3 get03Poll 1
attr SWITCH3 get03PollDelay 300
attr SWITCH3 get03URL http://192.168.0.100/PortStatisticsRpm.htm
attr SWITCH3 oldreadings Link_Status_[0-9]+,Port_State_[0-9]+
attr SWITCH3 reAuthRegex logonInfo
attr SWITCH3 reading01Name MAC_Address
attr SWITCH3 reading01Regex macStr\:\[\n?\"([0-9A-Fa-f\:]+)\"\n?\]
attr SWITCH3 reading02Name IP_Address
attr SWITCH3 reading02Regex ipStr\:\[\n?\"([0-9.]+)\"\n?\]
attr SWITCH3 reading03Name Firmware
attr SWITCH3 reading03Regex firmwareStr\:\[\n?\"([0-9a-zA-z. ]+)\"\n?\]
attr SWITCH3 reading04Name Hardware
attr SWITCH3 reading04Regex hardwareStr\:\[\n?\"([\w -.]+?)\"\n?\]
attr SWITCH3 reading05Name Name
attr SWITCH3 reading05Regex descriStr\:\[\n?\"([\w\-]+)\"\n?\]
attr SWITCH3 reading06Name Netmask
attr SWITCH3 reading06Regex netmaskStr\:\[\n?\"([0-9.]+)\"\n?\]
attr SWITCH3 reading07Name Gateway
attr SWITCH3 reading07Regex gatewayStr\:\[\n?\"([0-9.]+)\"\n?\]
attr SWITCH3 reading08Name State
attr SWITCH3 reading08Regex state\:\n?\"?(\[[0-9,]+\])\"?\n?
attr SWITCH3 reading09Name Link_Status
attr SWITCH3 reading09Regex link_status\:\n?\"?(\[[0-9,]+\])\"?\n?
attr SWITCH3 reading10Name Pakets
attr SWITCH3 reading10Regex pkts\:\n?\"?(\[[0-9,]+\])\"?\n?
attr SWITCH3 set15Hint 0,1
attr SWITCH3 set15Name SetPortStatus1
attr SWITCH3 set15URL http://192.168.0.100/port_setting.cgi?portid=1&state=$val&speed=1&flowcontrol=0&apply=Apply
attr SWITCH3 set16Hint 0,1
attr SWITCH3 set16Name SetPortStatus2
attr SWITCH3 set16URL http://192.168.0.100/port_setting.cgi?portid=2&state=$val&speed=1&flowcontrol=0&apply=Apply
attr SWITCH3 set17Hint 0,1
attr SWITCH3 set17Name SetPortStatus3
attr SWITCH3 set17URL http://192.168.0.100/port_setting.cgi?portid=3&state=$val&speed=1&flowcontrol=0&apply=Apply
attr SWITCH3 room Netzwerk
attr SWITCH3 sid01Data username=%%user%%&password=%%password%%&cpassword=&logon=Login
attr SWITCH3 sid01IgnoreRedirects 1
attr SWITCH3 sid01URL http://192.168.0.100/logon.cgi
attr SWITCH3 stateFormat Link_Status
attr SWITCH3 replacement01Mode key
attr SWITCH3 replacement01Regex %%user%%
attr SWITCH3 replacement02Value user
attr SWITCH3 replacement02Mode key
attr SWITCH3 replacement02Regex %%password%%
attr SWITCH3 replacement02Value password

set SWITCH3 storeKeyValue user admin
set SWITCH3 storeKeyValue password [s]1234568[/s]

05.01.2022
Reading05 gemäß Info von Jostar angepasst.

04.05.2022
Anpassungen durchgeführt:

10.05.2022
set15-17, Ports Ein/Ausschalten hinzugefügt
« Letzte Änderung: 10 Mai 2022, 12:32:30 von GunterB »

Offline Jostar

  • Full Member
  • ***
  • Beiträge: 114
Antw:HTTPMOD/Device für tp-link TL-SG108PE
« Antwort #1 am: 04 Januar 2022, 18:22:47 »
Klappt soweit. Mit

attr SWITCH3 reading05Regex descriStr\:\[\n?\"([\w\-]+)\"\n?\]

klappt auch der Standardname (mit Minuszeichen).
Raspberry Pi(s) mit FHEM auf Rasbian Jessie/Strech, DbLog/DbRep mit mySQL, piface, 1Wire-USB-Master von SMS-GUARD, RFXtrx433E

Offline GunterB

  • New Member
  • *
  • Beiträge: 32
Antw:HTTPMOD/Device für tp-link TL-SG108PE/ TL-SG116E
« Antwort #2 am: 04 Mai 2022, 14:44:03 »
Link_Status

Funktion um den Link_Status in einzelne Readings zu bekommen:
Code: (99_myUtils.pm) [Auswählen]
## ReadingArrayToReadings
## Device
## ReadingName
## Value e.g.:  "link_status:[5,5,5,6,0,0,0,6,0,0]"
sub ReadingArrayToReadings($$$) {
    my ($device, $reading, $value) = @_;
    my @values = ( $value =~ /(\d)/g );
    my $i = 0;

    readingsBeginUpdate( $hash );

    foreach(@values) {
        my $old_val = ReadingsVal($device, "${reading}_${i}", "-");
        if ($old_val ne $_) {
            readingsBulkUpdate( $hash, "${reading}_${i}", ${_} );
        }
        $i += 1;
    }
   
    readingsEndUpdate( $hash, 1 );
    ## evtl weitere vorhandene Einträge löschen (wenn Array kleiner wird)
}

Link_Status der Ports aufdröseln:
Code: (NTFY_SWITCH_LinkStatus) [Auswählen]
defmod NTFY_SWITCH_LinkStatus notify SWITCH[0-9]+:Link_Status:.* {\
    my $LinkStatus = ReadingsVal($NAME, "Link_Status", "-");;\
    ReadingArrayToReadings($NAME, "Link_Status", $LinkStatus);;\
}

Telegramnachricht bei Änderung des Link_Status:
Code: (TelegramMessage05_SWITCH_Link_Status) [Auswählen]
defmod TelegramMessage05_SWITCH_Link_Status notify SWITCH[0-9]+:Link_Status_[0-9]+.* {\
my $message = "${SELF}\n";;\
        my $switch_hardware = ReadingsVal($NAME, "Hardware", "-");;\
        my @port_state = ("Link Down","Auto","10Half","10Full","100Half","100Full","1000Full");;\
\
        ##$message .= "${NAME}\n";;\
        ##$message .= "${switch_hardware}\n";;\
        ##$message .= "EVENT: ${EVENT}\n";;\
\
        my @y = split / /, $EVENT;;\
        ##$message .= "dec: ${y[1]}\n";;\
\
        if ( $EVENT =~ /_(\d+)/) {\
            my $port = $1;;\
            my $port_state = $y[1];;\
            ##$message .= "state: ${port_state[$port_state]}\n";;\
            $message .= "#${NAME}\n";;\
            $message .= "${switch_hardware}\n";;\
            $message .= "Port ${port} changed state to: ${port_state[$port_state]}\n";;\
\
    fhem("set myTelegramBot _msg $message");;\
        }\
\
}
« Letzte Änderung: 16 Mai 2022, 12:58:03 von GunterB »