English 中文(简体)
Sending data over tcpip using Microchip s PIC18F
原标题:

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?

最佳回答

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
Host: ");
        TCPPutROMString(MySocket, ServerName);
        TCPPutROMString(MySocket, (ROM BYTE*)"
Content-Length:         
                        [put number of all following characters here]

");
        TCPPutROMString(MySocket, (ROM BYTE*)"variable1=whatever");
        TCPPutROMString(MySocket, (ROM BYTE*)"&variable2=whatever");
        TCPPutROMString(MySocket, (ROM BYTE*)"&variable3=whatever");
问题回答

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.





相关问题
Checking a local TCP port is not open in Java

Is there a simple way to make sure that a local port is not already open. Some TCP socket servers (eg Grizzly) don t seem to do this check by default. When this check is missing, the server appears ...

Client/Server: Integer always received as 1 (C-programming)

I m building a client and a server program that exchanges data over TCP and I m having trouble sending an ACK-confirmation from the server back to the client when an operation is successfull. I ve ...

Long Lived Persistent TCP Connection on the Android

I ve read some articles on the web and some questions on StackOverFlow, but no one seems to have a definite answer over a) If google uses Long Lived TCP connections for Gmail, Mail etc, and b) If ...

Maintaining many socket connections with a single thread

Many tutorials on socket communication I see seem to use 1 thread per socket. But on a server used for online gaming, you might have 10k concurrent users - 10k threads isn t probably a wonderful idea. ...

SSL_accept with blocking socket

I made a server with SSL and blocking sockets. When I connect with telnet (so it does not do the handshake), the SSL_accept blocks indefinitely and blocks every new handshake/accept (and by definition ...

How to list all devices in my wifi range in iphone

I am using the reachability code from apple to find if my iphone is connected to the wifi. Next i would like to list all the devices that are in my wifi range. How should i do this. The other devices ...

Sending struct over TCP (C-programming)

I have a client and server program where I want to send an entire struct from the client and then output the struct member "ID" on the server. I have done all the connecting etc and already managed ...

Idle tcp file descriptor after failed connect on HPUX

I have a client tcp socket (in c++) that has a loop where it retries to open a socket and connect to a server at a certain interval until it succeeds. A bug in the program caused close not to be ...

热门标签