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: WIZnetInterface WIZwiki-W7500-lecture mbed
Fork of WIZwiki-W7500-lecture2-udp by
main.cpp
- Committer:
- bangbh
- Date:
- 2016-02-01
- Revision:
- 2:ba228e5b659c
- Parent:
- 0:d7c890f9ee69
- Child:
- 3:f549134aa6c4
File content as of revision 2:ba228e5b659c:
#include "mbed.h"
#include "EthernetInterface.h"
int main() {
EthernetInterface eth;
uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x00, 0x01, 0x02};
eth.init(mac_addr, "192.168.0.180", "255.255.255.0", "192.168.0.1"); // USE Static IP
//eth.init(mac_addr); //Use DHCP
eth.connect();
printf("IP Address is %s\r\n", eth.getIPAddress());
UDPSocket udp_sock;
TCPSocketConnection tcp_sock;
tcp_sock.connect("192.168.0.244", 4545);
udp_sock.init();
udp_sock.bind(60001);
Endpoint udp_server;
udp_server.set_address("192.168.0.244",4023);
char http_cmd[] = "GET /data/2.5/weather?q=Seoul,kr HTTP/1.0\n\n";
tcp_sock.send_all(http_cmd, sizeof(http_cmd)-1);
udp_sock.sendTo(udp_server,http_cmd,sizeof(http_cmd)-1);
char buffer[400];
int ret;
while (true) {
ret = tcp_sock.receive(buffer, sizeof(buffer)-1);
if (ret <= 0) break;
buffer[ret] = '\0';
printf("Received %d chars from server: %s\n", ret, buffer);
}
tcp_sock.close();
eth.disconnect();
}
