Skip to content

Commit 7c3e261

Browse files
committed
fix ethernet include issue
1 parent 982e1e1 commit 7c3e261

File tree

2 files changed

+32
-58
lines changed

2 files changed

+32
-58
lines changed

AdafruitIO_Ethernet.cpp

Lines changed: 0 additions & 43 deletions
This file was deleted.

AdafruitIO_Ethernet.h

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,43 +9,60 @@
99
//
1010
// All text above must be included in any redistribution.
1111
//
12-
#ifndef ADAFRUITIO_Ethernet_H
13-
#define ADAFRUITIO_Ethernet_H
14-
12+
#ifndef ADAFRUITIO_ETHERNET_H
13+
#define ADAFRUITIO_ETHERNET_H
1514

1615
#include "Arduino.h"
1716
#include <SPI.h>
1817
#include "Adafruit_MQTT.h"
1918
#include "Adafruit_MQTT_Client.h"
2019

21-
#if __has_include("Ethernet2.h")
22-
#include <Ethernet2.h>
23-
#else
24-
#include <Ethernet.h>
25-
#endif
26-
20+
#include <Ethernet2.h>
2721
#include <EthernetClient.h>
2822
#include <Dns.h>
2923
#include <Dhcp.h>
3024

3125
#include "AdafruitIO.h"
3226

27+
// all logic in .h to avoid auto compile
3328
class AdafruitIO_Ethernet : public AdafruitIO {
3429

3530
public:
36-
AdafruitIO_Ethernet(const char *user, const char *key);
37-
AdafruitIO_Ethernet(const __FlashStringHelper *user, const __FlashStringHelper *key);
31+
AdafruitIO_Ethernet(const char *user, const char *key):AdafruitIO(user, key)
32+
{
33+
_client = new EthernetClient();
34+
_mqtt = new Adafruit_MQTT_Client(_client, _host, _port);
35+
}
3836

39-
aio_status_t networkStatus();
37+
AdafruitIO_Ethernet(const __FlashStringHelper *user, const __FlashStringHelper *key):AdafruitIO(user, key)
38+
{
39+
_client = new EthernetClient();
40+
_mqtt = new Adafruit_MQTT_Client(_client, _host, _port);
41+
}
4042

41-
protected:
42-
void _connect();
43+
aio_status_t networkStatus()
44+
{
45+
if(_status == AIO_NET_CONNECTED)
46+
return _status;
4347

48+
_connect();
49+
return _status;
50+
}
51+
52+
protected:
4453
byte _mac[6] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
4554
uint16_t _port = 1883;
4655

4756
EthernetClient *_client;
4857

58+
void _connect()
59+
{
60+
if(Ethernet.begin(_mac) == 0)
61+
_status = AIO_NET_DISCONNECTED;
62+
else
63+
_status = AIO_NET_CONNECTED;
64+
}
65+
4966
};
5067

51-
#endif // ADAFRUITIO_Ethernet_H
68+
#endif // ADAFRUITIO_ETHERNET_H

0 commit comments

Comments
 (0)