supla-device
Loading...
Searching...
No Matches
ENC28J60.h
1// SPDX-FileCopyrightText: AC SOFTWARE SP. Z O.O.
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#ifndef SRC_SUPLA_NETWORK_ENC28J60_H_
5#define SRC_SUPLA_NETWORK_ENC28J60_H_
6
7#ifdef ARDUINO_ARCH_AVR
8#include <Arduino.h>
9#include <EthernetENC.h>
10#include <supla/log_wrapper.h>
11
12#include "../supla_lib_config.h"
13#include "network.h"
14
15namespace Supla {
16class ENC28J60 : public Supla::Network {
17 public:
18 explicit ENC28J60(uint8_t mac[6], unsigned char *ip = NULL) : Network(ip) {
19 memcpy(this->mac, mac, 6);
20 }
21
22 void disable() override {
23 isDeviceReady = false;
24 }
25
26 bool isReady() override {
27 return isDeviceReady;
28 }
29
30 void setup() override {
31 setSSLEnabled(false); // no SSL support on Arduino MEGA target
32 SUPLA_LOG_INFO("Connecting to network...");
33 if (useLocalIp) {
34 Ethernet.begin(mac, localIp);
35 isDeviceReady = true;
36 } else {
37 isDeviceReady = Ethernet.begin(mac) == 1;
38 }
39
40 IPAddress localIP = Ethernet.localIP();
41 IPAddress subnetMaskIP = Ethernet.subnetMask();
42 IPAddress gatewayIP = Ethernet.gatewayIP();
43 IPAddress dnsServerIP = Ethernet.dnsServerIP();
44 SUPLA_LOG_INFO(
45 "localIP: %d.%d.%d.%d", localIP[0], localIP[1], localIP[2], localIP[3]);
46 SUPLA_LOG_INFO("subnetMaskIP: %d.%d.%d.%d",
47 subnetMaskIP[0],
48 subnetMaskIP[1],
49 subnetMaskIP[2],
50 subnetMaskIP[3]);
51 SUPLA_LOG_INFO("gatewayIP: %d.%d.%d.%d",
52 gatewayIP[0],
53 gatewayIP[1],
54 gatewayIP[2],
55 gatewayIP[3]);
56 SUPLA_LOG_INFO("dnsServerIP: %d.%d.%d.%d",
57 dnsServerIP[0],
58 dnsServerIP[1],
59 dnsServerIP[2],
60 dnsServerIP[3]);
61 SUPLA_LOG_INFO("ETH MAC: %02X:%02X:%02X:%02X:%02X:%02X",
62 mac[0],
63 mac[1],
64 mac[2],
65 mac[3],
66 mac[4],
67 mac[5]);
68 }
69
70 protected:
71 uint8_t mac[6] = {};
72 bool isDeviceReady = false;
73};
74
75}; // namespace Supla
76
77#endif // ARDUINO_ARCH_AVR
78
79#endif // SRC_SUPLA_NETWORK_ENC28J60_H_
Definition ip_address.h:15
Definition network.h:21