Hi Ryan,
I found the example at:-
http://www.bernardotti.it/portal/showthread.php?t=17537
to be very helpfull.
I modified it (below) to detect a phone in "RING". My GM862 then does a "hang up" (hence no phone cost). The GM862 then reads the GPS and sends an SMS to a fixed phone number (sub. in yours at the correct position in the code).
I use SER.send commands to debug and watch what is going on in the roundsolutions "rsterm" hyperterminal.
I compile the script in rsterm to get the .pyo which I then upload, enable and run. It works great.
Gotta give credit to Flavio Bernardotti (what a name..sounds good enough to eat!); without his example I would have got nowhere.
######################### Cut and Paste from here #################################
#phone_loc2 - phone locater version 2
#Phone in and get an SMS of GPS location sent to a fixed phone number
#Adapted by John from work by Flavio Bernardotti
#
http://www.bernardotti.it/portal/showthread.php?t=17537
#Improved structure from my phone_loc1 version using simpler main and larger functions
#Tested with GPS fix, yet to test for GPS no fix - 28/02/2010
##### Put Your Number Here ######
SMSTO = 'XXXXXXXXXXXX' # recipient number for the SMS
##########################
##### Import Modules ############
import SER
import MOD
import MDM
import GPS
###### General Functions ######
#Get the GPS position, check for a fix and format the message
def get_gps():
gpspos = GPS.getActualPosition() #Read GPS position
gpspos_parts = gpspos.split(',') #Break into parts on the commas
if ((gpspos_parts[5] == '2') or (gpspos_parts[5] == '3')): #2D or 3D fix
SER.send('GPS fix\n\r') #For Hyperterminal
SER.send('Position is: lat and lon \r\n') #For Hyperterminal
#extract lat and lon
lat = gpspos_parts[1] #Lat is field[1]
lon = gpspos_parts[2] #Lon is field[2]
#Format the text lines
line1 = lat[0:2] + ' ' + lat[2:10]
line2 = lon[0:3] + ' ' + lon[3:11]
#Form the sms message body
text = line1 + '\n\r' + line2 +'\n\r'
#Print it on the hyperterminal
SER.send(text)
return text
else:
text = 'GPS No Fix \r\n'
SER.send(text + '\r\n') #For Hyperterminal
return text
#Setup Module - Text Mode, verbose error report
def sms_setup():
MDM.send('AT+CMEE=2\r', 0) #Set verbose error reporting for GSM module
MDM.receive(50) #5 sec max for response
MOD.sleep(1) #wait 0.1sec
SER.send('Set text mode\r\n') #For Hyperterminal
a = MDM.send('AT+CMGF=1\r', 2) #Set text mode
res = MDM.receive(5) #Get the response
SER.send(res + '\r\n') #For Hyperterminal
MOD.sleep(1) #Some delay
#SMS Send - Fixed phone number, message is passed in variable 'text'
def sms_send(text):
SER.send('Sending SMS\r\n') #For Hyperterminal
a = MDM.send('AT+CMGS="' + SMSTO + '"\r', 2) #Send the number
res = MDM.receive(10) #Get the response
MOD.sleep(1) #Some delay
if(res.find('>') != -1): #Test the response
a = MDM.send(text, 20) #Good response - send the text
a = MDM.sendbyte(0x1A, 20) #Send the terminator
SER.send('SMS Sent\r\n') #For Hyperterminal
MOD.sleep(1) #Some delay
else:
SER.send('Did not get > \r\n') #Handle the error case
#Abort SMS (just in case)
MDM.sendbyte(0x1B, 0)
MOD.sleep(1)#wait 0.1sec
##################
###### Main ######
##################
#Setup USART
SER.set_speed('115200','8N1') #Baud, 8-bit data, 1 stop bit
#Setup Module for SMS etc
sms_setup()
#Everloop
while 1:
#Now check for RING
SER.send('Checking RING \n\r') #For Hyperterminal
res = MDM.receive(20) #Get the string to check for ring in
a = res.find('RING') #Test for Ring
if(a != -1): #Found a RING
SER.send('Found Ring \r\n') #For Hyperterminal
MDM.send('ATH\r', 10) #Hang up, no charge
res = MDM.receive(10)
#Read GPS
text = get_gps()
#Send the sms
sms_send(text) #Send the message
else:
SER.send('No RING Detected \r\n') #Did not find RING
################## End Cut andPaste ####################
Regards John
Melbourne Australia