Webserver only w/o any other functions, single thread. Running on STM32F013+W5500
Dependencies: NTPClient W5500Interface Watchdog device_configuration eeprom_flash mbed-rpc-nucleo mbed-rtos mbed
Fork of F103-Serial-to-Ethernet by
Revision 14:18eda020a589, committed 2014-09-28
- Comitter:
- olympux
- Date:
- Sun Sep 28 21:54:34 2014 +0000
- Parent:
- 13:bcf840da68fd
- Child:
- 15:edeb0aed160d
- Commit message:
- TCP client works with mbed.org, but not with TCP server on Hercules
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sun Sep 28 17:43:43 2014 +0000 +++ b/main.cpp Sun Sep 28 21:54:34 2014 +0000 @@ -94,10 +94,6 @@ * Variables for network configuration, server */ uint8_t u8mac[6], u8ip_addr[4];// keep mac and ip address in 8-bits -char * IP_Addr; // pointers to str_ip_xxx[16] -char * IP_Subnet; -char * IP_Gateway; - uint16_t u16mac_addr[3], u16ip_addr[4], u16ip_subnet[4], u16ip_gateway[4]; // 16-bits, directly loaded from eeprom char str_ip_addr[16], str_ip_subnet[16], str_ip_gateway[16]; // for printf, converted from 16-bits u16ip_xxx uint16_t first_run = 0; // first run flag @@ -109,10 +105,9 @@ // this device will transmit status every transmit_time_period uint16_t auto_transmit_flag = 0, transmit_time_period = 1000; // auto transmit status, time period = 1s uint16_t u16server_ip_addr[4]; // directly loaded from eeprom +uint8_t u8server_ip_addr[4]; // server ip address in 8-bits +char str_server_ip_addr[16];// for printf, converted from 16-bits u16server_ip_addr uint16_t u16tcp_server_port; // directly loaded from eeprom -uint8_t u8server_ip_addr[4]; // server ip address in 8-bits -char * server_ip_addr; // pointer to str_server_ip_addr -char str_server_ip_addr[16];// for printf, converted from 16-bits u16server_ip_addr char buffer[256]; // socket buffer @@ -197,7 +192,7 @@ */ int ethernet_init(void) { printf("Start initialising ethernet\n"); - int ret = eth.init(u8mac, IP_Addr, IP_Subnet, IP_Gateway); // static + int ret = eth.init(u8mac, str_ip_addr, str_ip_subnet, str_ip_gateway); // static if (!ret) { printf("Initialized, MAC: %s\n", eth.getMACAddress()); @@ -242,10 +237,6 @@ * FLASH */ load_eeprom_network(); - IP_Addr = str_ip_addr; - IP_Subnet = str_ip_subnet; - IP_Gateway = str_ip_gateway; - /* * Ethernet @@ -269,6 +260,30 @@ printf("TCP server started...\r\n"); tcp_server.set_blocking(false, TCP_SERVER_WAIT_CLIENT_TIMEOUT); #endif + + +#ifdef TCP_CLIENT + TCPSocketConnection tcp_sock; + if (!tcp_sock.is_connected()) { + ret = tcp_sock.connect("mbed.org", 80); + if (ret > -1) { + printf("Successfully connected to TCP server\r\n"); + char http_cmd[] = "GET /media/uploads/mbed_official/hello.txt HTTP/1.0\n\n"; + tcp_sock.send_all(http_cmd, sizeof(http_cmd)-1); + + while (true) { + n = tcp_sock.receive(buffer, sizeof(buffer)-1); + if (n <= 0) + break; + buffer[n] = '\0'; + printf("Received %d chars from server:\n%s\n", n, buffer); + } + tcp_sock.close(); + } + else printf("Connecting to TCP server failed\r\n"); + } +#endif + #ifdef UDP_SERVER UDPSocket udp_server; @@ -400,7 +415,7 @@ case 6: // discovery command if (strstr(buffer, "NNIODS") != NULL) { - udp_server.sendTo(ep_udp_client, str_ip_addr, strlen(str_ip_addr)); + udp_server.sendTo(ep_udp_client, eth.getIPAddress(), strlen(eth.getIPAddress())); } // NNIODS // ask for TCP server port else if (strstr(buffer, "NNIOTP") != NULL) {