【问题标题】:How connect to LTE cell network with PyCom FiPy?如何使用 PyCom FiPy 连接到 LTE 蜂窝网络?
【发布时间】:2020-07-11 09:09:12
【问题描述】:

我正在尝试让 PyC​​om FiPy 板与 LTE 网络连接一起使用。我有一张全息图 SIM 卡。我正在使用两段代码。一个来自 PyCom docs 另一个来自我在 PyCom 论坛上找到的用于调试的代码 LTE

来自 PyCom LTE Docs 的第一个代码 sn-p

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

输出

前几次我运行此代码时,它会附加,然后在lte.connect 调用上生成 python 错误。原始示例使用“verizon”的载体,但论坛帖子说没有必要。

>>> Running main-testy.py

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

来自 PyCom LTE 论坛帖子的第二个代码 sn-p

浏览论坛,我发现其他一些用户也有类似的问题。我将他们的尝试与文档中的一些可用命令结合起来编写此代码。它提供了有关 simcard 和调制解调器的一些基本信息。这是代码。

# 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))

输出

所有这些代码都会运行,但其中一个命令 (+COPS) 会出错。我确实检查了 AT 命令参考,语法是 +COPYS=?看起来是正确的。也许该特定命令只有在附加后才能发出。

>> 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
>

【问题讨论】:

    标签: python iot esp32 lte pycom


    【解决方案1】:

    使用 Hologram SIM 卡时,您不应使用 Verizon 配置文件,因为这仅适用于 Verizon SIM 卡。同样对于全息图,CID 应为 1,3 仅适用于 Verizon SIM 卡。

    即使 ICCID 命令返回结果,SIM 卡似乎也存在问题,因为 HP USIM FSM 报告 NULL。

    能否请您先尝试 lte.factory_reset(),然后使用 cid=1 重试?

    如果问题仍然存在,请联系 Pycom 支持https://pycom.io/community/contact-support/

    【讨论】:

    • 我会在 factory_reset() 上尝试你的建议,但在我这样做之前,我应该在你回复之前发布我正在工作的后续内容。顺便说一句,欢迎使用 stackoverflow。
    【解决方案2】:

    我确实设法让 LTE 与全息卡一起工作。但是,它不是 100% 可靠的。有时它会停止或挂断。任何意见表示赞赏。

    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())
    

    【讨论】:

      猜你喜欢
      • 2017-07-30
      • 2013-08-13
      • 2020-12-02
      • 2021-05-15
      • 1970-01-01
      • 1970-01-01
      • 2014-08-31
      • 2013-02-05
      • 2016-12-21
      相关资源
      最近更新 更多