Unable to Connect LTE



  • I'm attempting to connect my GPy to an Amarisoft network operating on band 42. I'm running the code below but the device seems to have issues attaching to the LTE network.

    import machine
    import time
    from network import LTE
    from machine import RTC
    # from network import WLAN
    
    lte = LTE() # instantiate the LTE object
    rtc = RTC() # instantiate the RTC object
    
    def getLTE():
    
        # If already used, the lte device will have an active connection.
        # If not, need to set up a new connection.
        if lte.isconnected():
            print("LTE is connected")
            return lte
    
        # Modem does not connect successfully without first being reset.
        print("Resetting LTE modem ... ", end="")
        lte.send_at_cmd('AT^RESET')
        print("OK")
        time.sleep(1)
    
        # While the configuration of the CGDCONT register survives resets,
        # the other configurations don't. So just set them all up every time.
        print("Configuring LTE ", end='')
        lte.send_at_cmd('AT+CGDCONT=1,"IP","test123"')  # Changed this from origninal
        print(".", end='')
        lte.send_at_cmd('AT!="RRC::addscanfreq band=42 dl-earfcn=9410"') # changed band from 28 to 4. I dont know what earfcn=9410 is;
        print(".", end='')
        lte.send_at_cmd('AT+CFUN=1')
        print(" OK")
    
        # If correctly configured for carrier network, attach() should succeed.
        if not lte.isattached():
            print("Attaching to LTE network ", end='')
            lte.attach()
            while(True):
                if lte.isattached():
                    print(" OK")
                    break
                print('.', end='')
                time.sleep(1)
    
        # Once attached, connect() should succeed.
        if not lte.isconnected():
            print("Connecting on LTE network ", end='')
            lte.connect()
            while(True):
                if lte.isconnected():
                    print(" OK")
                    break
                print('.', end='')
                time.sleep(1)
    
        # Once connect() succeeds, any call requiring Internet access will
        # use the active LTE connection.
        return lte
    
    def endLTE():
    
        print("Disonnecting LTE ... ", end='')
        lte.disconnect()
        print("OK")
        time.sleep(1)
        print("Detaching LTE ... ", end='')
        lte.dettach()
        print("OK")
    
    # Sets the internal real-time clock.
    # Needs LTE for Internet access.
    def setRTC():
    
        # Ensures LTE session is connected before attempting NTP sync.
        lte = getLTE()
    
        print("Updating RTC from {} ".format(NTP_SERVER), end='')
        rtc.ntp_sync(NTP_SERVER)
        while not rtc.synced():
            print('.', end='')
            time.sleep(1)
        print(' OK')
    
    # Only returns an RTC object that has already been synchronised with an NTP server.
    def getRTC():
    
        if not rtc.synced():
            setRTC()
    
        return rtc
    
    # Program starts here.
    try:
        print("Initially, the RTC is {}".format("set" if rtc.synced() else "unset"))
        rtc = getRTC()
        while(True):
            print("RTC is {}".format(rtc.now() if rtc.synced() else "unset"))
            time.sleep(5)
    except Exception:
        pass # do nothing on error
    
    finally:
        endLTE()
    

    I suspect the issues lies in this block of code, since it seems to be unable to attach to an LTE network.

    # While the configuration of the CGDCONT register survives resets,
    # the other configurations don't. So just set them all up every time.
    print("Configuring LTE ", end='')
    lte.send_at_cmd('AT+CGDCONT=1,"IP","test123"')  # Changed this from origninal
    print(".", end='')
    lte.send_at_cmd('AT!="RRC::addscanfreq band=42 dl-earfcn=41590"') # changed band from 28 to 4 and earfcn=9410 to earfcn=41590
    print(".", end='')
    lte.send_at_cmd('AT+CFUN=1')
    print(" OK")


  • @robert-hh It still doesn't seem to work for me even after setting the DNS servers. Aside from this method is there another way I can verify my connection?



  • @pycom_user123 After setting DNS servers manually with:

    socket.dnsserver(0,'8.8.8.8')
    socket.dnsserver(1,'4.4.4.4')
    

    also getaddrinfo() works.



  • @pycom_user123 Forgot to mention: My firmware is 1.20.0.rc11.1.
    What I wanted to tell is, that your function google() generally works, but each provider may have different omissions.



  • @robert-hh Still getting the same error when I change 'google.com' to its numeric value. I tried just getaddrinfo and it seems to work, so perhaps the issue as is with the s.connect() component.

    >>> print(socket.getaddrinfo('172.217.22.110', 443)[0][-1])
    ('172.217.22.110', 443)
    


  • @pycom_user123 Using my FiPy and an 1nce SIM, the google() function fails at getaddrinfo(), but replacing the symbolic address 'www.google.com' with the numeric '172.217.22.110' value succeeds, and I get data back from the server.
    This error at resolving names was discussed before.
    And yes: I disabled WiFi before the test. With WiFi, getaddrinfo() works.



  • @testuser The google() function works when I'm connected using wifi, so I don't think the function is the issue. I did retry using the code exactly as its written in the example as you suggest, but got the same error unfortunately.



  • @testuser That is an interesting observation you talk of. Can you give an example of that which is reproducible? The two statement you highlight should make exactly the same call, and if not, I would consider it as a bug, which should be fixed. For that, examples are essential.



  • @pycom_user123 transmissions like this can be very finicky. The functions do quite a bit of work to parse everything into exactly the right format with authorizations, acknowledgements, payloads, etc... Add in all of the formatting changes as everything is translated into hex, binary, etc....

    Something as small as

        s = socket.socket()
        ss = ssl.wrap_socket(s)
        i = socket.getaddrinfo('www.google.com', 443)[0][-1]
        print('Connecting to socket...')
        ss.connect(i)
        print('Send...')
        ss.send(b"GET / HTTP/1.0\r\n\r\n")
        print(ss.recv(4096))
        print('Close...')
        ss.close()
    

    versus

     s = socket.socket()
     s = ssl.wrap_socket(s)
     s.connect(socket.getaddrinfo('www.google.com', 443)[0][-1])
     s.send(b"GET / HTTP/1.0\r\n\r\n")
     print(s.recv(4096))
     s.close()
    

    can somehow result in a slightly different message being sent because

    s.connect(socket.getaddrinfo('www.google.com', 443)[0][-1]) 
    

    is treated slightly differently than

    i = socket.getaddrinfo('www.google.com', 443)[0][-1]
    s.connect(i)
    

    because of some small difference between floats, doubles, integers, strings, booleans, etc... I'd recommend starting with the Pycom documentation examples, or examples on the forums that are verified to be working.



  • @robert-hh Alright now I've successfully connected but I'm getting the following error when I try to run the google() function.

    >>> lte.attach()
    >>> lte.isattached()
    True
    >>> lte.connect(cid=3)
    >>> lte.isconnected()
    True
    >>> google()
    Connecting to socket...
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "boot.py", line 40, in google
    OSError: [Errno 113] EHOSTUNREACH
    


  • @robert-hh I see lte.attach(), but no lte.connect(). Does your code wait in the function connect() after sending lte.attach(), until attach succeeded, before issuing lte.connect()?



  • @robert-hh Correct. See my code in the previous reply. I issue the function connect(), which attempts to attach first and then connect.



  • @pycom_user123 connect follows attach



  • Update: The attach seems to work now, however I am still unable to connect. I get the following response.

    >>> connect()
    lte.attach()Connecting to LTE networkTraceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "boot.py", line 22, in connect
    OSError: the requested operation failed
    >>> lte.attach()
    >>> lte.isattached()
    True
    >>> lte.isconnected()
    False
    


  • @jcaron When I update the device through the Pycom firmware updater it updates to v1.8.6. Is this the latest version my board can handle? If not, where can I find a more up to date version of the firmware?



  • @pycom_user123 I strongly recommend you update to a more recent firmware version (and modem firmware as well). 1.8.6 is nearly 2 years old, lots has changed/been fixed since then.



  • @jcaron Okay I've replaced the Amarisoft sim to a Verizon one which uses band 13. I've also adjusted the code but I'm still having issues with attaching. Any ideas?

    import socket
    import time
    from network import LTE
    import ssl
    import machine
    from network import WLAN
    wlan = WLAN(mode=WLAN.STA)
    
    lte = LTE()
    
    def connect():
        print('lte.attach()', end='')
        lte.attach()
        while not lte.isattached():
            print('.', end='')
            time.sleep(0.25)
        print('Connecting to LTE network', end='')
        lte.connect()
        while not lte.isconnected():
            print('.', end='')
            time.sleep(0.25)
        print('LTE is connected')
    
    def disconnect():
        lte.disconnect();
        lte.dettach();
    
    def at(s):
        print(lte.send_at_cmd(s))
    
    def google():
        s = socket.socket()
        ss = ssl.wrap_socket(s)
        i = socket.getaddrinfo('www.google.com', 443)[0][-1]
        print('Connecting to socket...')
        ss.connect(i)
        print('Send...')
        ss.send(b"GET / HTTP/1.0\r\n\r\n")
        print(ss.recv(4096))
        print('Close...')
        ss.close()
    
    def wifi():
        wlan.init(mode=WLAN.STA, antenna=WLAN.INT_ANT)
        nets = wlan.scan()
        for net in nets:
            if net.ssid == 'Test':
                print('Network found!')
                wlan.connect(net.ssid, auth=(net.sec, 'Test1234'), timeout=5000)
                while not wlan.isconnected():
                    #machine.idle() # save power while waiting
                    print('.', end='')
                    time.sleep(0.5)
                print('WLAN connection succeeded!')
                break
    


  • @pycom_user123 That's a pretty old version of the firmware, but this is probably not the issue, band 42 is not listed as part of the supported bands in the GPy data sheet.



  • Hardware version: GPy 1.0
    Software version: v1.8.6-849-df9f237 on 2019-05-14
    Not sure of the firmware version of the modem



  • @pycom_user123 You should probably give details of the following version numbers:

    • hardware version of the GPy (visible on the board)
    • firmware version of the GPy
    • firmware version of the modem.

Log in to reply
 

Pycom on Twitter