netskink
netskink

Reputation: 4539

How connect to LTE cell network with PyCom FiPy?

I'm trying to get a PyCom FiPy board working with LTE network connection. I have a hologram sim card. I am using two pieces of code. One is from the PyCom docs the other is from code I found on the PyCom forum for debugging LTE.

First code snippet from PyCom LTE Docs

import time
from network import LTE

print('main-testy.py starting.  This is the code snippet from pycom docs')

#lte = LTE(carrier="verizon")
lte = LTE()


print("trying to attach")
lte.attach(band=13)
while not lte.isattached():
    time.sleep(0.5)
    print('Attaching...')

print("trying to connect")
lte.connect(cid=3)
while not lte.isconnected():
    time.sleep(0.5)
    print('Connecting...')

# Now use sockets as usual...

Output

The first few times I ran this code it would attach and then generate a python error on the lte.connect call. The original sample uses a carrier of 'verizon' but a forum post said that was not necessary.

>>> Running main-testy.py

>>> 
>>> 
main-testy.py starting.  This is the code snippet from pycom docs
trying to attach
Attaching...
Attaching...
Attaching...
.. never attaches

Second code snippet from PyCom LTE Forum Posts

Looking through the forums, I found some other users with similar problems. I combined their attempts with some of the avaialable commands from the docs to write this code. It gives some basic info about the simcard and modem. Here is that code.

# Determine carrier notes
from network import LTE


# 1817



lte = LTE()

def send_at_cmd_pretty(cmd):
    response = lte.send_at_cmd(cmd).split('\r\n')
    for line in response:
        print(line)


print("get phy status")
send_at_cmd_pretty('AT!="showphy"')     # get the PHY status
print("get System FSM")
send_at_cmd_pretty('AT!="fsm"')         # get the System FSM
print("get System COPS.  PLMN Selection: +COPS")
print("!!!!!!!!!1 always generates error !!!!!!!!!!!!")
send_at_cmd_pretty('AT+COPS=?')         # get the System FSM


print("get conformance test modes. List of carriers? ")
send_at_cmd_pretty("AT+SQNCTM=?")       # get list of carriers for
# results are
# "3gpp-conformance", "att", "docomo", "kt", "lgu", "softbank", "standard", "telstra", "verizon")

results = lte.imei()
print("lte.imei results \n{}" . format(results))


results = lte.iccid()
print("lte.iccid results \n{}" . format(results))

Output

All of this code runs but one of the commands (+COPS) gives an error. I did check the AT command reference and the syntax is +COPYS=? appears correct. Perhaps that particular command can only be issued once its attached.

>> Running lte-basic-operations.py

>>> 
>>> 
get phy status

DL SYNCHRO STATISTICS
=====================
    Synchro state                         : OFF
    PPU SIB1 ACQ watchdog                 : 0
    Frequency Hypothesis RF  (Hz)         : 0
    RSRP (dBm)                            : 0.00
    RSRQ  (dB)                            : 0.00
    Channel estimation state (Cell-spec.) : LOW CINR
    Channel estimation state (UE-spec.)   : LOW CINR
    Channel estimation state (MBSFN)      : LOW CINR
    Channel estimation CINR               : 0.00
    Channel length                        : SHORT
  AGC
    AGC RX gain (dB)                      : 0.00
    RX PSD BO (dBFs)                      : 0.00
    RX PSD (dBm)                          : 0.00
    Noise level RS (dBm)                  : 0.00
    Digital gain (dB)                     : 0.00
    CINR RS (dB)                          : 0.00
  NARROWBANDS
    Last DL NB                            : 0
    Last UL NB                            : 0
  AFC
    Frequency offset RF  (Hz)             : 0
    Frequency offset BB  (Hz)             : 0
  PBCH
    MIB received quantity                 : 0
    MIB timeout quantity                  : 0

OK

get System FSM

SYSTEM FSM
==========
    +--------------------------+--------------------+
    |            FSM           |        STATE       |
    +--------------------------+--------------------+
    | RRC TOP FSM              |STOPPED             |
    | RRC SEARCH FSM           |NULL                |
    | RRC ACTIVE FSM           |NULL                |
    | PMM PLMN FSM             |NULL                |
    | EMM MAIN FSM             |NULL                |
    | EMM AUTH FSM             |NULL                |
    | EMM CONN FSM             |NULL                |
    | EMM TAU FSM              |NULL                |
    | EMM TEST FSM             |NULL                |
    | ESM BEARER FSM           |BEARER_NULL         |
    | SMS MT FSM               |IDLE                |
    | SMS MO FSM               |IDLE                |
    | HP MAIN FSM              |IDLE                |
    | HP USIM FSM              |NULL                |
    | HP SMS MO FSM            |IDLE                |
    | HP SMS MT FSM            |IDLE                |
    | HP CAT FSM               |NULL                |
    +--------------------------+--------------------+

OK

get System COPS.  PLMN Selection: +COPS
!!!!!!!!!1 always generates error !!!!!!!!!!!!

ERROR

get conformance test modes. List of carriers? 

+SQNCTM: ("3gpp-conformance", "att", "docomo", "kt", "lgu", "softbank", "standard", "telstra", "verizon")

OK

lte.imei results 
354346095554902
lte.iccid results 
8944500208186565235
>

Upvotes: 1

Views: 1609

Answers (2)

netskink
netskink

Reputation: 4539

I did manage to get LTE working with a hologram card. However, it is not 100% reliable. Sometimes it will stall or get hung up. Any opinions is appreciated.

import time
from network import LTE
import utime
import machine
import _thread

print('main-testy.py starting.  This is the code snippet from pycom docs')

def send_at_cmd_pretty(cmd):
    response = lte.send_at_cmd(cmd).split('\r\n')
    for line in response:
        print(line)

def do_ntp(a_server):
    # Syncing time
    RTCI = machine.RTC()
    print('Syncing time with %s' % a_server, end='')
    RTCI.ntp_sync(a_server)
    while not RTCI.synced():
        print('.', end='')
        utime.sleep(1)
    print('')

def get_time_as_string():
    year, month, mday, hour, minute, second, weekday, yearday = utime.localtime()
    # form an iso time string
    # eg. 1985-12-04T23:20:50
    a_string = '{}-{:02d}-{:02d}T{:02d}:{:02d}:{:02d}' . format(year, month, mday, hour, minute, second)
    return a_string


###############################################


lte = LTE()
lte.reset()
lte.init()



print("trying to attach")
#lte.attach(band=13)
lte.attach()
while not lte.isattached():
    time.sleep(0.5)
    #print('Attaching...')
    print('Attaching...', end='')
    send_at_cmd_pretty('AT+CEREG?')         # get the System FSM

time.sleep(5)


print("trying to connect")
#lte.connect(cid=3)
lte.connect()
while not lte.isconnected():
    time.sleep(0.5)
    print('Connecting...')

time.sleep(5)



# Now use sockets as usual...
print('**** connected ***********************')


do_ntp('time.google.com')
#do_ntp('pool.ntp.org')
time.sleep(5)
print(get_time_as_string())

Upvotes: 0

Christian Ehlers
Christian Ehlers

Reputation: 11

When using a Hologram SIM card you shouldn't use the Verizon profile as this is only for Verizon SIM cards. Also with Hologram the CID should be 1, 3 is only for Verizon SIM cards.

Even though the ICCID command returns a result, there seems to be an issue with the SIM card as HP USIM FSM reports NULL.

Can you please first of all try lte.factory_reset() and then try again with cid=1?

If the problem persists please contact Pycom support https://pycom.io/community/contact-support/

Upvotes: 0

Related Questions