Page 1 of 1

Reading a webpage with Netburner?

Posted: Sat Jan 18, 2014 1:03 pm
by barttech
I suspect this is basic, but how can I read a webpage with my MOD5234?
I see (and have made) all sorts of ways to serve webpages. I want to have my device get some parameters from the DSL modem at 192.168.1.1. Do I have to do an FTP?
Sam

Re: Reading a webpage with Netburner?

Posted: Sun Jan 19, 2014 12:40 pm
by rnixon
A web browser request to a server is basically a TCP connection and GET or POST request. You need two consecutive line feeds after the GET. There is an example of this in the NetBurner weather demo: http://demo.netburner.com:81/INDEX.HTM.

Re: Reading a webpage with Netburner?

Posted: Mon Jan 20, 2014 1:36 pm
by pbreed
I'm actually in the middle of generating some examples of this....
Here is a snipit of known workign code that does this...

Before you get to this code you need to have turned the name into an IP address
and put it in the ip variable

and put the text of the request into tRequest...

In this example the code that fills in the tRequest is here:

if(GetHostByName(pAddress,&ip,0,SLEEP_INTERVAL.tval())==DNS_OK)
{
iprintf("IP Address ="); ShowIP(ip);
siprintf(tRequest,"GET /%s?%s HTTP/1.1\r\nHost:%s\r\n\r\n",pUrl,DEVICENAME.string(),pAddress);
iprintf("Request =[%s]\r\n",tRequest);
}
else
{
LedState=LED_NO_DNS_RESOLVE;
iprintf("Failed to get DNS address\r\n");
}

//Now connect and get the result....

int fd=connect(ip,0,OUTBOUND_PORT.wval(),SLEEP_INTERVAL.tval());
if(fd<0)
{
LedState=LED_NO_SERVER_CONNECT;
ip=0;
}
else
{

LastConTime=TimeTick;
writestring(fd,tRequest);
int nread=0;
while(1)
{
int rv=ReadWithTimeout(fd,tResponse+nread,RESPONSE_SIZE-nread,REQUEST_TIMEOUT.tval());
if(bLog) iprintf("Read at %ld\r\n",TimeTick-LastStartTime);
if(rv>0)
{nread+=rv;
if(nread>=(RESPONSE_SIZE-1)) break;
tResponse[nread]=0;
}
else
break;
};

LastReadDoneTime=TimeTick;

if(nread)
{
nRequests++;
char * FindResult= strstr(tResponse,"\r\n\r\n");
if(FindResult)
{//Process the returned data
}
}

close(fd);

Re: Reading a webpage with Netburner?

Posted: Tue Jan 21, 2014 1:53 pm
by barttech
Thanks, both are useful. Getting weather information was one of my objectives, I had forgotten about the demos.
Sam