How to pass lte cmds to a fn?

  • If I do

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

    the modem disconnects


    def lte_cmds(d):
    from network import LTE; lte=LTE()


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

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

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

    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.

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


Log in to reply

Pycom on Twitter