supla-device
Toggle main menu visibility
Loading...
Searching...
No Matches
src
supla
network
ENC28J60.h
1
/*
2
Copyright (C) AC SOFTWARE SP. Z O.O.
3
4
This program is free software; you can redistribute it and/or
5
modify it under the terms of the GNU General Public License
6
as published by the Free Software Foundation; either version 2
7
of the License, or (at your option) any later version.
8
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
13
14
You should have received a copy of the GNU General Public License
15
along with this program; if not, write to the Free Software
16
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
*/
18
19
#ifndef SRC_SUPLA_NETWORK_ENC28J60_H_
20
#define SRC_SUPLA_NETWORK_ENC28J60_H_
21
22
#ifdef ARDUINO_ARCH_AVR
23
#include <Arduino.h>
24
#include <EthernetENC.h>
25
#include <supla/log_wrapper.h>
26
27
#include "../supla_lib_config.h"
28
#include "network.h"
29
30
namespace
Supla {
31
class
ENC28J60 :
public
Supla::Network {
32
public
:
33
explicit
ENC28J60(uint8_t mac[6],
unsigned
char
*ip = NULL) : Network(ip) {
34
memcpy(this->mac, mac, 6);
35
}
36
37
void
disable()
override
{
38
isDeviceReady =
false
;
39
}
40
41
bool
isReady()
override
{
42
return
isDeviceReady;
43
}
44
45
void
setup()
override
{
46
setSSLEnabled(
false
);
// no SSL support on Arduino MEGA target
47
SUPLA_LOG_INFO(
"Connecting to network..."
);
48
if
(useLocalIp) {
49
Ethernet.begin(mac, localIp);
50
isDeviceReady =
true
;
51
}
else
{
52
isDeviceReady = Ethernet.begin(mac) == 1;
53
}
54
55
IPAddress localIP = Ethernet.localIP();
56
IPAddress subnetMaskIP = Ethernet.subnetMask();
57
IPAddress gatewayIP = Ethernet.gatewayIP();
58
IPAddress dnsServerIP = Ethernet.dnsServerIP();
59
SUPLA_LOG_INFO(
60
"localIP: %d.%d.%d.%d"
, localIP[0], localIP[1], localIP[2], localIP[3]);
61
SUPLA_LOG_INFO(
"subnetMaskIP: %d.%d.%d.%d"
,
62
subnetMaskIP[0],
63
subnetMaskIP[1],
64
subnetMaskIP[2],
65
subnetMaskIP[3]);
66
SUPLA_LOG_INFO(
"gatewayIP: %d.%d.%d.%d"
,
67
gatewayIP[0],
68
gatewayIP[1],
69
gatewayIP[2],
70
gatewayIP[3]);
71
SUPLA_LOG_INFO(
"dnsServerIP: %d.%d.%d.%d"
,
72
dnsServerIP[0],
73
dnsServerIP[1],
74
dnsServerIP[2],
75
dnsServerIP[3]);
76
}
77
78
protected
:
79
uint8_t mac[6] = {};
80
bool
isDeviceReady =
false
;
81
};
82
83
};
// namespace Supla
84
85
#endif
// ARDUINO_ARCH_AVR
86
87
#endif
// SRC_SUPLA_NETWORK_ENC28J60_H_
Generated by
1.17.0