Can't connect to local Machine IP through TCP From Arduino Uno using SIM900 Shield
Question: So you have a basic understanding of the parts im using, I have:

  * Arduino Uno

  * Seeed Studio GPRS Shield v2.0 (<http://www.seeedstudio.com/wiki/GPRS_Shield_V2.0>)

  * Ultimate GPS for Adafruit V3.3 (<https://www.adafruit.com/products/746?gclid=Cj0KEQjw3-W5BRCymr_7r7SFt8cBEiQAsLtM8qn4SCfVWIvAwW-x9Mu-FLeB6hLmVd0PAPVU8IAXXPgaAtaC8P8HAQ>)

Here is my problem: I have tested the Arduino stacked with the GPRS shield,
and it works fine with regards to accessing the internet through TCP, sending
SMS, etc.. However, my application requires me to send GPS data from the
adafruit GPS to a web server that I have already coded with Django and
postgresql. The backend is set up.

I need to send the data from the Uno (client) to my laptop (server), which I
coded in python (This is just to check whether it is creating a connection):

    
    
    #!/usr/bin/env python
    import socket
    # import postgres database functions 
    
    TCP_IP = '192.168.1.112'
    TCP_PORT = 10000
    BUFFER_SIZE = 40
    
    server_address = (TCP_IP,TCP_PORT)
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    print 'Socket created.'
    
    # Bind socket to TCP server and port
    try:
        s.bind(server_address)
    except socket.error as msg:
        print 'Bind failed. Error Code : ' + str(msg[0]) + ' Message ' + msg[1]
        sys.exit()
    print 'Socket Bind Complete.'
    
    # Start Listening on socket
    s.listen(1)                                             # Puts socket into server mode
    print 'Listening on port: ', TCP_PORT 
    
    # Now Keep Talking with the client
    while (1):
        # Wait to accept a connection
        conn, addr = s.accept()                                 # Wait for incoming connection with accept()
        print 'Connection address:', addr
    
        data = conn.recv(BUFFER_SIZE)
    
        if not data: break
    
        print "recieved data: data", data
    
        conn.send(data) #echo
    conn.close()
    

I dont think there is a problem with this. From this I will post data to my
postgreSQL database. However, When I try to use AT commands on the SIM900
module to connect to the server using port 10000, I cannot connect:

    
    
    AT+CIPSHUT
    
    SHUT OK
    AT+CGATT?
    
    +CGATT: 1
    
    OK
    AT+CIPMUX=0
    
    OK
    AT+CSTT="fast.t-mobile.com","",""
    
    OK
    AT+CIICR
    
    OK
    AT+CIFSR
    
    6.60.94.49
    AT+CIPSTART="TCP","192.168.1.112,"10000"
    
    OK
    
    STATE: TCP CLOSED
    
    CONNECT FAIL
    

I have tried connecting through TCP and replaced the AT+CIPSTART line with the
below statement and it worked, so I know TCP works:

    
    
    AT+CIPSTART="TCP","www.vishnusharma.com", "80"
    

Is the IP i'm using wrong? I'm new to this, but if it makes a difference, im
using Ubuntu 16.04 partitioned on my Mac OSX. I have also checked the APN for
T-mobile and it seems fine.

Any help would be greatly appreciated. Thank You!


Answer: The IP you're using is inside a
[NAT](https://en.wikipedia.org/wiki/Network_address_translation) since it
starts with 192.168. Unless you have a private apn with the mobile operator
you're using, you won't be able to reach your Ubuntu from a public IP. Your
ISP gives you a public IP address which ir administrated by your router, so if
you want this to work, you'll have to do a [port
forwarding](https://en.wikipedia.org/wiki/Port_forwarding) from your router to
your Ubuntu.

To do the port forwarding you have to get in the router's configuration page
(Typically 192.168.1.1 but depends on the model) an there you'll have to
redirect the port XXX to 192.168.1.112:10000. After that you have to obtain
your public IP (`curl ifconfig.co`) and use it to access from the SIM900.

