Skip to content

Commit eee0664

Browse files
author
brentru
committed
add a check for ethernet featherwing or hardware
1 parent 70c7ce1 commit eee0664

File tree

1 file changed

+38
-28
lines changed

1 file changed

+38
-28
lines changed

src/AdafruitIO_Ethernet.h

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -25,43 +25,53 @@
2525
#include "AdafruitIO.h"
2626

2727
// all logic in .h to avoid auto compile
28-
class AdafruitIO_Ethernet : public AdafruitIO {
28+
class AdafruitIO_Ethernet : public AdafruitIO
29+
{
2930

30-
public:
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, _mqtt_port, _username, _key);
35-
_http = new HttpClient(*_client, _host, _http_port);
36-
}
37-
38-
aio_status_t networkStatus()
39-
{
40-
if(_status == AIO_NET_CONNECTED)
41-
return _status;
31+
public:
32+
AdafruitIO_Ethernet(const char *user, const char *key) : AdafruitIO(user, key)
33+
{
34+
_client = new EthernetClient();
35+
_mqtt = new Adafruit_MQTT_Client(_client, _host, _mqtt_port, _username, _key);
36+
_http = new HttpClient(*_client, _host, _http_port);
37+
}
4238

43-
_connect();
39+
aio_status_t networkStatus()
40+
{
41+
if (_status == AIO_NET_CONNECTED)
4442
return _status;
45-
}
4643

47-
const char* connectionType()
48-
{
49-
return "ethernet_wing";
50-
}
44+
_connect();
45+
return _status;
46+
}
47+
48+
const char *connectionType()
49+
{
50+
return "ethernet_wing";
51+
}
5152

52-
protected:
53-
byte _mac[6] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
53+
protected:
54+
byte _mac[6] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
5455

55-
EthernetClient *_client;
56+
EthernetClient *_client;
5657

57-
void _connect()
58+
void _connect()
59+
{
60+
if (Ethernet.begin(_mac) == 0)
5861
{
59-
if(Ethernet.begin(_mac) == 0)
60-
_status = AIO_NET_DISCONNECTED;
61-
else
62-
_status = AIO_NET_CONNECTED;
62+
_status = AIO_NET_DISCONNECTED;
63+
if (Ethernet.hardwareStatus() == EthernetNoHardware)
64+
{
65+
AIO_DEBUG_PRINTLN("Ethernet FeatherWing not found! Please recheck wiring connections.");
66+
while (true)
67+
delay(1); // do nothing, no point running without Ethernet hardware
68+
}
6369
}
64-
70+
else
71+
{
72+
_status = AIO_NET_CONNECTED;
73+
}
74+
}
6575
};
6676

6777
#endif // ADAFRUITIO_ETHERNET_H

0 commit comments

Comments
 (0)