Editing UIP
Jump to navigation
Jump to search
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 75: | Line 75: | ||
==uIP Ethernet Application== | ==uIP Ethernet Application== | ||
− | |||
===DHCP Client=== | ===DHCP Client=== | ||
− | |||
*Enable UDP in "uip-config.h" | *Enable UDP in "uip-config.h" | ||
#define UIP_CONF_UDP 1 | #define UIP_CONF_UDP 1 | ||
*Make sure your uip buffer size is large enough (DHCP messages from some servers can be more than 500 bytes). In my setting, I use 1536 in "uip-config.h" | *Make sure your uip buffer size is large enough (DHCP messages from some servers can be more than 500 bytes). In my setting, I use 1536 in "uip-config.h" | ||
#define UIP_CONF_BUFFER_SIZE 1536 | #define UIP_CONF_BUFFER_SIZE 1536 | ||
+ | *Include the dhcpc.h header file in "uip-config.h" | ||
+ | #include "dhcpc.h" | ||
+ | *Change PT_WAIT_UNTIL(...) to PT_YIELD_UNTIL(...) in line 259 and 276 in "dhcpc.c" [This is a known bug in dhcpc.c] | ||
+ | *In your main loop, initialize your MAC address and DHCP if UIP_FIXEDADDR is 0 in "uip-opt.h", for example: | ||
+ | int main(void) | ||
+ | { | ||
+ | uip_ipaddr_t ipaddr; | ||
+ | struct timer periodic_timer, arp_timer; | ||
+ | struct uip_eth_addr mac = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06}; | ||
+ | |||
+ | timer_set(&periodic_timer, CLOCK_SECOND / 2); | ||
+ | timer_set(&arp_timer, CLOCK_SECOND * 10); | ||
+ | |||
+ | tapdev_init(); | ||
+ | uip_init(); | ||
+ | |||
+ | uip_setethaddr(mac); | ||
+ | dhcpc_init(&mac, 6); | ||
+ | |||
+ | while(1){ | ||
+ | //normal codes goes here | ||
+ | } | ||
+ | } | ||
+ | *Implement dhcpc_configured(). This function will be called after DHCP client has obtained an IP address. Basically, you have to at least set your IP address, subnet mask and default gateway, for example, | ||
+ | void dhcpc_configured(const struct dhcpc_state *s) | ||
+ | { | ||
+ | uip_sethostaddr(s->ipaddr); | ||
+ | uip_setnetmask(s->netmask); | ||
+ | uip_setdraddr(s->default_router); | ||
+ | |||
+ | //you can print your ip addr to your console/lcd to see if you get a valid ip address | ||
+ | } | ||
+ | *An example of using DHCP Client in the dsPic33F development board can be found [http://chungyan5.no-ip.org/vc/tags/1.09.05/demo_posix/common/app_http.c?root=freertos_posix&view=markup here]. | ||
===Web Server=== | ===Web Server=== | ||
− | * | + | *Include the "webserver.h" header file in "uip-config.h" |
+ | #include "webserver.h" | ||
+ | *Modify httpd-fs.h | ||
+ | **HTTPD_FS_STATISTICS set to 0 | ||
+ | *Create a website using HTML tags with/without Javascript | ||
+ | *Modify httpd-fs.c | ||
+ | **changed #include "httpd-fsdata.c" to #include <httpd-fsdata.c> | ||
+ | *Generate httpd-fsdata.c for your website by executing '''perl makefsdata''' under your web root directory. | ||
====add-on==== | ====add-on==== | ||
*The Web Server included in uIP 1.0 has been designed to load/reload the entire page (either html/shtml files) in response to a HTTP GET command, e.g. | *The Web Server included in uIP 1.0 has been designed to load/reload the entire page (either html/shtml files) in response to a HTTP GET command, e.g. | ||
Line 94: | Line 132: | ||
*In consideration of the above issue, a solution is proposed here, so that the webserver can handle this kind of cgi HTTP-request | *In consideration of the above issue, a solution is proposed here, so that the webserver can handle this kind of cgi HTTP-request | ||
GET /abc.shtml?val=500.0&button=Set HTTP/1.1 | GET /abc.shtml?val=500.0&button=Set HTTP/1.1 | ||
+ | *Modify httpd.c | ||
+ | **added #include "httpd-hget.h" in line 63 | ||
+ | **added httpd_hget(s->filename) in line 224 | ||
+ | *Create httpd-hget.h | ||
+ | **added to generate dynamic pages, e.g. /abc.shtml?button=Refresh | ||
+ | #ifndef __HTTPD_HGET_H__ | ||
+ | #define __HTTPD_HGET_H__ | ||
+ | extern void httpd_hget(char *name); | ||
+ | #endif | ||
+ | *Create httpd-hget.c | ||
+ | **an example is shown [http://chungyan5.no-ip.org/vc/tags/1.09.05/demo_posix/dspic/dspic33/rackmount/04_uip/uip/httpd-hget.c?root=freertos_posix&view=markup here] | ||
===DNS Resolver=== | ===DNS Resolver=== | ||
− | * | + | *to be added |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
===SMTP Mail Client=== | ===SMTP Mail Client=== | ||
− | * | + | *to be added |
− | |||