Programmation pyton sur "microcontroleur" GM862-GPS (fabrication d'un tracker GPS/GSM)
Répondre à la discussion
Affichage des résultats 1 à 7 sur 7

Programmation pyton sur "microcontroleur" GM862-GPS (fabrication d'un tracker GPS/GSM)



  1. #1
    invite68a65083

    Programmation pyton sur "microcontroleur" GM862-GPS (fabrication d'un tracker GPS/GSM)


    ------

    Bonjour à tous, j'aimerais réaliser un petit tracker GPS/GSM "intelligent" qui puisse donc me donner les coordonnées GPS par sms ou gprs (mail) accompagné d'une photo. Pour se faire, je vais acheter le module GM862-GPS
    accompagné d'un module caméra.

    Etant complètement débutant dans la programmation python ( j'arrive meme pas encore à ecrire un script pour autocad )

    J'aimerais avoir l'avis de personnes ayant déjà fait l'acquisition de ce module ( ou de la version PYT ) afin de me dire si je serai capable de programmer un tel projet.


    J'ai trouvé déjà un ptit script qui permet d'envoyer un sms avec les coordonnées mais jsais pas du tout si elle est bonne ( et jme vois pas acheter le module avec tous les accesoires ( + de 300€ ) pour finalement me retrouver comme un con à pas pouvoir le faire marcher )

    Voici le script:

    ##### Config #####

    sms_password = 'mypassword'


    ##### Constants #####

    TRUE = 1
    FALSE = 0


    ##### Modules #####

    #Use serial
    import SER

    #Use build in module
    import MOD

    #Use AT command interface
    import MDM

    #Use GPS
    import GPS


    ###### General Functions ######

    #Debug message
    def debugmsg(msgtext):
    msgtext = msgtext.replace('\r', '\\r')
    msgtext = msgtext.replace('\n', '\\n')
    print msgtext
    SER.send(msgtext + '\r\n')
    #f = open('log.txt','ab')
    #f.write(msgtext + '\n')
    #f.close()

    #GPS status
    def gps_status(gpspos):
    debugmsg('Retrieving GPS status')

    gpspos_parts = gpspos.split(',')

    if ( (gpspos_parts[5] == '2') or (gpspos_parts[5] == '3') ): #2D or 3D fix
    debugmsg('GPS fix "' + gpspos_parts[5] + '" ie valid');
    status = TRUE
    else:
    debugmsg('GPS fix "' + gpspos_parts[5] + '" ie not valid');
    status = FALSE

    return status


    ###### SMS Process Functions ######

    #Process SMS messages
    def sms_proceses(gpspos):
    debugmsg('Process SMS')

    #List SMS
    smsmsgs = sms_list()

    totalsms = len(smsmsgs)

    #debugmsg('SMS total: %d' % totalsms)

    #Go throguh SMS messages
    for smsmsgindex in range(0, totalsms):

    debugmsg('Message: %d' % smsmsgindex)

    #Delete SMS (it is being processed now)
    status = sms_delete(smsmsgs[smsmsgindex]['id'])

    #If status deleted ok
    if (status == TRUE):

    #debugmsg('List SMS id: %d, from: %s, msg: %s' % (smsmsgs[smsmsgindex]['id'], smsmsgs[smsmsgindex]['from'], smsmsgs[smsmsgindex]['msg']))

    #Split SMS message into parts
    smsmsgparts = smsmsgs[smsmsgindex]['msg'].split(' ')

    #If at least 2 parts
    if (len(smsmsgparts) > 1):

    #Check if password valid
    if (smsmsgparts[0].lower() == sms_password):

    debugmsg('Password valid')

    #If position requested
    if (smsmsgparts[1].lower() == 'pos') or (smsmsgparts[1].lower() == 'position'):

    debugmsg('Action: Position requested')

    #If GPS position fix valid
    if (gps_status(gpspos) == TRUE):
    gpsdataparts = gpspos.split(',')

    senddata = 'Lat: ' + gpsdataparts[1] + ', Lon: ' + gpsdataparts[2] + ', Heading: ' + gpsdataparts[6] + ', Speed: ' + gpsdataparts[7] + ' km/hr'

    else:
    senddata = 'No GPS Fix'

    #Send SMS
    sms_send(smsmsgs[smsmsgindex]['from'], senddata)

    else:
    debugmsg('Action: Unknown')

    else:

    debugmsg('Password invalid')

    else:

    debugmsg('Unable to delete')



    ###### SMS Library Functions ######

    #Setup SMS
    def sms_setup():

    debugmsg('Setting up SMS')

    MDM.send('AT+CMGF=1\r', 0)
    res = MDM.receive(50)#5 sec
    MOD.sleep(1)#wait 0.1sec

    debugmsg('SMS setup: ' + res)

    #List SMS
    def sms_list():

    #Note: Command will not return anything if SIM is not ready

    debugmsg('List SMS')

    #MDM.send('AT+CMGL="REC UNREAD"\r', 0) #ALL REC UNREAD STO SENT
    MDM.send('AT+CMGL="REC UNREAD"\r', 0)

    #smslist = ''
    #res = MDM.receive(50)#5 sec
    #smslist = smslist + res

    #while (res.find('\r\nOK\r\n') == -1):
    # res = MDM.receive(10)
    # smslist = smslist + res

    smslist = ''
    res = ''
    timeout = MOD.secCounter() + 60
    while ( (res.find('\r\nOK\r\n') == -1) and (MOD.secCounter() < timeout) ):
    debugmsg('Timeout now: %d timeout: %d' % (MOD.secCounter(), timeout))
    res = MDM.receive(50)
    smslist = smslist + res
    #debugmsg('get %s' % smslist)

    MOD.sleep(1)#wait 0.1sec

    smsparts = smslist.split('\r\n')

    smspartslen = len(smsparts)

    #debugmsg('SMS Parts %d' % smspartslen)

    smsmsgs = []

    if (smspartslen-2 > 0) and (smsparts[smspartslen-2] == 'OK'):

    #If there is at least 1 message
    if (smspartslen >= 6):

    #Go through all messages
    for partno in range(1, smspartslen):

    #Find out if this is an cmgl line
    cmglparts = smsparts[partno].split('CMGL: ')

    #If at least 2 parts, leading cmgl and data
    if (len(cmglparts) > 1) and (cmglparts[0] == '+') and (partno+1 <= smspartslen):

    #debugmsg('Found CMGL %d: %s' % (partno, smsparts[partno]))
    #debugmsg('Text %d: %s' % (partno+1, smsparts[partno+1]))

    #Split msg info line into parts
    msginfoparts = cmglparts[1].split(',')

    #Check have all parts
    #if (len(msginfoparts) > 5):
    if (len(msginfoparts) > 4):

    #int() may fail
    try:

    #Convert id to integer
    msginfoparts[0] = int(msginfoparts[0])

    #Remove quotes
    msginfoparts[2] = msginfoparts[2].replace('"', '')
    #msginfoparts[4] = msginfoparts[4].replace('"', '')
    #msginfoparts[5] = msginfoparts[5].replace('"', '')

    smsmsgs.append({'id': msginfoparts[0], 'from': msginfoparts[2], 'msg': smsparts[partno+1]})

    debugmsg('SMS id: %d, from: %s, msg: %s' % (msginfoparts[0], msginfoparts[2], smsparts[partno+1]))

    except Exception:
    debugmsg('Error CMGL %d: %s' % (partno, smsparts[partno]))

    debugmsg('SMS total: %d' % len(smsmsgs))

    else:

    debugmsg('No SMS messages available')

    return smsmsgs

    #SMS Delete
    def sms_delete(delindex):

    debugmsg('SMS Delete: %d' % delindex)

    MDM.send('AT+CMGD=' + str(delindex) + '\r', 0)
    res = MDM.receive(50)#5 sec
    MOD.sleep(1)#wait 0.1sec

    if (res == '\r\nOK\r\n'):
    status = TRUE
    else:
    status = FALSE

    return status

    #SMS Send
    def sms_send(to, text):

    debugmsg('Send SMS to: %s, MSG: %s' % (to, text))

    MDM.send('AT+CMGS="' + to + '"\r', 0)
    res = MDM.receive(50)#5 sec
    MOD.sleep(1)#wait 0.1sec

    #Check for SMS prompt
    if (res == '\r\n> '):

    #Send SMS message text
    MDM.send(text, 0)

    #End SMS
    MDM.sendbyte(0x1A, 0)
    res2 = MDM.receive(180)#5 sec
    MOD.sleep(1)#wait 0.1sec

    if (res2.find('\r\nOK\r\n') != -1):

    debugmsg('SMS sent')

    status = TRUE

    else:

    debugmsg('SMS Send: ' + res2)

    debugmsg('Did not get SMS sent confirmation')

    status = FALSE

    else:

    debugmsg('SMS Send: ' + res)

    debugmsg('Did not receive SMS prompt')

    #Abort SMS (just in case)
    MDM.sendbyte(0x1B, 0)
    MOD.sleep(1)#wait 0.1sec

    status = FALSE

    return status



    ############################## ############################## ######################


    ###### Init ######

    SER.set_speed('115200','8N1')
    SER.send('\r\n--------------------\r\n\r\n')

    debugmsg('Running...');

    #Set verbose error reporting
    MDM.send('AT+CMEE=2\r', 0)
    MDM.receive(50)#5 sec
    MOD.sleep(1)#wait 0.1sec

    #May be required in North America / Canada to switch the unit to 900/1900MHz frequency (uncomment if in those areas)
    #MDM.send('AT#BND=1\r', 0)
    #MDM.receive(1)#0.1sec
    #MOD.sleep(1)#wait 0.1sec

    gpspos_lastvalid = ''

    #Setup SMS
    sms_setup()

    #Main loop
    while 1:

    debugmsg('Entering loop')

    #Retrieve current position
    gpspos = GPS.getActualPosition()

    debugmsg('Position: %s' % gpspos)

    #Retrieve GPS fix status
    gps_statusnow = gps_status(gpspos)

    #Save last valid position
    #If position fix valid, or none recorded already, use last retrieved
    if ( (gps_statusnow == TRUE) or (gpspos_lastvalid == '') ):
    gpspos_lastvalid = gpspos

    #Check for / process new SMS messages
    sms_proceses(gpspos_lastvalid)

    debugmsg('Powersave for 10 seconds')

    #Powersave for 10 seconds
    MOD.powerSaving(10)




    Donc, en éspérant que ce petit programme fonctionne, il va falloir ajouter quelques lignes permettant la prise de photo via la petite camera ...

    Merci pour votre aide !

    -----

  2. #2
    invite13111c20

    Re : Programmation pyton sur "microcontroleur" GM862-GPS (fabrication d'un tracker GPS/GSM)

    salut fred78000,

    Il te faut aussi les librairies
    serial, MOD, MDM, GPS

    je te recommande de te rapprocher des spécialistes python.

    http://www.developpez.net/forums/forumdisplay.php?f=96.

  3. #3
    invite68a65083

    Re : Programmation pyton sur "microcontroleur" GM862-GPS (fabrication d'un tracker GPS/GSM)

    Citation Envoyé par GlopGlopPasGlop Voir le message
    salut fred78000,

    Il te faut aussi les librairies
    serial, MOD, MDM, GPS

    je te recommande de te rapprocher des spécialistes python.

    http://www.developpez.net/forums/forumdisplay.php?f=96.
    Merci pour le forum, jvais y poster le même topic
    Le gps est intégré au module ( y a juste à rajouter l'antenne )
    Sinon, MOD, MDM, c'est du chinois pour moi

  4. #4
    invite0324077b

    Re : Programmation pyton sur "microcontroleur" GM862-GPS (fabrication d'un tracker GPS/GSM)

    il y a au debut de ton programme
    #Use AT command interface
    import MDM
    importMDM cela veut dire charger la biliotheque MDM pour que le python de base connaisse en plus les commande AT
    la ligne de commentaire le rappelle a celui qui veut comprendre :
    #Use AT command interface

    les lignes de commandes qui commance par MDM ne fonctionneraient pas si il n'y avait pas ce import MDM au debut
    MDM.send('AT+CMGF=1\r', 0)

  5. A voir en vidéo sur Futura
  6. #5
    invite68a65083

    Re : Programmation pyton sur "microcontroleur" GM862-GPS (fabrication d'un tracker GPS/GSM)

    Je remets le programme avec les tabulations:

    Code:
    ##### Config #####
    
    sms_password = 'mypassword'
    
    
    ##### Constants #####
    
    TRUE = 1
    FALSE = 0
    
    
    ##### Modules #####
    
    #Use serial
    import SER
    
    #Use build in module
    import MOD
    
    #Use AT command interface
    import MDM
    
    #Use GPS
    import GPS
    
    
    ###### General Functions ######
    
    #Debug message
    def debugmsg(msgtext):
        msgtext = msgtext.replace('\r', '\\r')
        msgtext = msgtext.replace('\n', '\\n')
        print msgtext
        SER.send(msgtext + '\r\n')
        #f = open('log.txt','ab')
        #f.write(msgtext + '\n')
        #f.close()
    
    #GPS status
    def gps_status(gpspos):
        debugmsg('Retrieving GPS status')
    
        gpspos_parts = gpspos.split(',')
    
        if ( (gpspos_parts[5] == '2') or (gpspos_parts[5] == '3') ): #2D or 3D fix
            debugmsg('GPS fix "' + gpspos_parts[5] + '" ie valid');
            status = TRUE
        else:
            debugmsg('GPS fix "' + gpspos_parts[5] + '" ie not valid');
            status = FALSE
    
        return status
    
    
    ###### SMS Process Functions ######
    
    #Process SMS messages
    def sms_proceses(gpspos):
        debugmsg('Process SMS')
    
        #List SMS
        smsmsgs = sms_list()
    
        totalsms = len(smsmsgs)
    
        #debugmsg('SMS total: %d' % totalsms)
    
        #Go throguh SMS messages
        for smsmsgindex in range(0, totalsms):
    
            debugmsg('Message: %d' % smsmsgindex)
    
            #Delete SMS (it is being processed now)
            status = sms_delete(smsmsgs[smsmsgindex]['id'])
    
            #If status deleted ok
            if (status == TRUE):
    
                #debugmsg('List SMS id: %d, from: %s, msg: %s' % (smsmsgs[smsmsgindex]['id'], smsmsgs[smsmsgindex]['from'], smsmsgs[smsmsgindex]['msg']))
    
                #Split SMS message into parts
                smsmsgparts = smsmsgs[smsmsgindex]['msg'].split(' ')
    
                #If at least 2 parts
                if (len(smsmsgparts) > 1):
    
                    #Check if password valid
                    if (smsmsgparts[0].lower() == sms_password):
    
                        debugmsg('Password valid')
    
                        #If position requested
                        if (smsmsgparts[1].lower() == 'pos') or (smsmsgparts[1].lower() == 'position'):
    
                            debugmsg('Action: Position requested')
    
                            #If GPS position fix valid
                            if (gps_status(gpspos) == TRUE):
                                gpsdataparts = gpspos.split(',')
    
                                senddata = 'Lat: ' + gpsdataparts[1] + ', Lon: ' + gpsdataparts[2] + ', Heading: ' + gpsdataparts[6] + ', Speed: ' + gpsdataparts[7] + ' km/hr'
    
                            else:
                                senddata = 'No GPS Fix'
    
                            #Send SMS
                            sms_send(smsmsgs[smsmsgindex]['from'], senddata)
    
                        else:
                            debugmsg('Action: Unknown')
    
                    else:
    
                        debugmsg('Password invalid')
    
            else:
    
                debugmsg('Unable to delete')
    
    
    
    ###### SMS Library Functions ######
    
    #Setup SMS
    def sms_setup():
    
        debugmsg('Setting up SMS')
    
        MDM.send('AT+CMGF=1\r', 0)
        res = MDM.receive(50)#5 sec
        MOD.sleep(1)#wait 0.1sec
    
        debugmsg('SMS setup: ' + res)
    
    #List SMS
    def sms_list():
    
        #Note: Command will not return anything if SIM is not ready
    
        debugmsg('List SMS')
    
        #MDM.send('AT+CMGL="REC UNREAD"\r', 0) #ALL REC UNREAD   STO SENT
        MDM.send('AT+CMGL="REC UNREAD"\r', 0)
    
        #smslist = ''
        #res = MDM.receive(50)#5 sec
        #smslist = smslist + res
    
        #while (res.find('\r\nOK\r\n') == -1):
        #    res = MDM.receive(10)
        #    smslist = smslist + res
    
        smslist = ''
        res = ''
        timeout = MOD.secCounter() + 60
        while ( (res.find('\r\nOK\r\n') == -1) and (MOD.secCounter() < timeout) ):
            debugmsg('Timeout now: %d timeout: %d' % (MOD.secCounter(), timeout))
            res = MDM.receive(50)
            smslist = smslist + res
            #debugmsg('get %s' % smslist)
    
        MOD.sleep(1)#wait 0.1sec
    
        smsparts = smslist.split('\r\n')
    
        smspartslen = len(smsparts)
    
        #debugmsg('SMS Parts %d' % smspartslen)
    
        smsmsgs = []
    
        if (smspartslen-2 > 0) and (smsparts[smspartslen-2] == 'OK'):
    
            #If there is at least 1 message
            if (smspartslen >= 6):
    
                #Go through all messages
                for partno in range(1, smspartslen):
    
                    #Find out if this is an cmgl line
                    cmglparts = smsparts[partno].split('CMGL: ')
    
                    #If at least 2 parts, leading cmgl and data
                    if (len(cmglparts) > 1) and (cmglparts[0] == '+') and (partno+1 <= smspartslen):
    
                        #debugmsg('Found CMGL %d: %s' % (partno, smsparts[partno]))
                        #debugmsg('Text %d: %s' % (partno+1, smsparts[partno+1]))
    
                        #Split msg info line into parts
                        msginfoparts = cmglparts[1].split(',')
    
                        #Check have all parts
                        #if (len(msginfoparts) > 5):
                        if (len(msginfoparts) > 4):
    
                            #int() may fail
                            try:
    
                                #Convert id to integer
                                msginfoparts[0] = int(msginfoparts[0])
    
                                #Remove quotes
                                msginfoparts[2] = msginfoparts[2].replace('"', '')
                                #msginfoparts[4] = msginfoparts[4].replace('"', '')
                                #msginfoparts[5] = msginfoparts[5].replace('"', '')
    
                                smsmsgs.append({'id': msginfoparts[0], 'from': msginfoparts[2], 'msg': smsparts[partno+1]})
    
                                debugmsg('SMS id: %d, from: %s, msg: %s' % (msginfoparts[0], msginfoparts[2], smsparts[partno+1]))
    
                            except Exception:
                                debugmsg('Error CMGL %d: %s' % (partno, smsparts[partno]))
    
            debugmsg('SMS total: %d' % len(smsmsgs))
    
        else:
    
            debugmsg('No SMS messages available')
    
        return smsmsgs
    
    #SMS Delete
    def sms_delete(delindex):
    
        debugmsg('SMS Delete: %d' % delindex)
    
        MDM.send('AT+CMGD=' + str(delindex) + '\r', 0)
        res = MDM.receive(50)#5 sec
        MOD.sleep(1)#wait 0.1sec
    
        if (res == '\r\nOK\r\n'):
            status = TRUE
        else:
            status = FALSE
    
        return status
    
    #SMS Send
    def sms_send(to, text):
    
        debugmsg('Send SMS to: %s, MSG: %s' % (to, text))
    
        MDM.send('AT+CMGS="' + to + '"\r', 0)
        res = MDM.receive(50)#5 sec
        MOD.sleep(1)#wait 0.1sec
    
        #Check for SMS prompt
        if (res == '\r\n> '):
    
            #Send SMS message text
            MDM.send(text, 0)
    
            #End SMS
            MDM.sendbyte(0x1A, 0)
            res2 = MDM.receive(180)#5 sec
            MOD.sleep(1)#wait 0.1sec
    
            if (res2.find('\r\nOK\r\n') != -1):
    
                debugmsg('SMS sent')
    
                status = TRUE
    
            else:
    
                debugmsg('SMS Send: ' + res2)
    
                debugmsg('Did not get SMS sent confirmation')
    
                status = FALSE
    
        else:
    
            debugmsg('SMS Send: ' + res)
    
            debugmsg('Did not receive SMS prompt')
    
            #Abort SMS (just in case)
            MDM.sendbyte(0x1B, 0)
            MOD.sleep(1)#wait 0.1sec
    
            status = FALSE
    
        return status
    
    
    
    ##################################################################################
    
    
    ###### Init ######
    
    SER.set_speed('115200','8N1')
    SER.send('\r\n--------------------\r\n\r\n')
    
    debugmsg('Running...');
    
    #Set verbose error reporting
    MDM.send('AT+CMEE=2\r', 0)
    MDM.receive(50)#5 sec
    MOD.sleep(1)#wait 0.1sec
    
    #May be required in North America / Canada to switch the unit to 900/1900MHz frequency (uncomment if in those areas)
    #MDM.send('AT#BND=1\r', 0)
    #MDM.receive(1)#0.1sec
    #MOD.sleep(1)#wait 0.1sec
    
    gpspos_lastvalid = ''
    
    #Setup SMS
    sms_setup()
    
    #Main loop
    while 1:
    
        debugmsg('Entering loop')
    
        #Retrieve current position
        gpspos = GPS.getActualPosition()
    
        debugmsg('Position: %s' % gpspos)
    
        #Retrieve GPS fix status
        gps_statusnow = gps_status(gpspos)
    
        #Save last valid position
        #If position fix valid, or none recorded already, use last retrieved
        if ( (gps_statusnow == TRUE) or (gpspos_lastvalid == '') ):
            gpspos_lastvalid = gpspos
    
        #Check for / process new SMS messages
        sms_proceses(gpspos_lastvalid)
    
        debugmsg('Powersave for 10 seconds')
    
        #Powersave for 10 seconds
        MOD.powerSaving(10)

  7. #6
    invite68a65083

    Re : Programmation pyton sur "microcontroleur" GM862-GPS (fabrication d'un tracker GPS/GSM)

    up !

Discussions similaires

  1. [Blanc] Déverrouillage du mode "DEMO ON" sur cuisinière "Scholtès CI 36GW"
    Par invitec6cf2f03 dans le forum Dépannage
    Réponses: 0
    Dernier message: 28/02/2007, 13h35
  2. programmation en "C" microcontrôleur MPS430
    Par invite5f7a5ab5 dans le forum Électronique
    Réponses: 1
    Dernier message: 04/05/2006, 18h05
Dans la rubrique Tech de Futura, découvrez nos comparatifs produits sur l'informatique et les technologies : imprimantes laser couleur, casques audio, chaises gamer...