views:

446

answers:

2

All of the examples in the TCPIP Demo App are built using a custom program that designs a webpage that triggers callbacks when the webpage is changed. Is it possible to get a value from a sensor every X seconds and send the data out over an HTTP POST?

A: 

I'm pretty sure that your webpage must request the data from the server. I've never seen it where the server could force a page update. You could try using meta tags to refresh the page or build a java applet to request a file containing dynamic variables for the sensor data you want to read. I had also considered writing my own protocol based on telnet that would push data out to an application that connected to it on a TCP/IP port, but decided that wouldn't be much better than using the HTTP protocol that was already supported to supply data to my applet. It would probably be a lot faster, but also a lot more work. It really depends on how frequently you want the data to update. If it's on the order of 5-10 seconds and you only have a single connection then using HTTP should work fine. If you have multiple connections and want data updated every second or so you might want to go the Telnet route. I haven't seen any demo applications that do this, but it would be nice of Microchip to provide a demo application for this since I had the same problem you are having.

mjh2007
+3  A: 

I do this right now. Reading the value from the sensor every x seconds should be pretty self-explanatory, but encoding the message with a "POST" is a little trickier.

I did something like the following generic packet:

        TCPPutROMString(MySocket, (ROM BYTE*)"POST ");
        TCPPutROMString(MySocket, RemoteURL);
        TCPPutROMString(MySocket, (ROM BYTE*)" HTTP/1.1\r\nHost: ");
        TCPPutROMString(MySocket, ServerName);
        TCPPutROMString(MySocket, (ROM BYTE*)"\r\nContent-Length:         
                        [put number of all following characters here]\r\n\r\n");
        TCPPutROMString(MySocket, (ROM BYTE*)"variable1=whatever");
        TCPPutROMString(MySocket, (ROM BYTE*)"&variable2=whatever");
        TCPPutROMString(MySocket, (ROM BYTE*)"&variable3=whatever");
Pontiac6000fan