• 10 dec 2017: forum version update. In case of issues use this topic.
  • 30 nov 2017: pilight moved servers. In case of issues use this topic.
Hello There, Guest! Login Register

@chief-wiggem: I also had problems with phone detection until I added the poll-interval. I don't see it in your config, maybe if you add it detection will work.
I have done some more intensive testing, i think the machine and the programmer do not agree, thus it would be helpfull if some comments are added to libs/pilight/ping.c in order to clearify the intentions of the code.

I have renumbered the return -1 exits of function ping in pilight/ping.c and called them Exit 1 to 6 (from top to bottom).
I can ping my router in the network, but pilight/ping.c uses Exit 6.
I can ping my own machine, but pilight/ping.c uses Exit 6.
For non existing devices pilight/ping.c uses Exit 5.

Line 93 of protocols/ping.c
I do not under stand the logic of } else if { statement.
as this would imply to set the state to DISCONNECT independent of the ping function call.

I assume that the logic is
} else {
    if (state == CONNECTED) {
Please add the closing } at the end.
1 = Cannot create socket.
2 = Cannot construct IP header.
3 = Cannot set timeout to prevent us from waiting too long for a ping answer.
4 = Failed to send our ICMP package. Failure is on the server side.
5 = Didn't receive a ICMP respons within our timeout. Failure is on the client side.
6 = The received reply didn't match what we expected to receive or the respons address didn't match the device we were pinging.

Ping protocol:
This checks for changes in the ping device state. It makes sure we only broadcast when the state changes from CONNECTED -> DISCONNECTED or the reverse. The ping command only return 0 on successfull ping. So every other return code can be considered a disconnected state. However, we only broadcast this once.
Exit 5:
Could the problem be caused by the WLAN nature of that link ?
What is the Timeout criteria ?
root@md:/home/wolfgang/pilight# ifconfig
eth0      Link encap:Ethernet  Hardware Adresse b8:27:eb:xx:xx:xx
          UP BROADCAST MULTICAST  MTU:1500  Metrik:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          Kollisionen:0 Sendewarteschlangenlänge:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

lo        Link encap:Lokale Schleife
          inet Adresse:  Maske:
          UP LOOPBACK RUNNING  MTU:65536  Metrik:1
          RX packets:482122 errors:0 dropped:0 overruns:0 frame:0
          TX packets:482122 errors:0 dropped:0 overruns:0 carrier:0
          Kollisionen:0 Sendewarteschlangenlänge:0
          RX bytes:55875536 (53.2 MiB)  TX bytes:55875536 (53.2 MiB)

tun0      Link encap:UNSPEC  Hardware Adresse 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
          inet Adresse:10.xx.xx.xx  P-z-P:10.xx.xx.xx  Maske:
          RX packets:76342 errors:0 dropped:0 overruns:0 frame:0
          TX packets:382499 errors:0 dropped:305612 overruns:0 carrier:0
          Kollisionen:0 Sendewarteschlangenlänge:100
          RX bytes:5365161 (5.1 MiB)  TX bytes:495110265 (472.1 MiB)

wlan0     Link encap:Ethernet  Hardware Adresse 80:3f:5d:xx:xx:xx
          inet Adresse:  Bcast:  Maske:
          RX packets:133981 errors:0 dropped:0 overruns:0 frame:0
          TX packets:152392 errors:0 dropped:0 overruns:0 carrier:0
          Kollisionen:0 Sendewarteschlangenlänge:1000
          RX bytes:16379126 (15.6 MiB)  TX bytes:42964605 (40.9 MiB)

root@md:/home/wolfgang/pilight# ping
PING ( 56(84) bytes of data.
64 bytes from icmp_req=1 ttl=255 time=2.32 ms
64 bytes from icmp_req=2 ttl=255 time=5.88 ms
64 bytes from icmp_req=3 ttl=255 time=7.81 ms
64 bytes from icmp_req=4 ttl=255 time=5.95 ms
64 bytes from icmp_req=5 ttl=255 time=6.31 ms
64 bytes from icmp_req=6 ttl=255 time=6.62 ms
64 bytes from icmp_req=7 ttl=255 time=5.99 ms
64 bytes from icmp_req=8 ttl=255 time=6.02 ms
--- ping statistics ---
8 packets transmitted, 8 received, 0% packet loss, time 7010ms
rtt min/avg/max/mdev = 2.322/5.866/7.810/1.467 ms
root@md:/home/wolfgang/pilight# ping
PING ( 56(84) bytes of data.
64 bytes from icmp_req=1 ttl=64 time=0.293 ms
64 bytes from icmp_req=2 ttl=64 time=0.214 ms
64 bytes from icmp_req=3 ttl=64 time=0.205 ms
64 bytes from icmp_req=4 ttl=64 time=0.212 ms
64 bytes from icmp_req=5 ttl=64 time=0.208 ms
64 bytes from icmp_req=6 ttl=64 time=0.221 ms
--- ping statistics ---
6 packets transmitted, 6 received, 0% packet loss, time 5003ms
rtt min/avg/max/mdev = 0.205/0.225/0.293/0.034 ms
Exit 6:
Could it be that it has an impact that both devices in question are WiFi devices ?
I do not think that the tun adapter interface is causing the problem here.
You can of course remove the timeout to test. It's currently 1 second. It are these lines:
    tv.tv_sec = 1;
    tv.tv_usec = 0;
    if(setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(struct timeval)) < 0) {
        return -1;

I have not clue. You could add the values in the strcmp into a printf to see what they are on return.
As you can see from the roundtrip time that is typically less then 10mS between Pi and AP, and less than 500µS on the Pi, i do feel comportablewith 1000mS.

I will get more detailled info on the status-bits.
There are two implementation issues with the usage of the raw sockets. I found a solution for the first one and I am chasing the second.
send from tapatalk
Nice! Thanks for investigating.
I will test the 2nd issue tonight
I had the following 2 issues:
1. I was unable to ping my own machine.
2. My TP-LINK router does not reply to ICMP timestamp requests but to ECHO requests only.

regarding issue 1: i added the additional flag checking to the code
regarding issue 2: i replaced ICMP_TSTAMP with ICMP-ECHO

errno of some system calls was checked with perror, i changed that to logperror(LOG_DEBUG, ....);

I have uploaded a test version here..

pilight-daemon: INFO: version 5.0, commit v5.0-275-g68d8927

I get this error below, where 137.120 is the IP address of the rpi running pilight.

pilight-daemon: DEBUG: unexpected status reply 3 from addr:

Besides the above, is it possible to specify poll-interval a bit more? Is it defined in ms, sec or?

Forum Jump:

Browsing: 1 Guest(s)