Can't connect GPy to pybytes with NB-IoT

  • Re: Can't connect Fipy via LTE NB-IoT to Pybytes

    Connecting my GPy to Pybytes via Wifi works fine, but I have a similar issue as above with NB-IoT. On booting the GPy with latest pybytes firmware:

    Firmware: 1.18.2.r6
    Pybytes: 0.9.12
    Pybytes configuration read from /flash/pybytes_config.json
    Initialized watchdog for WiFi and LTE connection with timeout 660000 ms
    LTE init(carrier=standard, cid=1)
    LTE attach(band=20, apn=lpwa.telia.iot, type=None)
    LTE connect()
    LTE is_connected()
    LTE connection established
    Unknown error while connecting to MQTT server [Errno 113] EHOSTUNREACH
    Unknown error while connecting to MQTT server [Errno 113] EHOSTUNREACH

    Quite close to connecting to Pybytes I think... Could this be DNS related?

    My carrier is Telia. These REPL lines give me perfect access to Internet:

    >>> import socket
    >>> from network import LTE
    >>> lte = LTE()
    >>> lte.send_at_cmd('AT!="addscanband band=20"')
    >>> lte.attach(band=20, apn="lpwa.telia.iot")
    >>> lte.isattached()
    >>> lte.connect()
    >>> lte.isconnected()
    >>> socket.dnsserver(0,'')
    >>> socket.dnsserver(1,'')
    >>> socket.dnsserver()
    ('', '')
    >>> print(socket.getaddrinfo("", 80)[0][-1])
    ('', 80)

    Grateful for your advice.
    // Erik

  • @Scott-Basgaard Well at the time I'm pretty sure you could download what was called the "pybytes" firmware and modify it accordingly (with the patch above). But this particular problem was sorted out in a later version of the built-in pybytes library, at least for me.

    FWIW, back then you had to set the dns server with socket.dnsserver() before you did from network import LTE.

  • @Gijs thanks again. Looks like I can't set them and they are ('', '') wherever I print socket.dnsserver().

  • Global Moderator

    To be honest, I'm not completely sure.
    It could be the case your LTE carrier is not providing the DNS servers correctly, or that the LTE modem is not picking up on them. You can verify by calling socket.dnsserver() after the lte connection is established, but before you change the servers yourself?

  • @Gijs thanks for the reply.

    Can I ask how? I'm getting

    Socket create error: [Errno 202] EAI_FAIL

    when using Pybytes and not setting DNS to and in manual LTE connect tests.

  • Global Moderator

    The feature you mention is available in the latest firmware (1.20.2.r1)

  • @ebran said in Can't connect GPy to pybytes with NB-IoT:


    •            socket.dnsserver(1,'')

    @ebran can I ask how you modified this library?

  • @Xykon Telia allows tcp/ip mqtt access.

    It was as I suspected, a DNS server issue. I solved it by modifying the pybytes source code to use Google DNS.

    diff --git a/lib/ b/lib/
    index b7c3f49..3d16201 100644
    --- a/lib/
    +++ b/lib/
    @@ -130,6 +130,10 @@ class PybytesConnection:
                     print("You need a device with FiPy or GPy firmware to connect via LTE")
                     return False
    +                # use Google DNS servers
    +                socket.dnsserver(0,'')
    +                socket.dnsserver(1,'')
                     from network import LTE
                     print_debug(1, 'LTE init(carrier={}, cid={})'.format(lte_cfg.get('carrier'), lte_cfg.get('cid', 1)))

    And also need to reset modem on boot-up, because otherwise it can hang when connecting to the MQTT server, for whatever reason (?):

    # -- run on boot-up
    from network import LTE
    print("Resetting modem...", end="\r")
    lte = LTE()
    print("Resetting modem... Done.")

    I have to disable pybytes autostart in the json file, to get this working, obviously.

    // Erik

  • administrators

    @ebran Are you sure Telia is allowing tcp/ip mqtt access to 3rd party platforms via NB-IoT? A lot of providers place restrictions on what you can do and only allow connectivity to their own proprietary platform. I've briefly looked through what's available on google and I only found information on how to connect to the Telia cloud platform through nb-iot.

Pycom on Twitter