-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDHCP_TEST.ino
102 lines (74 loc) · 1.93 KB
/
DHCP_TEST.ino
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
97
98
99
100
101
102
#include <EtherCard.h>
//https://github.com/greiman/SSD1306Ascii
#include <SPI.h>
#include "SSD1306Ascii.h"
#include "SSD1306AsciiSoftSpi.h"
// ethernet interface mac address, must be unique on the LAN
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
byte Ethernet::buffer[700];
#define CSEthernetPin 10
// Declaration for SSD1306 oled connected using software SPI (default case):
#define OLED_MOSI 9
#define OLED_CLK 7
#define OLED_DC 5
#define OLED_CS 4
#define OLED_RESET 6
SSD1306AsciiSoftSpi oled;
void OLEDprintIp (const uint8_t *buf) {
for(uint8_t i = 0; i < 4; i++){
char rr[4];
int num = buf[i];
itoa(num, rr, 10);
oled.write(rr);
if(i < 3) oled.write(".");
}
}
void OLEDprintMac (const uint8_t *buf) {
for(uint8_t i = 0; i < 6; i++){
char rr[4];
int num = buf[i];
itoa(num, rr, 16);
oled.write(rr);
//if(i <5) oled.write(".");
}
}
void setup()
{
Serial.begin(9600);
oled.begin(&Adafruit128x64, OLED_CS, OLED_DC, OLED_CLK, OLED_MOSI, OLED_RESET);
oled.setFont(System5x7);
oled.clear();
oled.write("Trying DHCP server...");
oled.setCursor(0, 1);
if (ether.begin(sizeof Ethernet::buffer, mymac, CSEthernetPin) == 0)
{
oled.write("ETHERNET FAILED");
for (;;);
}
else {
if (!ether.dhcpSetup())
{
oled.write("DHCP FAILED");
}
else
{
oled.write("DHCP OK");
oled.setCursor(0,2);
oled.write("IP: ");
OLEDprintIp(ether.myip);
oled.setCursor(0,3);
oled.write("Mask: ");
OLEDprintIp(ether.netmask);
oled.setCursor(0,4);
oled.write("DNS: ");
OLEDprintIp(ether.dnsip);
oled.setCursor(0,5);
oled.write("GW: ");
OLEDprintIp(ether.gwip);
oled.setCursor(0,6);
oled.write("MAC: ");
OLEDprintMac(mymac);
}
}
}
void loop() { }