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

    How to pass lte cmds to a fn?

    Scheduled Pinned Locked Moved MicroPython
    lte commandsfunctions
    3 Posts 2 Posters 412 Views 2 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.
    • K Offline
      kjm
      last edited by kjm

      If I do

      from network import LTE; lte=LTE()
      d='lte.disconnect()'; eval(d)
      

      the modem disconnects

      but

      def lte_cmds(d):
         eval(d)
      
      from network import LTE; lte=LTE()
      lte_cmds('lte.disconnect()')
      

      gives

      AttributeError: 'NoneType' object has no attribute 'disconnect'`
      

      What's a good way to pass lte commands to a function?

      T 1 Reply Last reply Reply Quote 0
      • T Offline
        timh @kjm
        last edited by

        @kjm Hi

        You first problem is one of scope.

        The lte object you have created is not in the scope of the lte_cmds() function.

        To be honest I can't work out why you would even use eval to call lte commands in this way.

        May be you should elaborate on what you are trying to do and then we can suggest approachs.

        I tend to create an instance of a class that wraps the LTE() object and provides convenience methods and tracks the state of the connection.

        T

        1 Reply Last reply Reply Quote 0
        • K Offline
          kjm
          last edited by kjm

          My problem with attach & connect is that examples in the docs like

          lte.attach()
          while not lte.isattached(): time.sleep(0.5);    print('Attaching...')
          

          can get stuck looping forever, the modem never actually attaches or connects. I wanted to write a function that I can call when I want to attach or connect that tries a fixed number of times then resets the modem &/or the gpy. To do this I need a way to pass the attach or connect cmd to the function.

          Speaking more broadly I would have thought that the basic requirements of something like a gpy in a battery powered application were pretty obvious. Wake up, use the lte to upload some data, quit if you can't get a connection in a reasonable time, sleep, repeat. After a month with this device I'm still no closer to that basic objective.

          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