SparkFun Forums 

Where electronics enthusiasts find answers.

Tips and questions relating to the GPS modules from SFE
By Jonek
#53447
Hi guys & gals,

I have a working GM862 and I am using the GPRS. I am trying to connect to a web server but I cant seem to get a response when running the code on the device. Using RSTerm I can get a reply so I think I am formatting my GET request incorrectly.

I am doing this:
MDM.send('GET /gps/index.php?s=50 HTTP/1.0\r\nConnection: close\r\n\r\n',0)
That should get the index page in the gps folder on the web server. The s=50 gets added to the database (should be the speed from the device but I hard coded 50 just to test). Now nothing gets into the DB so I know there is a problem. I tried RSTerm and got the entry in the database so I think it is just the way I am sending the newlines.

So should I be sending them this way, just have them in the wrong place, or do I need to split it up and use something like:
MDM.send('GET /gps/index.php?s=50 HTTP/1.0')
MDM.sendbyte(0x0d,0)
MDM.sendbyte(0x0a,0)
MDM.send('Connection: close')
MDM.sendbyte(0x0d,0)
MDM.sendbyte(0x0a,0)
MDM.sendbyte(0x0d,0)
MDM.sendbyte(0x0a,0)
Also if sending the second way, do I need to put a \r at the end (eg GTTP/1.0\r) or do I just leave it without (eg HTTP/1.0)

Thanks for any help :)
Jonek
By fireball003
#53520
Where is your connection to the web server?
Code: Select all
  MDM.send('GET /gps/index.php?s=50 HTTP/1.0\r\nHost: www.myweb.com\r\nConnection: close\r\n\r\n',0)
Or
Code: Select all
 MDM.send('GET /gps/index.php?s=50 HTTP/1.0')
 MDM.sendbyte(0x0d,0)
 MDM.sendbyte(0x0a,0)
 MDM.send('Host: www.myweb.com')
 MDM.sendbyte(0x0d,0)
 MDM.sendbyte(0x0a,0)  
 MDM.send('Connection: close')
 MDM.sendbyte(0x0d,0)
 MDM.sendbyte(0x0a,0) 
 MDM.sendbyte(0x0d,0)
 MDM.sendbyte(0x0a,0)
Here change the "myweb.com" by your web host name.
And always better to give some time instead of 0 in MDM.send()

I hope this will help.
By Jonek
#53531
Thank you for your reply.

I didnt include the AT+SKTD in my quote because I know that part works - if I type it manually in Hpyerterminal then I see the html of the page but if I do the exact same thing in code I get nothing. Thats why I thought it must be an incorrect formatting of the GET request - the only difference between typing it out in hyperterminal and writing it in code is how the now lines are sent - Hyperterm is ctrl-J and ctrl-M whereas python is either \r\n or sendbytes.

The host part of the request is an addition to the http protocol from version 1.1 onwards and doesnt exist in http/1.0 so it is not required to send this. As I am trying to send as little data as possible it is not included and using RSTerm to send the request, also without the host part of the header, returns the html of the web page with no problems.

I have tried it with the newlines as \r\n and that doesnt work, ive tried it using sendbytes and that doesnt work, ive tried using \r at the end of send and also sendbytes for the actual newlines and that doesnt work, I just dont know what the correct way of sending the GET request to the device is, with the new lines. The actual GET request itself should work as I have tested it with RSTerm and Hyperterm.

In total, what I am doing is this:
Code: Select all
#includes
import MOD

import MDM

import GPS

#globals
run = 0

#functions
def init():
	#if(run==0):
	MDM.send('AT\r',0)
	#	r = MDM.receive(10)
	#	if r == '\r\nOK\r\n': return 1
	#	else: return 0

	#if(run==1):
 	#MDM.send('AT+CPIN?\r',0)
	#r = MDM.receive(10)
		#if r = ready
		#return 1
		#else
		#send at+cpin=xxxx
		#receive OK?
		#return 1
		#else
		#return 0

	#if(run==2):
	MDM.send('AT+CGATT=1\r',0)
	r = MDM.receive(10)
	#	if(r == '\r\n+CGATT: 1\r\n'): return 1
	#	else: return 0

	#if(run==3):
		#initialise GPS
		#pass
	#if(run==4):
	MDM.send('AT+CGDCONT=1,"IP","pp.vodafone.co.uk"\r',0)
	r = MDM.receive(10)
	#	if r == '\r\nOK\r\n': return 1
	#	else: return 0

	#if(run==5):
	MDM.send('AT#USERID=web\r',0)
	r = MDM.receive(10)
	#	if(r == '\r\nOK\r\n'): return 1
	#	else: return 0

	#if(run==6):
	MDM.send('AT#PASSW=web\r',0)
	r = MDM.receive(10)
	#	if(r == '\r\nOK\r\n'): return 1
	#	else: return 0

	#if(run==7):
	MDM.send('AT#GPRS=1\r',0)
	r = MDM.receive(10)
	#	if(r == '\r\nERROR\r\n'):
	#		run = 4
	#		return 0
	#	else: return 1
	return 1

def sync():
	MDM.send('AT#SKTD=0,80,"mywebserv.com"\r',0)
	#r = MDM.receive(20)
	#while(r.find('CONNECT')==-1):
	MOD.sleep(120)
	#	r = MDM.receive(20)
	MDM.send('GET /gps/index.php?s=50 HTTP/1.0\r',0)
	MDM.sendbytes(0x0D,0)
	MDM.sendbytes(0x0A,0)
	MDM.send('Connection: close\r',0)
	MDM.sendbytes(0x0D,0)
	MDM.sendbytes(0x0A,0)
	MDM.sendbytes(0x0D,0)
	MDM.sendbytes(0x0A,0)

	#r = MDM.receive(20)
	#while(r.find('\r\nContent-Length\r\n')==-1):
	#	MOD.sleep(30)
	#	r = MDM.receive(20)


#main code
#while run <= 7:
#	if(init()==1):
#		run=run+1
init()
run = 1
while run:
	sync()
	#set timer
	MOD.sleep(30000);
	run = 0
As you can see most of it is commented out as I was not sure my error checking was working correctly. If I get the device to send an SMS to my phone before the AT#SKTD then I receive it so I know it is executing the code to get the web page, but it just doesnt work - again making me think it is the newlines in the GET request being wrong.