forked from njh/EtherCard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docu.dox
96 lines (81 loc) · 3.76 KB
/
docu.dox
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/**
@mainpage EtherCard is a driver for the ENC28J60 chip, compatible with Arduino IDE.<br/>
Adapted and extended from code written by Guido Socher and Pascal Stang.<br/>
The home page for this library is at http://jeelabs.net/projects/ethercard/wiki.<br/>
License: <a href="http://www.gnu.org/licenses/gpl-2.0.html">GPL2</a><br/><br/>
<b>PIN Connections (Using Arduino UNO):</b>
<table border="1">
<tr><th>EtherCard</th><th>Arduino UNO</th></tr>
<tr><td>VCC</td><td>3.3V</td></tr>
<tr><td>GND</td><td>GND</td></tr>
<tr><td>SCK</td><td>Pin 13</td></tr>
<tr><td>SO</td><td>Pin 12</td></tr>
<tr><td>SI</td><td>Pin 11</td></tr>
<tr><td>CS</td><td>Pin 8</td></tr>
</table>
@section intro_sec Introduction
EtherCard is a library that performs low-level interfacing with network interfaces based on the MicroChip (C) ENC28J60.
High-level routines are provided to allow a variety of purposes including simple data transfer through to HTTP handling.
EtherCard is a driver for the ENC28J60 chip, compatible with Arduino IDE.
Adapted and extended from code written by Guido Socher and Pascal Stang.
The documentation for this library is at http://jeelabs.net/pub/docs/ethercard/
The code is available on GitHub, at https://github.com/jcw/ethercard - to install:
Download the ZIP file from https://github.com/jcw/ethercard/archive/master.zip
From the Arduino IDE: Sketch -> Import Library... -> Add Library...
Restart the Arduino IDE to see the new "EtherCard" library with examples
See the comments in the example sketches for details about how to try them out.
For questions and help, see the forums. For bugs and feature requests, see the issue tracker.
@section eg_sec Examples
Several @link examples example scripts @endlink are provided with the library which demonstrate various features. Below are descriptions on how to use the library.
<p>Note: <b>ether</b> is defined globally and may be used to access the library thus: ether.<i>member</i>.
@subsection Initiate To initiate the library call EtherCard::begin
<pre>
uint8_t Ethernet::buffer[700]; // configure buffer size to 700 octets
static uint8_t mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 }; // define (unique on LAN) hardware (MAC) address
uint8_type nFirmwareVersion ether.begin(sizeof Ethernet::buffer, mymac);
if(0 == nFirmwareVersion)
{
// handle failure to initiate network interface
}
</pre>
@subsection DHCP To configure IP address via DHCP use EtherCard::dhcpSetup
<pre>
if(!ether.dhcpSetup())
{
// handle failure to obtain IP address via DHCP
}
ether.printIp("IP: ", ether.myip); // output IP address to Serial
ether.printIp("GW: ", ether.gwip); // output gateway address to Serial
ether.printIp("Mask: ", ether.mymask); // output netmask to Serial
ether.printIp("DHCP server: ", ether.dhcpip); // output IP address of the DHCP server
</pre>
@subsection StaticIP To configure a static IP address use EtherCard::staticSetup
<pre>
const static uint8_t ip[] = {192,168,0,100};
const static uint8_t gw[] = {192,168,0,254};
const static uint8_t dns[] = {192,168,0,1};
if(!ether.staticSetup(ip, gw, dns);
{
// handle failure to configure static IP address (current implementation always returns true!)
}
</pre>
@subsection SendUDP Send UDP packet
To send a UDP packet use EtherCard::sendUdp
<pre>
char payload[] = "My UDP message";
uint8_t nSourcePort = 1234;
uint8_t nDestinationPort = 5678;
uint8_t ipDestinationAddress[4];
ether.parseIp(ipDestinationAddress, "192.168.0.200");
ether.sendUdp(payload, sizeof(payload), nSourcePort, ipDestinationAddress, nDestinationPort);
</pre>
@subsection DNSLookup DNS Lookup
To perform a DNS lookup use EtherCard::dnsLookup
<pre>
if(!ether.dnsLookup("google.com"))
{
// handle failure of DNS lookup
}
ether.printIp("Server: ", ether.hispip); // Result of DNS lookup is placed in the hisip member of EtherCard.
</pre>
*/