Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Early launch of ssdp_server.py (from rc.local) will fail on Pi #1

Open
philippeportesppo opened this issue Feb 13, 2018 · 0 comments
Open

Comments

@philippeportesppo
Copy link

philippeportesppo commented Feb 13, 2018

Hi, I thank you a lot for the code you wrote.
I adapted it for my needs in my SmartThings porting to add UPNP detection of my Pi (see https://github.com/philippeportesppo/AirMentorPro2_SmartThings).

I found your original code in main.py had a problem to be launched when the system is early in booting, meaning the network interface is not yet available.

Since I modified your code too much to fork a version of it, I just snap the code below.
The idea is to have a waiting stage till the network interface shows up.

Thanks again (ou merci si vous etes en France).

def get_network_interface_ip_address(interface='wlan0'):

"""

Get the first IP address of a network interface.

:param interface: The name of the interface.

:return: The IP address.

"""


while interface not in ni.interfaces():

    print('Could not find interface %s.' % (interface,))

    sleep(10)



while True:
    interfacestring = ni.ifaddresses(interface)

    if (2 not in interfacestring) or (len(interfacestring[2]) == 0):

        print('Could not find IP of interface %s. Sleeping.' % (interface,))

        sleep(10)

        continue
    else:
        break
return interfacestring[2][0]['addr']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant