Presence und iPhone / Android

Begonnen von JoWiemann, 07 September 2017, 11:58:59

Vorheriges Thema - Nächstes Thema

en-trust

Mein script liegt genau da wo er es angeblich nicht findet.
Ich habe jetzt mal das script von #89 kopiert, ist zwar 3mal so gross aber ich habs versucht. Reboot und die gleiche Meldung.

2018.02.01 17:18:30.211 1: PERL WARNING: Can't exec "/opt/fhem/FHEM/presence.sh": No such file or directory at ./FHEM/99_myUtils.pm line 87.
2018.02.01 17:18:30.212 3: eval: {CheckiPhone("xxx","xxx")}
2018.02.01 17:18:30.230 1: PERL WARNING: Use of uninitialized value $ret in substitution (s///) at ./FHEM/99_myUtils.pm line 89.
2018.02.01 17:18:30.231 3: eval: {CheckiPhone("xxx","xxx")}
2018.02.01 17:18:30.231 1: PERL WARNING: Argument "" isn't numeric in numeric ne (!=) at ./FHEM/99_myUtils.pm line 91.
2018.02.01 17:18:30.232 3: eval: {CheckiPhone("xxx","xxx")}
2018.02.01 17:18:30.247 2: PRESENCE (Galaxy.S5.Wlan) - error while processing check: unexpected function output (expected 0 or 1):

Master_Nick

Dann bitte mal den Inhalt aus deiner 99_myUtils.pm.
Rancher K8s Cluster mit nanoCUL (a-culfw) | IObroker | IT(V1&V3), IT-PIR, THGR122NX |Co² | alexa-fhem | WOL | NFC | Harmony UltimateHub | Anwesenheitserkennnung | Roomba | 10" Touch mit Node-Red | SonOff S20 | SonOff Touch | SonOff Dual | Rolladen | Und ganz viel anderes tolles Gerödel.... ;-)

Wernieman

Vorallem checjk mal Zeile 89 .. wenn das System so nett ist und Dir den genauen Ort angiebt ...
- Bitte um Input für Output
- When there is a Shell, there is a Way
- Wann war Dein letztes Backup?

Wie man Fragen stellt: https://tty1.net/smart-questions_de.html

en-trust

Hab die sub aus #1 einfach kopiert.

##############################################
# $Id: myUtilsTemplate.pm 7570 2015-01-14 18:31:44Z 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;
use POSIX;

sub
myUtils_Initialize($$)
{
  my ($hash) = @_;
}

# Enter you functions below _this_ line.
use HTML::Entities;

sub
wrapLine($$)
{
  my ($string, $maxLength) = @_;
  $string = decode_entities($string);
my @stringParts = split(/ /, $string);
  my $actRowLength = 0;
  my $resultString = '';
  while (scalar(@stringParts) > 0) {
  my $tempString = shift @stringParts;
    if ($actRowLength > 0)
    {
    if (($actRowLength + length($tempString)) > $maxLength)
      {
      $actRowLength = 0;
        $resultString .= '<br>';
      }
    }
    $resultString .= $tempString;
    $actRowLength += length($tempString);
    if (scalar(@stringParts) > 0)
    {
    $resultString .= ' ';
    $actRowLength += 1;
    }
  }
  if ($resultString eq '')
  {
  return ' ';
  }
  else
  {
  return $resultString;
  }
}

######## Gerät über Fritzbox abfragen ########
sub
NetDevDa($)
{
my $n = 0;
my ($Reading) = @_;
$Reading =~ tr/:/_/;
my @fbs = devspec2array("TYPE=FRITZBOX");
foreach( @fbs ) {
my $Name = ReadingsVal($_,"mac_" . $Reading,"");
if( ($Name ne "") && ($Name ne "inactive") ) {
$n++;
}
}
if( $n == 0) {
return 0;
} else {
return 1;
}
}

######## Gerät über Script abfragen ########
sub CheckiPhone($$)
{
  my ($ip,$mac)= @_;
  my $ret = "";

  $mac = lc($mac);

  $ret = qx(/opt/fhem/FHEM/presence.sh $ip $mac);

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

  if ( $ret != 0 && $ret != 1) {
    Log3 "CheckiPhone", 2, "CheckiPhone: $ret";
    return 0;
  }

  return $ret;

}

1;

MadMax-FHEM

Wie hast du denn das Script erstellt?

Wenn für Linux "untaugliche" Zeichen/Zeilenenden/-umbrüche drin sind (kopiert über Windows z.B.) dann gibt es u.U. auch die komische File not found Meldung...

Kurz da Handy...

Gruß, Joachim
FHEM PI3B+ Bullseye: HM-CFG-USB, 40x HM, ZWave-USB, 13x ZWave, EnOcean-PI, 15x EnOcean, HUE/deCONZ, CO2, ESP-Multisensor, Shelly, alexa-fhem, ...
FHEM PI2 Buster: HM-CFG-USB, 25x HM, ZWave-USB, 4x ZWave, EnOcean-PI, 3x EnOcean, Shelly, ha-bridge, ...
FHEM PI3 Buster (Test)

Wernieman

Sorry aber ich werde nicht für Dich Zeile 89 suchen .. das kann Dein Editor besser ...
- Bitte um Input für Output
- When there is a Shell, there is a Way
- Wann war Dein letztes Backup?

Wie man Fragen stellt: https://tty1.net/smart-questions_de.html

en-trust

Zeile 89

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

kjmEjfu

Grundproblem ist aber weiterhin, dass er die Datei nicht finden/ausführen kann.
Ich würde immernoch gerne ein ls -al von dem Ordner sehen.

Das andere sind Folgefehler.
Migriere derzeit zu Home Assistant

Wernieman

Hatte mich auch verschrieben ... meinte Zeile 87 ....
- Bitte um Input für Output
- When there is a Shell, there is a Way
- Wann war Dein letztes Backup?

Wie man Fragen stellt: https://tty1.net/smart-questions_de.html

Master_Nick

Hast du das Script auch ausführbar gemacht und nicht nur 777? :-)
Rancher K8s Cluster mit nanoCUL (a-culfw) | IObroker | IT(V1&V3), IT-PIR, THGR122NX |Co² | alexa-fhem | WOL | NFC | Harmony UltimateHub | Anwesenheitserkennnung | Roomba | 10" Touch mit Node-Red | SonOff S20 | SonOff Touch | SonOff Dual | Rolladen | Und ganz viel anderes tolles Gerödel.... ;-)

