DHCP basic setup and communication?
Ethernet Chips
No replies yet. Be the first to reply.
Join the discussion.
Ethernet Chips
No replies yet. Be the first to reply.
Join the discussion.
Share projects and connect with makers.
Joined before the site update? first.
New to WIZnet Makers?
We sent a verification link to your address. Open it to activate your account, then log in.
Accounts from this email provider are reviewed by an administrator after verification. Approval usually takes one business day.
Already have an account?
Enter your email address. If it belongs to an account, we'll send a link to set a new password. Members who joined before the site update use this to set their password.
If an account uses that address, we sent a link to set a new password. The link works once and expires in 30 minutes.
Know your password?
Need an account?
RE: DHCP basic setup and communication?
by hjjeon0608 ·
Hi,
I will try to describe how to use DHCP application.
If you cannot understand, reply.
I explain based on ioLibrary with CoIDE project at WIZwiki.
Step 1.
Register DHCP timer handler.
[code]void SysTickIntHandler(void)
{
msTicks++; /* increment counter necessary in Delay()*/
}[/code]
SysTickIntHandler is MCU timer handler. This handler is dependent on MCU. So you should refer to your MCU vendor datasheet.
msTicks is increased every 1ms and DHCP timer wants to increase every 1sec. So DHCP_time_handler() called every 1sec by if(msTicks % 1000 == 0) DHCP_time_handler();
Step 2.
You can see structure gWIZNETINFO.
wiz_NetInfo gWIZNETINFO = { .mac = {0x00, 0x08, 0xdc,0x00, 0xab, 0xcd}, .ip = {192, 168, 1, 123}, .sn = {255,255,255,0}, .gw = {192, 168, 1, 1}, .dns = {0,0,0,0}, .dhcp = NETINFO_DHCP };You concern only MAC address, so set MAC address.
And then run setSHAR function.
Then MAC address setting is done.
Step 3.
Run DHCP_init function and register callback function.
(It uses number 0 socket)
Step 4.
Run main loop
/* Main Loop */ while(1) { switch(DHCP_run()) { case DHCP_IP_ASSIGN: case DHCP_IP_CHANGED: /* If this block empty, act with default_ip_assign & default_ip_update */ // // This example calls my_ip_assign in the two case. // // Add to ... // break; case DHCP_IP_LEASED: // // TO DO YOUR NETWORK APPs. // break; case DHCP_FAILED: /* ===== Example pseudo code ===== */ // The below code can be replaced your code or omitted. // if omitted, retry to process DHCP my_dhcp_retry++; if(my_dhcp_retry > MY_MAX_DHCP_RETRY) { #ifdef _MAIN_DEBUG_ printf(">> DHCP %d Failed\r\n", my_dhcp_retry); #endif my_dhcp_retry = 0; DHCP_stop(); // if restart, recall DHCP_init() network_init(); // apply the default static network and print out netinfo to serial } break; default: break; }The main loop has DHCP_run() function. This function get IP, gateway, subnet. And then you concern only return value.
If main loop is success, return value is DHCP_IP_LEASED.
And IP, gateway, subbet is set already so just design your application in case DHCP_IP_LEASED:
Thanks.
RE: DHCP basic setup and communication?
by devWarrior ·
Thanks!
So I’m trying to understand the lowest level right now. Could you help me? Not sure if the general steps are:
I’m very new at this, but I don’t want to use the prewritten files from Wiznet. Any help would be greatly appreciated!
RE: DHCP basic setup and communication?
by alexpescaru ·
It’s no shame to look and understand the prewritten files.
Consider them as an instructions manual.
When you’ll understand them, you’ll be able to write your own code.
RE: DHCP basic setup and communication?
by hjjeon0608 ·
And then DHCP phases are run.
Refer to WIKI~
[url]http://en.wikipedia.org/wiki/Dynamic_Host_Configuration_Protocol[/url]
There is detailed explanation.
Also refer to WIZnet W5100 application note.
[url]https://www.wiznet.co.kr:8011/UpLoad_Files/ReferenceFiles/W5100_Appnote_DHCP.zip[/url]
RE: DHCP basic setup and communication?
by devWarrior ·
So this is what I have…I send the message, but never receive a response. Maybe my message is in the wrong format…please let me know if you see anything that I may be doing wrong (ps-I know this isn’t the prettiest code, but I’m working on it
) Thanks!!!
Here’s my DHCP setup:
Here’s the DHCP DISCOVER message I make…
RE: DHCP basic setup and communication?
by hjjeon0608 ·
I want to know your discover message by packet capture(like wireshark).
Plz, attach files.
Thanks.