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 17:88ef7a078095, committed 2014-10-04
- Comitter:
- olympux
- Date:
- Sat Oct 04 20:25:45 2014 +0000
- Parent:
- 16:84a5bf7285d0
- Child:
- 18:ca499a2e7da6
- Commit message:
- Modify DISCOVERY command. Added IP, NetMask, GW query commands
Changed in this revision
--- a/main.cpp Thu Oct 02 19:41:38 2014 +0000 +++ b/main.cpp Sat Oct 04 20:25:45 2014 +0000 @@ -151,10 +151,22 @@ * Protocol */ // Commands -#define DEVICE_ID "NNIO" -#define DISCOVERY_COMMAND "NNIODS" -#define TCP_SERVER_PORT_COMAMND "NNIOTP" -#define UDP_SERVER_PORT_COMAMND "NNIOUP" +#define DEVICE_ID "NNIO" + +#define RECEIVING_PROTOCOL_LENGTH 58 +#define SENDING_PROTOCOL_LENGTH 39 +#define QUERY_CMD_LENGTH 6 +#define SET_NETWORK_CONFIG_CMD_LENGTH 19 +#define UPDATE_TCP_SERVER_INFO_CMD_LENGTH 12 + +#define QUERY_DISCOVERY_CMD "NNIODS" +#define QUERY_IP_CMD "NNIOIP" +#define QUERY_SUBNET_CMD "NNIOSN" +#define QUERY_GATEWAY_CMD "NNIOGW" +#define QUERY_MAC_CMD "NNIOMC" +#define QUERY_UDP_PORT_CMD "NNIOUP" +#define QUERY_TCP_PORT_CMD "NNIOTP" +#define QUERY_UPDATE_TIME_CMD "NNIOTM" #define RECEIVING_PROTOCOL_ENABLE_OUTPUT 'O' #define QUERY_STATUS_COMMAND 'Q' #define DIGITAL_HIGH 'H' @@ -162,7 +174,6 @@ // Positions -#define RECEIVING_PROTOCOL_LENGTH 58 #define RECEIVING_PROTOCOL_ID_POS 0 #define RECEIVING_PROTOCOL_OP_POS 4 #define RECEIVING_PROTOCOL_EN_DO_POS RECEIVING_PROTOCOL_OP_POS + 0 @@ -178,7 +189,6 @@ #define RECEIVING_PROTOCOL_UART_POS 25 -#define SENDING_PROTOCOL_LENGTH 39 #define SENDING_PROTOCOL_ID_POS 0 #define SENDING_PROTOCOL_MAC_POS 4 #define SENDING_PROTOCOL_IP_POS 10 @@ -446,29 +456,43 @@ if (n <= 0) continue; // got some data, test it - DBG("UDP received: %s\r\n", udp_server_buffer); + DBG("UDP received (%s) from (%s) and port (%d)\r\n", udp_server_buffer, ep_udp_client.get_address(), ep_udp_client.get_port()); // process received data switch (n) { - // length = 6, a CONFIGURATION command (discovery command, TCP port, or UDP port) - // Format: NNIODS, NNIOTP or NNIOUP - case 6: + // length = 6, a QUERY command (discovery command, TCP port, or UDP port) + // Format: NNIODS, NNIOTP, NNIOUP, NNIOTM + case QUERY_CMD_LENGTH: // discovery command - if (strstr(udp_server_buffer, "NNIODS") != NULL) { - udp_server.sendTo(ep_udp_client, eth.getIPAddress(), strlen(eth.getIPAddress())); + if (strstr(udp_server_buffer, QUERY_DISCOVERY_CMD) != NULL) { + char str[30]; + sprintf(str, "%s%s", DEVICE_ID, eth.getIPAddress()); + udp_server.sendTo(ep_udp_client, str, strlen(str)); } // NNIODS + else if (strstr(udp_server_buffer, QUERY_IP_CMD) != NULL) { + udp_server.sendTo(ep_udp_client, eth.getIPAddress(), strlen(eth.getIPAddress())); + } // NNIOIP + else if (strstr(udp_server_buffer, QUERY_SUBNET_CMD) != NULL) { + udp_server.sendTo(ep_udp_client, eth.getNetworkMask(), strlen(eth.getNetworkMask())); + } // NNIOSN + else if (strstr(udp_server_buffer, QUERY_GATEWAY_CMD) != NULL) { + udp_server.sendTo(ep_udp_client, eth.getGateway(), strlen(eth.getGateway())); + } // NNIOGW + else if (strstr(udp_server_buffer, QUERY_MAC_CMD) != NULL) { + udp_server.sendTo(ep_udp_client, eth.getMACAddress(), strlen(eth.getMACAddress())); + } // NNIOMC // ask for TCP server port - else if (strstr(udp_server_buffer, "NNIOTP") != NULL) { + else if (strstr(udp_server_buffer, QUERY_TCP_PORT_CMD) != NULL) { char port[5]; sprintf(port, "%5d", tcp_server_local_port); udp_server.sendTo(ep_udp_client, port, strlen(port)); } // NNIOTP // ask for UDP server port - else if (strstr(udp_server_buffer, "NNIOUP") != NULL) { + else if (strstr(udp_server_buffer, QUERY_UDP_PORT_CMD) != NULL) { char port[5]; sprintf(port, "%5d", udp_server_local_port); udp_server.sendTo(ep_udp_client, port, strlen(port)); } // NNIOUP - else if (strstr(udp_server_buffer, "NNIOTM") != NULL) { + else if (strstr(udp_server_buffer, QUERY_UPDATE_TIME_CMD) != NULL) { #ifdef NTP char str_time[50]; @@ -498,7 +522,7 @@ // length = 19, SET NETWORK CONFIGURATION // Format: 4E 4E 49 4F C0 A8 00 78 FF FF FF 00 C0 A8 00 01 00 00 01 // (NNIO; IP: 192.168.0.120; Subnet: 255.255.255.0; GW: 192.168.0.1; MAC: 0 0 1) - case 19:{ + case SET_NETWORK_CONFIG_CMD_LENGTH: { // check device id char* id = strstr(udp_server_buffer, DEVICE_ID); if (id == NULL) @@ -512,9 +536,9 @@ } // length = 12, SET TCP SERVER CONFIGURATION // auto update & its time period, TCP server configuration (IP & port) - // Format: 4E 4E 49 4F 5A 01 C0 A8 00 09 E0 2E (LSB MSB) + // Format: 4E 4E 49 4F 'Y' 01 C0 A8 00 09 E0 2E (LSB MSB) // NNIO Auto 1s 192.168.0.9 12000 - case 12: { + case UPDATE_TCP_SERVER_INFO_CMD_LENGTH: { char* id = strstr(udp_server_buffer, DEVICE_ID); if (id == NULL) break;
--- a/my_eeprom_funcs.lib Thu Oct 02 19:41:38 2014 +0000 +++ b/my_eeprom_funcs.lib Sat Oct 04 20:25:45 2014 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/olympux/code/my_eeprom_funcs/#69e1c4ed69e1 +http://mbed.org/users/olympux/code/my_eeprom_funcs/#944a4646b825
--- a/readme.txt Thu Oct 02 19:41:38 2014 +0000 +++ b/readme.txt Sat Oct 04 20:25:45 2014 +0000 @@ -2,7 +2,9 @@ 1. DISCOVERY Command + UDP broadcast: 192.168.0.255 to port 11000 + Send: NNIODS - + Receive: IP address + + Receive: NNIO IP-address +1a. Query Command: IP, subnet, gateway, mac + + + Send: NNIOIP, NNIOSN, NNIOGW, NNIOMC 2. TCP SERVER PORT Command + Send: NNIOTP