Gpy connected to wifi but no internet access



  • I am using Gpy module in Pysense board, and I have run several scripts for wifi as AP , connect to wifi, light sensor ... and it works correctly.

    But when the device is connected to wifi, it doesn't have internte access, I have executed the next code for check it and for show the wlan connection status (after review another old topic in this page):

    import urllib

    try:
    urllib.request.urlopen('http://www.google.com')
    except:
    print('No internet connection! AAAHH!')
    else:
    print('Internet connection! YAAAY!')

    print("Check pycom page")
    import socket
    s = socket.socket()
    print(socket.getaddrinfo('time-a.nist.gov', 13))
    s.connect(socket.getaddrinfo('time-a.nist.gov', 13)[0][-1])
    s.read()

    The result of the script is:

    No internet connection! AAAHH!
    Check pycom page
    [(2, 1, 0, '', ('129.6.15.28', 13))]

    Could you help me with this?



  • @josejulianrp
    Have you installed urllib.request ? It doesn't come as part of the default firmware, you need to get it from

    https://github.com/micropython/micropython-lib/tree/master/urllib.urequest

    If you don't have it an exception will be thrown causing it to print your message.

    The second part of your code using sockets seems to be connecting just fine.



  • Sorry, I didn't explained correctly, I tried AP and STA options for wifi, in both cases I can connect to Gpy with filezilla, but in STA mode, although my laptop has connection to internet, the Gpy not. This is the code that I used to connect to wifi and check internet access (it is connected to the wifi because I can connect by FTP and upload and download files):

    import machine
    import network
    from network import WLAN
    import time

    setup as a station

    wlan = network.WLAN(mode=network.WLAN.STA)
    wlan.connect(ssid='my ssid', auth=(WLAN.WPA2, 'the password of wlan'))
    while not wlan.isconnected():
    time.sleep_ms(50)
    print(wlan.ifconfig())

    import urllib

    try:
    urllib.request.urlopen('https://www.google.es')
    except:
    print('No internet connection! AAAHHHHHHH!')
    else:
    print('Internet connection! YAAAY!')

    print("Check pycom code")
    import socket
    s = socket.socket()
    print(socket.getaddrinfo('time-a.nist.gov', 13))
    s.connect(socket.getaddrinfo('time-a.nist.gov', 13)[0][-1])
    s.read()

    The result of this script is:

    ('192.168.43.119', '255.255.255.0', '192.168.43.1', '192.168.43.1')
    No internet connection! AAAHHHHHHH!
    Check pycom page
    [(2, 1, 0, '', ('129.6.15.28', 13))]

    MicroPython v1.8.6-849-055728a on 2018-02-13; GPy with ESP32
    Type "help()" for more information.

    As you can see, cannot access to google page. The last part of the code is one that I saw in one of your answer to other users and you can check the result: [(2, 1, 0, '', ('129.6.15.28', 13))]

    I have tried at 20 cm of my router if the reason would be the wif signal and using my mobile as AP and sharing internet connection, in both cases the result is no access to internet.



  • In the code you have shared the device has not been connected to a WiFi or LTE CAT-M1 network so therefore it cannot access the internet. Please see the example here: https://docs.pycom.io/chapter/tutorials/all/wlan.html#connecting-to-a-router



  • @josejulianrp You have to set up the Gpy as STA, not as AP, to get internet access from it through your normal router by WiFi.
    OR, you enable LTE, and use that to connect to the Internet, but also then the GPy would act as a Station.


Log in to reply
 

Pycom on Twitter

Looks like your connection to Pycom Forum was lost, please wait while we try to reconnect.