4

I'm using a Telit LE910-C1 module to connect my ESP32 to internet through a SIM card. I don't know much about how modems work but I inherited a code which works correctly (establishing a connection).

The problem is that it works only with the SIM it was developed for (Vodafone Italy). If I switch SIM with another that is linked to another phone operator it seems not to work anymore. I suppose it is because the APN is hardcoded into the code (which I cannot share) and I would like to know if there is a way to automatically configure the modem with the information it can retrieve from the SIM.

  • Is there a procedure to follow?
  • Should I set some flags into the modem to automatically config itself through some AT command?
  • Is there a sequence of AT command to set it?

My solution up to now is to ask the operator to the SIM and set the APN through an external BT device with that information but you can imagine it is more like a workaround.

As you can notice I don't have a lot of knowledge about this kind of technology so if I'm lacking in information I will try to provide them as precise as I can.

Here the AT command guide PDF of my device.

Roberto Caboni
  • 7,252
  • 10
  • 25
  • 39
  • Are you able to edit the code you inherited? Changing the APN is just a single AT command. Furthermore: are you able to send single commands to the module with a simple terminal? What operator are you switching to? Are we talking about TCP connections? – Roberto Caboni Feb 07 '20 at 09:02
  • @RobertoCarboni yes, I'm able to modify the code and send new AT commands to the modem but i dont want to set an hardcoded apn since it should works with any possible SIM card used. Some collegues of mine said that it should be automatic but when I use the AT+CGDCONT? command it returns the apn previously hardcoded into the code (there were a AT+CGDCONT=2,\"IP\",\"mobile.vodafone.it\"\r command too but i disabled it). Others said that there should be a "special" SMS to the provider that returns the apn to use, but i cant find enough information that explain which sms it is – Seriousl Lancerl Feb 07 '20 at 10:49
  • Your information are correct. The command I was talking about is exactly `+CGDCONT`. I woonder if you would accept a "bad news" answer.. I could complete it with a workaround, but this workaround requires a further info: when you write _"any possible SIM card used"_ you mean in your country (Italy?) in a set of countries or really for EVERY provider in the world? – Roberto Caboni Feb 07 '20 at 11:02
  • this should work worldwide and not solo in my country(italy), for now the goal are the entire Europe and America. – Seriousl Lancerl Feb 07 '20 at 13:36
  • After an hard work, I built a (IMO) nice answer. It might have bad news, but I'm sure it will provide a good piece of help. – Roberto Caboni Feb 07 '20 at 18:09
  • I had a similar problem a few years back, and eventually found out that the LE910 didn't actually need the APN to be specified, nor many of the other network registration steps our code had previously performed manually on earlier models. I found removing those command and letting the LE-910 use all its defaults was more reliable and performed the 4G registration process better (with 3G fallbacks etc). The APN name is populated from "the server" during initial connection, which suprised me. This is on Telstra, Vodafone or Optus in Australia. Presumably using the OMADM mentioned below. – scipilot Aug 29 '22 at 03:25
  • The details are in "Telit_LE9x0_Registration_Flow_r2.pdf" available on their download zone. – scipilot Aug 29 '22 at 03:27

1 Answers1

4

Unfortunately, there's not an universal recipe for obtaining the APN update that can be used for data traffic. In fact, operators behaviors are different with each other, and what works for one of them might not work for another one.

I will try to explain all the solutions and the reason why they could not work. I will base my answer on the fact you are using LE910-C1 module, which is a LTE device.

General introduction

Before 4G era, cellular devices did not require an APN in order to complete the network registration. It was required just in case of PDP context activation, which in turn was performed whenever packed data had to be exchanged.

The APN was written within the modem's NVM by means of the +CGDCONT AT command:

AT+CGDCONT=<contextID>,<PDP Type>,<APN>[,...]

// Example
AT+CGDCONT=1,"IP","mobile.vodafone.it"

With LTE, things changed: the PDP context was required also for the basic registration to the network, because of the support of VoLTE (Voice Over LTE) and IMS (a service used to send SMS over LTE).

Solution 1: +CGDCONTRDP command

For backward compatibility with old 2G & 3G world, in order to register to the network without setting +CGDCONT, LTE devices have the capability to retrieve the APN from the network.

This registration info can be queried by issuing AT+CGDONTRDP command (PDP Context Read Dynamic Parameters) that, according to the AT guide you linked, has the following syntax:

AT+CGCONTRDP=[<p_cid>]

And generates a response with N lines with the following format

+CGCONTRDP:<p_cid>,<bearerId>,<apn>[,<ip&subnet>[,<gw_addr>[,<DNS_prim>[,<DNS_sec>[, <P_CSCF_prim>[,<P_CSCF_sec>]]]]]]

As you can see it provides a lot of information about the activated APN, like for example p_cid (context ID, equal to 1 for the context activated by registration), the IP address and above all the APN name.

Good news: we have an APN name related to the current operator. You could try removing at all +CGDCONT from your script and you could find out that your device is able to connect on its own (or with little adjustment).

Bad news: it is not guaranteed that the same APN name can be used by the user for their data exchange. Some operators (e.g. Verizon) have a specific APN for registration (which gets a private network IP address, useless for custom data exchange), so that the user has to activate another PDP context in order to exchange data.

Solution 2: OMADM

Some operators (e.g. Verizon, in USA) implement a special protocol defined by OMA Alliance for Device Management: OMADM. As also explained my answer to this question, it allows the network operator to retrieve (and set!) several settings.

APN is one of them: the network is aware of any change in Device-SIM couple, and if they change starts a DM session in order to update APN name. Of course the device must support this very specific protocol.

Bad news: there's not absolutely any guarantee that every operator in the world supports this APN update mechanism. Furthermore any of these mechanisms are very operator-specific, and would require modem's vendor customization for every operator.

A simple workaround

You could build a look-up table within your code, matching each operator with the corresponding APN:

  1. Query the current operator with AT+COPS?
  2. Search it within your look-up table
  3. If it is changed since last power-on of your device (you could store somewhere in your flash memory the lastOperator name), change APN to the one found in the lookup-table by issuing AT+CGDCONT command

Pro: It would be quite easy, and not so memory consuming, building a look-up table covering the entire Europe and at least North America countries (by the way: make sure that your device is actually suitable for the area you want use it in: not all devices support the RF bands to be used worldwide).

Cons: it is not something "universal", as requested by the question, and it is something that will definitely have to be mantained. I suggest you to implement a recovery solution, in which you manage a special SMS updating APN to a custom value.

Roberto Caboni
  • 7,252
  • 10
  • 25
  • 39
  • 1
    Thanks a lot, i really appreciate your answer, it is very clear and detailed. I read a lot of solution around the internet (some pretty similar to your analysis) but those weren't that detailed. Thanks for clearing up my doubts =). – Seriousl Lancerl Feb 07 '20 at 20:15