In this second post, I’m going to show you how to use a DHCP server to automatically configure network parameters.
At the end of my first post you wrote a simple sketch where all the network parameters were defined as constants; this force you to recompile and reload your sketch if you need to change the network Arduino is connected to.
Usually, in local network you can find a DHCP server (Dynamic Host Configuration Protocol), that is a service which automatically configure the devices connected to the network.
Without explaining too deeply the protocol, it works this way:
- the device (client) that needs an IP address, sends a DISCOVERY broadcast packet (that is a packet which will reach all the devices in the network), to “discover” if there are DHCP servers available;
- if one or more DHCP servers are alive, they answer with an OFFER packet, “proposing” an available IP address to the requesting client;
- the client chooses one of the offered IP addresses and sends a REQUEST packet, to ask for permission to use that address;
- the server that proposed it, answers with an ACK packet to confirm the IP address association.
Luckly what I described above has altready been implemented for us in the dhcp.cpp library file: in the next page I’m going to show a simple sketch using DHCP services…
Pages: 1 2