MCF52235 EVB. CodeWarrior. Niche_Lite. HTTP Web Client

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MCF52235 EVB. CodeWarrior. Niche_Lite. HTTP Web Client

2,341 Views
Marcia
Contributor I
Hi Everyone,
 
I'm hoping that some of you guys can help me by providing some general guidance. I am a newbie on this forum, but pretty experienced with Coldfire and CodeWarrior.
 
OK, I have 32 remote products, which I want to monitor over ethernet. They are each on my client's enterprise networks, and I want a keep-alive from each box every 5 minutes, and to report a status byte when anything changes. I had planned to use the AJAX technique described in the Web_Server_with_labs material, but of course got caught out by the enterprise firewalls. I now need to change my thinking from the board running a web server (HTTP server) to running a web client. Every 5 minutes, the CF board can send a HTTP packet over to my local server:
 
 
I have a CGI script running on my server, and the http request I plan to make every 5 minutes is:
GET
/cgi-bin/marcia/marcia.cgi?Board%3d55+Status%3dAA
HTTP/1.0
 
So now I have a web client which can make a HTTP request to my server. But I need your advice on the InterNiche web client. As it stands, the freescale_http demo is a web server.
 
I know I have to do this:
M_SOCK socket = m_socket();
int m_connect(M_SOCK socket, struct sockaddr_in * sin, M_CALLBACK(my cb function));
bytes_sent = m_send (socket, data, length);
err=m_close(socket);
 
I have found it challenging to turn this theory into a workable CW project, and I'm not sure how I should be handling the response from my server - it's just a HTTP/1.1 200 OK frame. Also, when I run the Freescale http server, and break to look at the socket it is using, there is lots of data in the socket. Does the m_socket() function populate this for me? How do I set blocking and unblocking, etc. I dont think I really understand the sockaddr structure in the m_connect, also.
 
Does anyone have any advice that you could share with me??
 
Marcia
 
 
Labels (1)
0 Kudos
3 Replies

322 Views
mccPaul
Contributor I
Hi Marcia,
 
I can't help with CW as I use the GNU toolchain, but I may be able to offer some other assistance.
 
You will need to make a new task in the NicheLite stack for your HTTP mini client. I put a minimal task here:
 
 
that you can adapt.
 
For your http client to work, you will need to leave the socket open long enough for the server to reply. If you connect, send and close, the server may well abandon the CGI task before it runs, simply because the client has dropped the TCP connection.
 
So, you need to open the socket, send the GET and then wait for the response.
 
The response should be the 200 OK, followed by the headers and body created by the CGI application. Depending on the web server, it may generate headers, etc. itself. It will be best if your client can parse the response so that it knows when it is complete and only then close the connection.
 
I haven't used the Nichelite sockets so I can't give you an example for that - you may be able to get a pointer from the Nichelite tftp code.
 
The NicheLite code does suffer from a few code (minor bugs) and documentation (lack of) issues - search the forum - so you are a bit on your own. Are you stuck with this stack? If you're just starting there are alternatives, http://www.utasker.com/ is one that is often on this forum (I am not affiliated with them and have not used it). Although there is a small licence fee for commercial use, the support may well be worth it.
 
Cheers,
 
Paul.
 
0 Kudos

322 Views
Marcia
Contributor I
Thanks Paul,
 
I was already using your task example. In your description in the code you mentioned tk_task.h but I think this is a typo - you meant tk_ntask.h, I believe.
 
I had overlooked the requirement for a delay before closing the socket. Will create a timer task to close it after a 1 minute delay, if its still pending. At present I'm able to open the socket with the m_connect; will try sending some data and parsing the result later today.
 
Marcia
0 Kudos

322 Views
WOLF
Contributor I
Did you ever get this to work.  I'm tring a similar project. but having difficulties.   My system needs to send a HTTP Post every 5 min..  
 
thanks,
0 Kudos