How to select APN automatically in SIM800L GPRS module interfacing with ESP32

1.8k Views Asked by At

I have been working on a SIM800L GPRS module with ESP32. My purpose is to post data to a IoT platform using GPRS. I'm using sim800l library.

Here in the code i want to provide apn manually like this,

const char APN[] = "airtelgprs.com";

is there any possible method to assign apn automatically?

1

There are 1 best solutions below

0
On

It's possible, but not simple. There are people who maintain a public database of network providers in the world and their access points: Service Provider Database. Upon logging into a GSM network you can choose the correct APN based on the MCC and MNC of what your GSM module is reporting. It's not entirely trivial, as the database file is over 341 KiB (but it's XML, so lots of redundancy).

The most annoying factor is that there are entries with different APNs, but same combination of MCC and MNC. This means there are networks with look exactly the same to the GSM module, but use different APNs. In such case you cannot automatically choose an APN and expect it to work. Either the user would have to choose between the alternative APNs or you'd have to try them out one by one until you succeed in connecting to the Internet.