Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: HC_SR04_Ultrasonic_Library PinDetect
client.cpp
00001 #include "client.h" 00002 /* ethernet */ 00003 #include <EthernetInterface.h> 00004 00005 // Network interface 00006 EthernetInterface net; 00007 00008 int init_nw() { 00009 printf("%s\n", __FUNCTION__); 00010 net.connect(); 00011 // Show the network address 00012 const char *ip = net.get_ip_address(); 00013 printf("IP address is: %s\n", ip ? ip : "No IP"); 00014 return 0; 00015 } 00016 00017 int desinit_nw() { 00018 printf("%s\n", __FUNCTION__); 00019 // Bring down the ethernet interface 00020 net.disconnect(); 00021 printf("Done\n"); 00022 return 0; 00023 } 00024 00025 // Socket demo 00026 int send_data(/* TODO */) { 00027 00028 // Open a socket on the network interface, and create a TCP connection to mbed.org 00029 TCPSocket socket; 00030 socket.open(&net); 00031 socket.connect("developer.mbed.org", 80); 00032 00033 // Send a simple http request 00034 char sbuffer[] = "GET / HTTP/1.1\r\nHost: developer.mbed.org\r\n\r\n"; 00035 int scount = socket.send(sbuffer, sizeof sbuffer); 00036 printf("sent %d [%.*s]\n", scount, strstr(sbuffer, "\r\n")-sbuffer, sbuffer); 00037 00038 // Recieve a simple http response and print out the response line 00039 char rbuffer[64]; 00040 int rcount = socket.recv(rbuffer, sizeof rbuffer); 00041 printf("recv %d [%.*s]\n", rcount, strstr(rbuffer, "\r\n")-rbuffer, rbuffer); 00042 00043 // Close the socket to return its memory and bring down the network interface 00044 socket.close(); 00045 00046 return 0; 00047 00048 } 00049 00050 00051 int send_data2(const int distance) { 00052 00053 // Open a socket on the network interface, and create a TCP connection to mbed.org 00054 TCPSocket socket; 00055 socket.open(&net); 00056 socket.connect("192.168.1.67", 3000); 00057 00058 // Send a simple http request 00059 char sbuffer[256]; 00060 snprintf(sbuffer, 256, "POST /?distance=%d HTTP/1.1\r\n\r\n\r\n", distance); 00061 int scount = socket.send(sbuffer, sizeof sbuffer); 00062 printf("sent %d [%.*s]\n", scount, strstr(sbuffer, "\r\n")-sbuffer, sbuffer); 00063 00064 // Recieve a simple http response and print out the response line 00065 char rbuffer[64]; 00066 int rcount = socket.recv(rbuffer, sizeof rbuffer); 00067 printf("recv %d [%.*s]\n", rcount, strstr(rbuffer, "\r\n")-rbuffer, rbuffer); 00068 00069 // Close the socket to return its memory and bring down the network interface 00070 socket.close(); 00071 00072 return 0; 00073 00074 }
Generated on Mon Jul 25 2022 02:11:50 by
1.7.2