serverip-addressgsmat-commandsim800

How do I get the public IP address when starting a GSM modem in server mode?


I have a SIM800C GSM module that I want to use to make a server. I am really confused about knowing the public IP address. In order to make people to connect to any server is that they need the correct public IP address and the correct port, and of course the correct protocol (TCP, HTTP and so on..).

There is already a command to get the local IP address (AT+CIFSR); in case I make a server and I want to let my friends connect to it, I need the public IP address. How do I get it?

I searched on the internet but found nothing.


Solution

  • AT+CIFSR (as well as the standard command AT+CGPADDR) returns your IP as soon as you activate the PDP context. Unfortunately, if it is public or not depends on your operator. In fact, due to the need to face the IPv4 address exhaustion they often perform a Network Address Translation (NAT) that will actually provide a local IP to your device.

    As a consequence, your device won't be reachable for communications that are not device-initiated, and you won't able to create a public server at all.

    So, that's not a public IP opposed to a local IP: there's just the IP you obtain from the network. If doesn't perform NAT, then the IP you obtain with AT+CIFSR will be the public one.


    Design work-around

    Usually the NATted IP limitation is faced with a design trick

    1. A wake-up SMS is sent to the device hosting the server. The SMS can either be a basic one (just text containing data relevant to the application) or a special SMS type (Wap Push notifications).
    2. As soon it receives the SMS, the device starts the server and sends some data to the remote peer
    3. This will result in a device initiated communication, so from the network side the NAT will be opened and the device will be temporarily public.
    4. After a certain inactivity time (operator dependent) the NAT will be closed again

    "Commercial" solution

    If the design solution is not feasible, there's another option involving the purchase of special (and more expensive...) SIMs specific for M2M and IOT applications:

    1. SIMs which will always obtain a public IP
    2. SIMs which will always obtain a public fixed IP