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



  • 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
    

Log in to reply
 

Pycom on Twitter