Wernieman

Über die Sinnhaftigkeit von 777 kann (und sollte man) streiten. Aber es bedeutet, das es ausführbar ist!

(Wobei man NIEMALS ein globales Schreibbit für ein Ausführbares Programm setzen sollte. Also ein 755 wäre DEUTLICH besser wegen der Security)
- Bitte um Input für Output
- When there is a Shell, there is a Way
- Wann war Dein letztes Backup?

Wie man Fragen stellt: https://tty1.net/smart-questions_de.html

en-trust

Testhalber sind mein scripte immer erstmal auf 777 und ja mit sudo chmod +x "/opt/fhem/FHEM/presence.sh" auch ausführbar gemacht.
Über ls -af bekomm ich auch die ganze liste mit allen Dateien *.pm als auch das presence.sh angezeigt.

Zeile 87
$ret = qx(/opt/fhem/FHEM/presence.sh $ip $mac);

Zeile 89
$ret =~ s,[\r\n]*,,g;        # remove CR from return-string

Wernieman

#117
Um mal sicher zu gehen:
ls -lha /opt/fhem/FHEM/presence.sh

Edit:
Und dann bitte mal:
head -n5 /opt/fhem/FHEM/presence.sh

Edit2:
Wie hast Du die Datei erstellt?
- Bitte um Input für Output
- When there is a Shell, there is a Way
- Wann war Dein letztes Backup?

