GregClem
GregClem

Reputation: 1

SIM7080G Long connection

I have a SIM7080G module. The connection does not seem constant. Sometimes, in 2 seconds I am connected to the network and sometimes, it will take 10 minutes. I’m wondering if the AT commands I’m sending are in the correct order or relevant. Could anyone help me? My module sleeps and wakes up every 5 to 10 min, once awake, I send the following commands (I check the errors, I don’t put the responses to simplify reading):

AT+CFUN=1
AT+COPS=0
AT+CNMP=38
AT+CMNB=1
AT+CGREG? => wait for response +CGREG: 0.5 or +CGREG: 0.1 => sometimes it’s instantaneous and sometimes it takes more than 10 min
AT+CNCFG=0.1, “hologram”
AT+CGDCONT=1,“IP”,“hologram”
AT+CGNAPN
AT+CNACT=0.1 =>  AT+CNACT=0,1\r\r\nOK\r\n\r\n+APP PDP: 0,DEACTIVE\r\n'

AT +CSQ => AT+CSQ\r\r\n+CSQ: 22.99\r\n\r\nOK\r\n

I tried to reset the SIM7080G module with CFUN=1.1

I tried to select a provider, but I still get the response ERROR = > '+COPS=1,2,"20801"'

Upvotes: 0

Views: 104

Answers (1)

Kris Mclean
Kris Mclean

Reputation: 31

The code below works OK for the rpi2040/SIM7080 with Telstra here in Australia Greg. With the 7080 I find the main issue is with network attachment, connection not so much.

from machine import Pin,UART; uart=UART(0); from time import sleep, ticks_ms as ms; pwrkey=Pin(14,Pin.OUT); led=Pin(25,Pin.OUT); ms0=ms(); import sys

def _uart(cmd, want='OK', timeout=100):                                                                                                               # read until timeout or we get what we want
  uart.read(); uart.write(cmd+'\r\n'); r=b''; now=ms()                                                                                                # clear the buffer, write
  while (ms()-now)<timeout:
    if uart.any():
      r+=uart.read()
      if want in r: sleep(.1); r+=uart.read() if uart.any() else ''; return 1, r.decode()                                                             # get extra characters after the want just in case
  return 0, r

def boot_modem():                                                                                                                                     # check modem is on
  flag=1; tout=10; led(1)                                                                                                                             # 10ms uart reply timeout, generally takes 6 polls
  for i in range(10):
    r,R=_uart('at+cmnb?', 'OK', tout); mode='?'
    if r:
      if '1' in R: mode='cat-M1'
      elif '2' in R: mode='nb-IoT'
      r,R=_uart('at+cgmr','7080\r\n\r\nOK\r\n',tout)                                                                                                  # get firmware release & LTE mode to verify modem is up
      if r: print('%04d'%(ms()-ms0), 'mode:'+mode, 'firmware:'+R.split('n:')[1][:14], str(i)+'x'+str(tout)+'ms'); return r                            # 'at+cgmr\r\r\nRevision:1951B07SIM7080\r\n\r\nOK\r\n' --> Revision:1951B07SIM7080
    if flag: pwrkey(1);sleep(1.4);pwrkey(0);sleep(1); flag=0; print('%04d'%(ms()-ms0), '7080G pwrup')                                                 # needs >800ms dly for 6 poll rapid pwrup
  print('NoModem', R)

def check_attached():
  tout=100
  for i in range(450):
    r,R=_uart('at+cgatt?','T: 1', tout); led.toggle()                                                                                                 # 100ms timeout gives ~21 cycles for 2s attchment
    if r: print('%04d'%(ms()-ms0), 'attached', str(i)+'x'+str(tout)+'ms'); 
  return r
  print('no attachment', R)

def check_connected():
  for i in range(9):
    _uart('at+cncfg=0,1'); r,R=_uart('at+cnact=0,1','0,1')
    if r: print('%04d'%(ms()-ms0), 'connected in', i+1, 'trys'); led(1); return 1
  else: print('no connection', R); led(0)

def _getss():                                                                                                                                         # on pwrup & sms request
  try:
    print(' _getss', end='  '); num=ss='?'
    r,R=_uart('at+ceng?', ',-')
    print(repr(R))
    if r: lst=R.split('G: 0,"')[1].split(','); ss=lst[2] if len(lst)>5 else ''                                                                        # eg 'at+ceng?\r\r\n+CENG: 1,1,4,LTE CAT-M1\r\n\r\n+CENG: 0,"9410,77,-88,-62,-12,7,8313,135224587,505,01,255"\r\n+CENG: 1,"450,42,-95,-76,-11,7"\r\n+CENG: 2,"450,160,-108,-76,-20,7"\r\n+CENG: 3,"1275,385,-102,-79,-15,7"\r\n\r\nOK\r\n'
    if ss[0]=='-' and ss[1:].isdigit():
      ss=int(ss[1:])                                                                                                                                  # this flav of upython happy to integerise a string without floating it 1st
      if ss>70:
        ssbars=[120, 110, 100, 90, 80, 70]; bar=0                                                                                                     # so >120=0 111-120=1 101-110=2 91-100=3 81-90=4 71-80=5 <71=6
        for s in ssbars:
          if ss>s: bar=ssbars.index(s); break
      else: bar=6
      if bar>=0:
        msg=' 4G signal strength(0-6)='+str(bar)
  except Exception as e: sys.print_exception(e)


print(' ms  simcom 7080G rapid connect')
print(_uart('at+cclk?'))                                                                    # 64,300 netlight flashing
if boot_modem() and check_attached(): _uart('at+clts=1'); 
print(_uart('at+cclk?'), end=' '); print(_uart('at+cclk?'))                                 # 1st at+cclk returns "80/01/06,11:00:05+44"\r\n\r\nOK\r\n\r\nDST: 1\r\n\r\n*PSUTTZ: 22/10/18,01:48:25","+44",1\r\n')
check_connected()
_getss()
r,R=_uart('at+cmnb=1;+cgsms=2'); print(r,R)

Upvotes: 0

Related Questions