STM32 Nucleo F207Z ultrasonic radar. TODO: send the data over the net
Dependencies: HC_SR04_Ultrasonic_Library PinDetect
Diff: client.cpp
- Revision:
- 0:23a36e52a5fa
- Child:
- 1:b4179d7a5f2c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/client.cpp Thu Jun 28 15:33:29 2018 +0000 @@ -0,0 +1,46 @@ +#include "client.h" +/* ethernet */ +#include <EthernetInterface.h> + +// Network interface +EthernetInterface net; + +int init_nw() { + printf("%s\n", __FUNCTION__); + net.connect(); + // Show the network address + const char *ip = net.get_ip_address(); + printf("IP address is: %s\n", ip ? ip : "No IP"); + return 0; +} + +int desinit_nw() { + printf("%s\n", __FUNCTION__); + // Bring down the ethernet interface + net.disconnect(); + printf("Done\n"); + return 0; +} + +// Socket demo +int send_data(/* TODO */) { + + // Open a socket on the network interface, and create a TCP connection to mbed.org + TCPSocket socket; + socket.open(&net); + socket.connect("developer.mbed.org", 80); + + // Send a simple http request + char sbuffer[] = "GET / HTTP/1.1\r\nHost: developer.mbed.org\r\n\r\n"; + int scount = socket.send(sbuffer, sizeof sbuffer); + printf("sent %d [%.*s]\n", scount, strstr(sbuffer, "\r\n")-sbuffer, sbuffer); + + // Recieve a simple http response and print out the response line + char rbuffer[64]; + int rcount = socket.recv(rbuffer, sizeof rbuffer); + printf("recv %d [%.*s]\n", rcount, strstr(rbuffer, "\r\n")-rbuffer, rbuffer); + + // Close the socket to return its memory and bring down the network interface + socket.close(); + +} \ No newline at end of file