STM32 Nucleo F207Z ultrasonic radar. TODO: send the data over the net

Dependencies:   HC_SR04_Ultrasonic_Library PinDetect

Committer:
vhx
Date:
Fri Jun 29 08:52:41 2018 +0000
Revision:
1:b4179d7a5f2c
Parent:
0:23a36e52a5fa
Envoi d'une donn?e

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vhx 0:23a36e52a5fa 1 #include "client.h"
vhx 0:23a36e52a5fa 2 /* ethernet */
vhx 0:23a36e52a5fa 3 #include <EthernetInterface.h>
vhx 0:23a36e52a5fa 4
vhx 0:23a36e52a5fa 5 // Network interface
vhx 0:23a36e52a5fa 6 EthernetInterface net;
vhx 0:23a36e52a5fa 7
vhx 0:23a36e52a5fa 8 int init_nw() {
vhx 0:23a36e52a5fa 9 printf("%s\n", __FUNCTION__);
vhx 0:23a36e52a5fa 10 net.connect();
vhx 0:23a36e52a5fa 11 // Show the network address
vhx 0:23a36e52a5fa 12 const char *ip = net.get_ip_address();
vhx 0:23a36e52a5fa 13 printf("IP address is: %s\n", ip ? ip : "No IP");
vhx 0:23a36e52a5fa 14 return 0;
vhx 0:23a36e52a5fa 15 }
vhx 0:23a36e52a5fa 16
vhx 0:23a36e52a5fa 17 int desinit_nw() {
vhx 0:23a36e52a5fa 18 printf("%s\n", __FUNCTION__);
vhx 0:23a36e52a5fa 19 // Bring down the ethernet interface
vhx 0:23a36e52a5fa 20 net.disconnect();
vhx 0:23a36e52a5fa 21 printf("Done\n");
vhx 0:23a36e52a5fa 22 return 0;
vhx 0:23a36e52a5fa 23 }
vhx 0:23a36e52a5fa 24
vhx 0:23a36e52a5fa 25 // Socket demo
vhx 0:23a36e52a5fa 26 int send_data(/* TODO */) {
vhx 0:23a36e52a5fa 27
vhx 0:23a36e52a5fa 28 // Open a socket on the network interface, and create a TCP connection to mbed.org
vhx 0:23a36e52a5fa 29 TCPSocket socket;
vhx 0:23a36e52a5fa 30 socket.open(&net);
vhx 0:23a36e52a5fa 31 socket.connect("developer.mbed.org", 80);
vhx 0:23a36e52a5fa 32
vhx 0:23a36e52a5fa 33 // Send a simple http request
vhx 0:23a36e52a5fa 34 char sbuffer[] = "GET / HTTP/1.1\r\nHost: developer.mbed.org\r\n\r\n";
vhx 0:23a36e52a5fa 35 int scount = socket.send(sbuffer, sizeof sbuffer);
vhx 0:23a36e52a5fa 36 printf("sent %d [%.*s]\n", scount, strstr(sbuffer, "\r\n")-sbuffer, sbuffer);
vhx 0:23a36e52a5fa 37
vhx 0:23a36e52a5fa 38 // Recieve a simple http response and print out the response line
vhx 0:23a36e52a5fa 39 char rbuffer[64];
vhx 0:23a36e52a5fa 40 int rcount = socket.recv(rbuffer, sizeof rbuffer);
vhx 0:23a36e52a5fa 41 printf("recv %d [%.*s]\n", rcount, strstr(rbuffer, "\r\n")-rbuffer, rbuffer);
vhx 0:23a36e52a5fa 42
vhx 0:23a36e52a5fa 43 // Close the socket to return its memory and bring down the network interface
vhx 0:23a36e52a5fa 44 socket.close();
vhx 1:b4179d7a5f2c 45
vhx 1:b4179d7a5f2c 46 return 0;
vhx 1:b4179d7a5f2c 47
vhx 1:b4179d7a5f2c 48 }
vhx 1:b4179d7a5f2c 49
vhx 1:b4179d7a5f2c 50
vhx 1:b4179d7a5f2c 51 int send_data2(const int distance) {
vhx 1:b4179d7a5f2c 52
vhx 1:b4179d7a5f2c 53 // Open a socket on the network interface, and create a TCP connection to mbed.org
vhx 1:b4179d7a5f2c 54 TCPSocket socket;
vhx 1:b4179d7a5f2c 55 socket.open(&net);
vhx 1:b4179d7a5f2c 56 socket.connect("192.168.1.67", 3000);
vhx 1:b4179d7a5f2c 57
vhx 1:b4179d7a5f2c 58 // Send a simple http request
vhx 1:b4179d7a5f2c 59 char sbuffer[256];
vhx 1:b4179d7a5f2c 60 snprintf(sbuffer, 256, "POST /?distance=%d HTTP/1.1\r\n\r\n\r\n", distance);
vhx 1:b4179d7a5f2c 61 int scount = socket.send(sbuffer, sizeof sbuffer);
vhx 1:b4179d7a5f2c 62 printf("sent %d [%.*s]\n", scount, strstr(sbuffer, "\r\n")-sbuffer, sbuffer);
vhx 1:b4179d7a5f2c 63
vhx 1:b4179d7a5f2c 64 // Recieve a simple http response and print out the response line
vhx 1:b4179d7a5f2c 65 char rbuffer[64];
vhx 1:b4179d7a5f2c 66 int rcount = socket.recv(rbuffer, sizeof rbuffer);
vhx 1:b4179d7a5f2c 67 printf("recv %d [%.*s]\n", rcount, strstr(rbuffer, "\r\n")-rbuffer, rbuffer);
vhx 1:b4179d7a5f2c 68
vhx 1:b4179d7a5f2c 69 // Close the socket to return its memory and bring down the network interface
vhx 1:b4179d7a5f2c 70 socket.close();
vhx 1:b4179d7a5f2c 71
vhx 1:b4179d7a5f2c 72 return 0;
vhx 0:23a36e52a5fa 73
vhx 0:23a36e52a5fa 74 }