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"')
    '\r\n\r\nOK\r\n'
    >>> lte.attach(band=20, apn="lpwa.telia.iot")
    >>> lte.isattached()
    True
    >>> lte.connect()
    >>> lte.isconnected()
    True
    >>> socket.dnsserver(0,'8.8.8.8')
    >>> socket.dnsserver(1,'8.8.4.4')
    >>> socket.dnsserver()
    ('8.8.8.8', '8.8.4.4')
    >>> print(socket.getaddrinfo("www.google.com", 80)[0][-1])
    ('172.217.21.132', 80)
    

    Grateful for your advice.
    // Erik



  • @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/pybytes_connection.py b/lib/pybytes_connection.py
    index b7c3f49..3d16201 100644
    --- a/lib/pybytes_connection.py
    +++ b/lib/pybytes_connection.py
    @@ -130,6 +130,10 @@ class PybytesConnection:
                     print("You need a device with FiPy or GPy firmware to connect via LTE")
                     return False
                 try:
    +                # use Google DNS servers
    +                socket.dnsserver(0,'8.8.8.8')
    +                socket.dnsserver(1,'8.8.4.4')
    +                
                     from network import LTE
                     time.sleep(3)
                     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 (?):

    # boot.py -- run on boot-up
    from network import LTE
    
    print("Resetting modem...", end="\r")
    
    lte = LTE()
    lte.reset()
    lte.send_at_cmd('AT^RESET')
    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