SparkFun Forums 

Where electronics enthusiasts find answers.

Tips and questions relating to the GPS modules from SFE
By copernicus
#36239
Hi

I'm trying to open an UDP socket via python script, but when I send the command AT#SKTOP, I receive the message NO CARRIER from the module.
I know that the problem isn't the configuration because I can open the socket via AT commands. Does any one have any idea of how can I fix it?

I'm using the 7.02.403 firmware version.

If there is any other relevant information that you need to think about the solution, just ask. But remember that I can connect via AT commands.
Code: Select all
import MDM
import MOD
import SER

def delay_s(seg):
    MOD.sleep(seg*10)
    

def delay_m(min):
    while min > 0:
        delay_s(60)
        min = min - 1

def send_TX(text):
    a = SER.send(text)
    if a != 1:
        a = SER.send(text)
    a = SER.sendbyte(13)
    a = SER.sendbyte(10)        
    
def send_AT(text):
    a = MDM.send(text + '\r',0)
    if a != 1:
        a = MDM.send(text + '\r',0)

def receive_AT(timeout):
    return MDM.receive(timeout*10)

def init():
    send_AT('ATE0')
    a = SER.set_speed('9600','8N1')
    
def skt_config():
    send_AT('AT#PKTSZ=300')
    send_AT('AT#DSTO=50')
    send_AT('AT#SKTTO=90')
    send_AT('AT#SKTCT=600')
    send_AT('AT#USERID=EasyGPRS')
    send_AT('AT#PASSW=EasyGPRS')
    send_AT('AT+CGDCONT=1,"IP","tim.br",,,')
    send_AT('AT#SKTSET=1,1720,"200.246.118.2",255,1025')

def connect_GPRS():
    send_AT('AT#GPRS=1')
    send_TX('AT#GPRS=1')

def check_GPRS():
    send_AT('AT#GPRS?')
    b = receive_AT(2)
    if b.find('#GPRS: 1') != -1:
        send_TX('GPRS: OK!')
        return 1
    else :
        send_TX('GPRS: ERROR!!')
        return 0

def open_SKT():
    send_TX('AT#SKTOP')
    send_AT('AT#SKTOP')

def close_SKT():
    send_AT('+++')

def send_GPS_data():
    send_AT('AT$GPSACP')
    b = receive_AT(2)
    c = 0
    comma = 0
    while c < len(b):
        if b[c] == ':':
            hora = b[c+2:c+8]
        if b[c] == ',':
            if comma == 0:
                latitude = b[c+1:c+10]
                if b[c+10] == 'S':
                    latitude = '-' + latitude
                else :
                    latitude = '+' + latitude
            elif comma == 1:
                longitude = b[c+1:c+11]
                if b[c+11] == 'W':
                    longitude = '-' + longitude
                else :
                    longitude = '+' + longitude
            elif comma == 8:
                data = b[c+1:c+7]
            comma = comma + 1
        c = c+1
    data = data[0:2] + '/' + data[2:4] + '/' + data[4:6]
    hora = hora[0:2] + ':' + hora[2:4] + ':' + hora[4:6]
    lat = latitude
    lon = longitude
    century_data = '$century,ID,'+hora+','+lat+','+lon+','+data
    send_AT(century_data)
    send_TX(century_data)

def main():
    delay_s(2)
    init()
    skt_config()
    send = 0
    while 1:
        if send == 1:
            delay_m(1)
            send = 0
        if check_GPRS() == 0:
            send_TX('connecting...')
            connect_GPRS()
            delay_s(5)
        else :
            open_SKT()
            delay_s(2)
            send_GPS_data()
            close_SKT()
            send = 1
I still have to check the century_data, but it doesn't matter now...

Thanks!!
By copernicus
#36593
The problem was solved using the command AT#SKTD instead of AT#SKTSET and AT#SKTOP.

I'm trying to make a car tracker, that send the coordinates via an UDP socket. I can open the socket via python script but I can't close it. Even when I set the timeout to 20 sec it doesn't close after the timeout. Does any one knows how can I close the socket?

I need to close the socket to request de GPS information from the AT interface (AT$GPSACP). I can get the gps data connecting the GPS_TX to the serial port RX. But I don't like it...

Can you understand what I'm saying?
I need some help here!

Thanks!!
By orb
#40438
Hi copernicus

I see you are in athread by yourself here... until I came along.

I am attempting to do something similar to you - but seem to working a little blind as I do not have the Evaluation kit (yet). Do you use the kit for development?

I have tried your code to get my unit to create a TCP connection - but when looking at the server I still do not see anything coming through.

I would like to "join resources" - so please let me know if you are interested in exchanging ideas.

D