Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    Can't connect GPy to pybytes with NB-IoT

    Scheduled Pinned Locked Moved Support & Troubleshooting
    gpy nbiotpybytesconnect issuesdns
    9 Posts 4 Posters 783 Views 4 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • E Offline
      ebran
      last edited by ebran

      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

      X 1 Reply Last reply Reply Quote 0
      • X Offline
        Xykon administrators @ebran
        last edited by

        @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.

        Christian Ehlers

        E 1 Reply Last reply Reply Quote 0
        • E Offline
          ebran @Xykon
          last edited by

          @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

          S 1 Reply Last reply Reply Quote 0
          • S Offline
            Scott Basgaard @ebran
            last edited by

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

            socket.dnsserver(0,'8.8.8.8')

            •            socket.dnsserver(1,'8.8.4.4')
              

            @ebran can I ask how you modified this library?

            E 1 Reply Last reply Reply Quote 0
            • G Offline
              Gijs
              last edited by

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

              S 1 Reply Last reply Reply Quote 0
              • S Offline
                Scott Basgaard @Gijs
                last edited by

                @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 8.8.8.8. and 8.8.4.4 in manual LTE connect tests.

                1 Reply Last reply Reply Quote 0
                • G Offline
                  Gijs
                  last edited by

                  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?
                  Best,
                  Gijs

                  S 1 Reply Last reply Reply Quote 0
                  • S Offline
                    Scott Basgaard @Gijs
                    last edited by

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

                    1 Reply Last reply Reply Quote 0
                    • E Offline
                      ebran @Scott Basgaard
                      last edited by

                      @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.

                      1 Reply Last reply Reply Quote 0

                      Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                      Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                      With your input, this post could be even better 💗

                      Register Login
                      • 1 / 1
                      • First post
                        Last post

                      Pycom on Twitter

                      Pycom