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 43:48ca8c6f6f49, committed 2016-06-16
- Comitter:
- olympux
- Date:
- Thu Jun 16 21:44:22 2016 +0000
- Parent:
- 42:d0ff08711ca5
- Child:
- 44:4e8a9b466695
- Commit message:
- Reset and save IP address through RPC
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
my_eeprom_funcs.lib | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Thu Jun 16 19:22:36 2016 +0000 +++ b/main.cpp Thu Jun 16 21:44:22 2016 +0000 @@ -73,7 +73,7 @@ */ // Device configuration uint16_t u16ip_addr[4], u16ip_subnet[4], u16ip_gateway[4], u16mac_addr[3]; // 16-bits, directly loaded from eeprom -char str_ip_addr[16], str_ip_subnet[16], str_ip_gateway[16], str_mac_addr[16]; // for printf and RPC, converted from 16-bits u16ip_xxx +char str_ip_addr[16], str_ip_subnet[16], str_ip_gateway[16], str_mac_addr[20]; // for printf and RPC, converted from 16-bits u16ip_xxx uint8_t u8ip_addr[4];// keep ip address in 8-bits uint16_t configured_ip = 0; // flag indicates a static ip has been configured 0xA5A5 uint8_t u8mac[6]; // mac in 8-bits @@ -96,11 +96,39 @@ RPCVariable<char*> rpcIPAddress(str_ip_addr, 16, "ipaddr"); RPCVariable<char*> rpcSubnet(str_ip_subnet, 16, "subnet"); RPCVariable<char*> rpcGateway(str_ip_gateway, 16, "gateway"); -RPCVariable<char*> rpcMac(str_mac_addr, 16, "mac"); +RPCVariable<char*> rpcMac(str_mac_addr, 20, "mac"); RPCVariable<unsigned short> rpcLocalTCPServerPort(&tcp_server_local_port, "localtcpserverport"); RPCVariable<unsigned short> rpcLocalUDPPort(&udp_server_local_port, "localudpport"); RPCVariable<unsigned short> rpcEnableTCPServer(&u16enable_tcp_server, "enabletcpserver"); +// RPC function definitions +// Create a function of the required format +void save_ip_addr(Arguments* args, Reply* rep); +void disable_static_ip_addr_flag(Arguments* args, Reply* rep); + +void save_ip_addr(Arguments* args, Reply* rep){ + int b[4], n, i; + char ipaddr[4]; + + n = sscanf(str_ip_addr, "%d.%d.%d.%d", &b[0], &b[1], &b[2], &b[3]); + if (n == 4) { + DBG("%d.%d.%d.%d",b[0],b[1],b[2],b[3]); + for (i = 0; i < 4; i++) { + ipaddr[i] = b[i] & 0x00FF; + } + save_ip_addr(ipaddr); + NVIC_SystemReset(); + } + else { + DBG("Saving IP address failed"); + } +} +void reset_configuration(Arguments* args, Reply* rep){ + reset_conf(); +} +// Attach it to an RPC object +RPCFunction rpcSaveIPAddr(&save_ip_addr, "saveipaddr"); +RPCFunction rpcResetConfiguration(&reset_configuration, "resetconf"); // Serial Serial uart(USBTX,USBRX); @@ -178,12 +206,6 @@ } Thread::wait(2000); // TCP/UDP stack delay - - // Test parsing ip address string - char* ipaddr = "192.168.0.121"; - int b[4]; - sscanf(ipaddr, "%d.%d.%d.%d", &b[0], &b[1], &b[2], &b[3]); - DBG("%d.%d.%d.%d",b[0],b[1],b[2],b[3]); // create rpc http server HTTPServer srv = create_interactive_server();
--- a/my_eeprom_funcs.lib Thu Jun 16 19:22:36 2016 +0000 +++ b/my_eeprom_funcs.lib Thu Jun 16 21:44:22 2016 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/olympux/code/my_eeprom_funcs/#7ffbbfe999c5 +http://mbed.org/users/olympux/code/my_eeprom_funcs/#17a44517b13d