friendev EtherDune TCP/IP library
DHCPTest.ino
Go to the documentation of this file.
1 // EtherDune DHCP client demo
2 // Author: Javier Peletier <jm@friendev.com>
3 // Summary: Shows how to use DHCP in your project
4 //
5 // Copyright (c) 2015 All Rights Reserved, http://friendev.com
6 //
7 // This source is subject to the GPLv2 license.
8 // Please see the License.txt file for more information.
9 // All other rights reserved.
10 //
11 // THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
12 // KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
13 // IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
14 // PARTICULAR PURPOSE.
15 
30 #include <ACross.h>
31 #include <FlowScanner.h>
32 #include <DHCP.h>
33 
34 
35 #define AC_LOGLEVEL 6
36 #include <ACLog.h>
37 ACROSS_MODULE("DHCPTest");
38 
39 
40 static const uint8_t CS_PIN = 10; //Put here what pin you are using for your ENC28J60's chip select
41 static MACAddress_P mymac = { 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64 };
42 
43 DHCP dhcp; //instantiate the DHCP service
44 
45 
46 void setup()
47 {
48 
49  Serial.begin(115200);
50  ACross::init();
51 
52  Serial.println(F("EtherDune DHCP sample"));
53  Serial.print(F("Free RAM: ")); Serial.println(ACross::getFreeRam());
54  Serial.println(F("Press any key to start..."));
55 
56  while (!Serial.available());
57 
59 
60  if (!net::begin(CS_PIN))
61  ACERROR("failed to start EtherDune");
62 
63  ACINFO("waiting for link...");
64 
65  while (!net::isLinkUp());
66 
67  ACINFO("link is up");
68 
69  Serial.println("Obtaining DHCP configuration...");
70 
71  if (!dhcp.dhcpSetup())
72  {
73  Serial.println(F("DHCP setup failed"));
74  ACross::halt(1);
75  }
76 
77  Serial.println(F("DHCP setup OK"));
78 
79  Serial.println(F("DHCP config:"));
80  Serial.print(F("Local IP: "));
81  Serial.println(net::localIP.toString());
82  Serial.print(F("Network mask: "));
83  Serial.println(net::netmask.toString());
84  Serial.print(F("Gateway IP: "));
85  Serial.println(net::gatewayIP.toString());
86  Serial.print(F("DNS IP: "));
87  Serial.println(net::dnsIP.toString());
88 
89  Serial.println(F("\nDHCP works!"));
90 
91 }
92 
93 
94 void loop()
95 {
96  net::loop(); //given the DHCP instance is alive, net::loop() will keep the lease alive.
97 
98 }
99 
100 /// \endcond
#define MACAddress_P
Definition: inet.h:242
EtherDune DHCP Service.
Definition: DHCP.h:122
static bool begin(uint8_t cspin)
Initializes EtherDune and the underlying hardware
static IPAddress netmask
Subnet mask.
static IPAddress gatewayIP
IP address of the gateway in this network.
ACROSS_MODULE("ARP")
static const uint8_t CS_PIN
bool dhcpSetup()
Attempts to configure the IP settings: local IP, subnet mask, gateway and DNS via DHCP...
Definition: DHCP.cpp:50
static MACAddress_P mymac
static bool isLinkUp()
Determines whether the network link is ready
Definition: ENC28J60.cpp:306
void setup()
static IPAddress dnsIP
IP address of the DNS server to use.
DHCP dhcp
static MACAddress localMAC
Ethernet MAC address.
static void loop()
Gives processing time to EtherDune so that it can check for incoming packets or send queued packets...
static IPAddress localIP
IP address of this application.
void loop()