code running fine on computer and on pydroid 3 it doesnt

Question:

so i have made a script that when my phone connects to my wifi network it automatically turn on my computer and i downloaded pydroid on another phone to run it non stop and it outputs :

ping [-aAbBdDfhLnOqrRUvV] [-c count] [-i interval] [-I interface]
            [-m mark] [-M pmtudisc_option] [-l preload] [-p pattern] [-Q tos]
            [-s packetsize] [-S sndbuf] [-t ttl] [-T timestamp_option]
            [-w deadline] [-W timeout] [hop1 ...] destination

and the code is this that works perfectly on a computer:

import subprocess
from wakeonlan import send_magic_packet

IP_DEVICE = 'phonesip'

devices = {
    'my_pc': {'mac': 'mymacadress', 'ip_address': 'myipadress'}
}


def wake_device(device_name):
    if device_name in devices:
        mac, ip = devices[device_name].values()
        send_magic_packet(mac, ip_address=ip)
        print('Magic Packet Sent')
    else:
        print('Device Not Found')


proc = subprocess.Popen(["ping", '-t', IP_DEVICE], stdout=subprocess.PIPE)

while True:
    line = proc.stdout.readline()
    if not line:
        break
    else:
        None

    try:
        connected_ip = line.decode('utf-8').split()[2].replace(':', '')
        if connected_ip == IP_DEVICE:
            print('Device connected!')
            wake_device('my_pc')
            # Do whatever you want when the device connects here...
            break
        else:
            print('Pinging device...')
    except:
        pass
Asked By: 590ms

||

Answers:

Try omitting the -t from ping when running the script on your phone.

ping works differently on your phone. On windows you have to add -t for it to ping nonstop, on other operating systems that is the default behaviour.

Answered By: ColdIV
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.