0

Cellular survey?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Cellular survey?

by barkerben on Sun Feb 21, 2021 7:46 am

I've been looking at the AT commands for the 5320E :

https://www.adafruit.com/product/2691

I was ideally looking for a way to survey the available mobile networks.

I can use the +COPS? AT command to see which networks are available locally
I can then loop through each, attempt to register with the network, and ask for signal quality using +CSQ

However, I assume that signal quality would be expected to change depending on whether I was connecting over 3G or 2G, so it is not clear to me what the CSQ is actually returning...

Is there a way I can query each available network for the access technologies availabile (2G / 3G etc) as well as the signal quality for each...?

Cheers!

barkerben
 
Posts: 6
Joined: Sun Feb 21, 2021 7:42 am

Re: Cellular survey?

by rskup on Sun Feb 21, 2021 9:16 am

Just a tinkerer with a FONA 3G, not an expert, but looks like:

AT+CPSI?

will tell you whether you're GSM or CDMA

and

AT+CNMP=x

can select GSM (13) or CDMA (14)

Here's the big 5320 manual where I found these:

https://simcom.ee/documents/SIM5320/SIM ... _V2.05.pdf

There's also a command to set band preference in there, AT+CNBP=x, you could possibly even check out each band under GSM or CDMA.

563 pages of commands, this much fun should be illegal!

rskup
 
Posts: 84
Joined: Sat Aug 01, 2020 9:04 pm

Re: Cellular survey?

by barkerben on Sun Feb 21, 2021 10:17 am

Good spot!
That seems to be backed up by this page (It is referring to LTE bands, but an extension of the same it seems, for modules that support that):

https://m2msupport.net/m2msupport/how-t ... 0-modules/

I'm assuming then that if I try to select a given band, I will get a success of failure, depending upon the cababilities of that cell, and if success, if I then run the +CSQ command, I will get the signal quality for that band.

I'll test it out tonight. If that works, it suggests CSQ defaults to the default preferred mode. Not sure how that default is chosen - the obvious choice would be "best available in theory" - but then, is poor quality on 3G better than great quality on GPRS. Not that it really matters :-)

Cheers!

barkerben
 
Posts: 6
Joined: Sun Feb 21, 2021 7:42 am

Re: Cellular survey?

by barkerben on Sun Feb 21, 2021 3:43 pm

Looking good.
Interestingly,. with a SIM inserted a +COPS command only shows me the operator who provided the SIM - not much use for a survey!
Perhaps for this to work I need to try with an international SIM, which lets you see all the UK networks at once

barkerben
 
Posts: 6
Joined: Sun Feb 21, 2021 7:42 am

Re: Cellular survey?

by rskup on Sun Feb 21, 2021 4:53 pm

Hmmm, looking over the big manual, curious, did you type:

AT+COPS?

or

AT+COPS=?

Looks like (according to the examples on page 81) the first one just tells you who you're currently connected to, but the second one gives you a list?!

Also looks like (again, according to the examples) the leading number (1, 2, or 3) tells you whether that network is "available", "current", or "forbidden". Guessing "forbidden" would be who your simcard isn't with.

rskup
 
Posts: 84
Joined: Sat Aug 01, 2020 9:04 pm

Re: Cellular survey?

by barkerben on Sun Feb 21, 2021 5:01 pm

Yep - the first tells you what you have, the second runs a query.

But, in the UK at least, you can't normally see operators networks other than those who own the SIM unless you are roaming abroad.
I have ordered a French SIM (which I don't plan to activate) to see whether having it inserted allows me to see the other UK networks - I suspect it may...

barkerben
 
Posts: 6
Joined: Sun Feb 21, 2021 7:42 am

Re: Cellular survey?

by rskup on Sun Feb 21, 2021 5:24 pm

Ah, ok. For kicks I think I'll try this on my FONA 3G (5320A) tonight, see what happens in the US (or at least where I live in the US).

I also have a SIM7000G breakout board with a Hologram.io simcard, is suppose to connect anywhere.

Anyways, will try both with both versions of the COPS command, see what happens.

rskup
 
Posts: 84
Joined: Sat Aug 01, 2020 9:04 pm

Re: Cellular survey?

by barkerben on Sun Feb 21, 2021 5:29 pm

Cheers :-) And I'll await my French SIM!

Btw, one useful thing:

+CSQ returns RSSI as a number from 0-199 that can be converted to dBm

It looks like the command you noticed - +CPSI - returns the same RSSI, but directly in dBm, with no conversion required, along with a load of other useful info

barkerben
 
Posts: 6
Joined: Sun Feb 21, 2021 7:42 am

Re: Cellular survey?

by barkerben on Sun Feb 21, 2021 6:57 pm

Ah - I may have spoken too soon regarding the inability to see other networks.

The below works fine, and returns a list of all networks in sight

Code: Select all | TOGGLE FULL SIZE
import serial
import pprint
import time
import re

modem = serial.Serial("/dev/ttyS0", baudrate=115200, timeout=1.0)

def cops():
        modem.write('AT+COPS=?\r\n')
        time.sleep(60)
        result=modem.read(2000)
        regex = r"(\(([^)]*)\))"
        matches = re.finditer(regex, result, re.MULTILINE)
        return matches

def csq():
        modem.write('AT+CSQ=?\r\n')
        result=modem.read(100)
        regex = r"\+CSQ:.*"
        matches = re.search(regex, result, re.MULTILINE)
        return matches.group(0)

def cpsi():
        modem.write('AT+CPSI?\r\n')
        result=modem.read(100)

        regex = r"\+CPSI:.*"
        matches = re.search(regex, result, re.MULTILINE)
        return matches.group(0)

#cpsi=cpsi()
#print cpsi

#csq=csq()
#print csq

cops=cops()
operators={}

for match in cops:
        operator =  match.group(2)
        data=operator.split(",")

        registration=data[0]

        if registration != "0":
                long_name=data[1]
                short_name=data[2]
                operator_code=data[3]
                mode=data[4]

                if operator not in operators:
                        operators[long_name]=[]

                site_data={}

                site_data["short_name"]=data[2]
                site_data["code"]=data[3]
                site_data["mode"]=data[4]
                site_data["registration"]=data[0]

                operators[long_name].append(site_data)


pp = pprint.PrettyPrinter(indent=4)
pp.pprint(operators)

barkerben
 
Posts: 6
Joined: Sun Feb 21, 2021 7:42 am

Re: Cellular survey?

by rskup on Sun Feb 21, 2021 8:15 pm

Oh, very cool, was just finishing up my tests. Like yourself, it seems like I can see all the networks around me too.

btw, thanks for posting that m2msupport link for the SIM7000, I'm still learning the details of mine and examples are great to have!

rskup
 
Posts: 84
Joined: Sat Aug 01, 2020 9:04 pm

Please be positive and constructive with your questions and comments.