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

    if lte.is attached() makes it think it's not

    Scheduled Pinned Locked Moved Issues & Bugs
    if lte.isattachgpy
    1 Posts 1 Posters 397 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

      I can run this program repeatedly & it works OK

      import time, pycom, machine
      import urequests as requests
      from network import LTE
      lte = LTE()
      pycom.heartbeat(False)
      
      def getLTE():
        if lte.isconnected(): return lte
        if not lte.isattached():
          print('attaching ', end=''); lte.attach()
          while not lte.isattached(): print('.', end=''); time.sleep(1)
        if not lte.isconnected():
          print('connnecting ', end=''); lte.connect()
          while not lte.isconnected(): print('.', end=''); time.sleep(1)
        return lte
      
      getLTE()
      r=requests.get('http://micropython.org/ks/test.html'); print(r.text)
      lte.disconnect()
      

      But if I add one extra line to check the modem is still attached

      import time, pycom, machine
      import urequests as requests
      from network import LTE
      lte = LTE(); rtc = RTC()
      pycom.heartbeat(False)
      
      def getLTE():
        if lte.isconnected(): return lte
        if not lte.isattached():
          print('attaching ', end=''); lte.attach()
          while not lte.isattached(): print('.', end=''); time.sleep(1)
        if not lte.isconnected():
          print('connnecting ', end=''); lte.connect()
          while not lte.isconnected(): print('.', end=''); time.sleep(1)
        return lte
      
      getLTE()
      r=requests.get('http://micropython.org/ks/test.html'); print(r.text)
      if lte.isattached(): pycom.rgbled(0x007f00)
      lte.disconnect()
      

      it won't run a second time. On the second run it behaves like it thinks it's not attached. It looks like asking if it's attached makes it think it's not?!

      attaching Traceback (most recent call last):
        File "<stdin>", line 18, in <module>
        File "<stdin>", line 11, in getLTE
      OSError: the requested operation failed
      
      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