It turned out to be quite simple to implement, I forgot to update this question.
I pretty much followed the instructions on this site, which is the Raw / TCP documentation.
Basically, the HTTP request is encoded in TCP packets, so to send data to my PHP server, I sent an HTTP request using TCP packets (lwIP does all the work).
The HTTP packet I want to send looks like this:
HEAD / process.php? Data1 = 12 & data2 = 5 HTTP / 1.0
Host: mywebsite.com
To "translate" this into text that the HTTP server understands, you must add the "\ r \ n" carriage return / new line to your code. So it looks like this:
char *string = "HEAD /process.php?data1=12&data2=5 HTTP/1.0\r\nHost: mywebsite.com\r\n\r\n ";
Please note that the end has two lots "\ r \ n"
You can use GET or HEAD, but due to the fact that I didn’t like the HTML site returned by my PHP server, I used HEAD (it returns 200 OK to success or other code if it fails).
lwIP raw / tcp works with callbacks. You basically configure all the callback functions, then click the data you want on the TCP buffer (in this case, the above TCP line), and then you specify lwIP to send the packet.
Function for configuring a TCP connection (this function is directly called by my application every time I want to send a TCP packet):
void tcp_setup(void) { uint32_t data = 0xdeadbeef; struct ip_addr ip; IP4_ADDR(&ip, 110,777,888,999);
Once the connection to my PHP server is established, the connectCallback function is called by lwIP:
err_t connectCallback(void *arg, struct tcp_pcb *tpcb, err_t err) { UARTprintf("Connection Established.\n"); UARTprintf("Now sending a packet\n"); tcp_send_packet(); return 0; }
This function calls the actual tcp_send_packet () function, which sends an HTTP request, as follows:
uint32_t tcp_send_packet(void) { char *string = "HEAD /process.php?data1=12&data2=5 HTTP/1.0\r\nHost: mywebsite.com\r\n\r\n "; uint32_t len = strlen(string); error = tcp_write(testpcb, string, strlen(string), TCP_WRITE_FLAG_COPY); if (error) { UARTprintf("ERROR: Code: %d (tcp_send_packet :: tcp_write)\n", error); return 1; } error = tcp_output(testpcb); if (error) { UARTprintf("ERROR: Code: %d (tcp_send_packet :: tcp_output)\n", error); return 1; } return 0; }
Once the TCP packet has been sent (all this is necessary if you want to “hope for the best” and don’t care if the data is actually sent), the PHP server returns the TCP packet (with 200 OK, etc. and HTML code if you used GET instead of HEAD). This code can be read and verified in the following code:
err_t tcpRecvCallback(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err) { UARTprintf("Data recieved.\n"); if (p == NULL) { UARTprintf("The remote host closed the connection.\n"); UARTprintf("Now I'm closing the connection.\n"); tcp_close_con(); return ERR_ABRT; } else { UARTprintf("Number of pbufs %d\n", pbuf_clen(p)); UARTprintf("Contents of pbuf %s\n", (char *)p->payload); } return 0; }
p-> The payload contains the actual information "200 OK", etc. Hope this helps someone.
I missed some errors in my code above to simplify the answer.