Wie man Fragen stellt: https://tty1.net/smart-questions_de.html

MadMax-FHEM

FHEM PI3B+ Bullseye: HM-CFG-USB, 40x HM, ZWave-USB, 13x ZWave, EnOcean-PI, 15x EnOcean, HUE/deCONZ, CO2, ESP-Multisensor, Shelly, alexa-fhem, ...
FHEM PI2 Buster: HM-CFG-USB, 25x HM, ZWave-USB, 4x ZWave, EnOcean-PI, 3x EnOcean, Shelly, ha-bridge, ...
FHEM PI3 Buster (Test)

en-trust

Datei habe ich mit notepad erstellt, sprich hier rauskopiert im notepad eingefügt abgespeichetr und auf den raspi kopiert.

pi@raspberrypi:/opt/fhem/FHEM $ ls -lha /opt/fhem/FHEM/presence.sh
-rwxrwxrwx 1 fhem dialout 1.9K Feb  1 17:18 /opt/fhem/FHEM/presence.sh

pi@raspberrypi:/opt/fhem/FHEM $ head -n5 /opt/fhem/FHEM/presence.sh
#!/bin/bash
# detect Iphone/Android by IP/HOSTNAME and MAC address.
# use MAC address too, to prevent false positives if IP might change
# returns 1 or 0


hier ist nochmal die presence.sh vielleicht ist ja auch nen tippfehler...

#!/bin/bash
# detect Iphone/Android by IP/HOSTNAME and MAC address.
# use MAC address too, to prevent false positives if IP might change
# returns 1 or 0

# number of retries, less is faster, but less accurate
# Max retries for predetection
PREMAXRETRIES=10
# Max retries for detection
MAXRETRIES=10

# exit immediately if no parameters supplied
if [ $# -lt 2 ]
  then
    echo "UNDEF"
  exit 1
fi

# Set variables
# Checking if $1 is a host or an ipadress
IP=`echo $1 | grep -oP '([0-9]){1,3}\.([0-9]){1,3}\.([0-9]){1,3}\.([0-9]){1,3}'`
HOST=`host -4 $1 | grep -oP '([0-9]){1,3}\.([0-9]){1,3}\.([0-9]){1,3}\.([0-9]){1,3}'`
MAC=$2
COUNT=0
PRECOUNT=0

# This if takes care of an empty $IP by setting variable Host as IP or even quits the detection by setting absent - if no ip for a hostname is available
if [ -z "$IP" ]; then
IP=${HOST}
if [ -z "$IP" ]; then
echo "0"
exit 0
fi
fi

# Predetection: saves energie on your mobile devices by first trying to get presence over current arp-scan results
while [ ${PRECOUNT} -lt ${PREMAXRETRIES} ];
do
PRECHECK=`sudo arp-scan -q -g ${IP} | grep -o "${MAC}"`
if [ ${#PRECHECK} -eq ${#MAC} ]; then
   # exit when phone is detected
   echo "1"
   exit 0
   fi
  ((PRECOUNT++))
done

# Detection: trys to wake up your mobile device an getting it visible in arp-scan results
while [ ${COUNT} -lt ${MAXRETRIES} ];
do
  # Change dev and eth0 if needed
  #   sudo ip neigh flush dev eth0 ${IP}
  sudo hping3 -q -2 -c 10 -p 5353 -i u1 ${IP} >/dev/null 2>&1
#  sudo hping3 -q -2 -c 10 -p 5353 -i u1 ${IP}
  sleep .1
  # Only arp specific device, grep for a mac-address
  STATUS=`sudo arp-scan -q -g ${IP} | grep -o "${MAC}"`

  if [ ${#STATUS} -eq ${#MAC} ]; then
     # exit when phone is detected
     echo "1"
    exit 0
  fi
  ((COUNT++))
  sleep .1
done
# consider away if reached max retries
echo "0"