Adafruit IO Arduino Library
AdafruitIO_Ethernet.h
Go to the documentation of this file.
1 
15 #ifndef ADAFRUITIO_ETHERNET_H
16 #define ADAFRUITIO_ETHERNET_H
17 
18 #include "Adafruit_MQTT.h"
19 #include "Adafruit_MQTT_Client.h"
20 #include "Arduino.h"
21 #include <SPI.h>
22 
23 #include <Dhcp.h>
24 #include <Dns.h>
25 #include <Ethernet.h>
26 #include <EthernetClient.h>
27 
28 #include "AdafruitIO.h"
29 
30 /**************************************************************************/
34 /**************************************************************************/
36 
37 public:
38  /**************************************************************************/
46  /**************************************************************************/
47  AdafruitIO_Ethernet(const char *user, const char *key)
48  : AdafruitIO(user, key) {
49  _client = new EthernetClient();
50  _mqtt = new Adafruit_MQTT_Client(_client, _host, _mqtt_eth_port, _username,
51  _key);
52  _http = new HttpClient(*_client, _host, _http_port);
53  }
54 
55  /**************************************************************************/
61  /**************************************************************************/
63  if (_status == AIO_NET_CONNECTED)
64  return _status;
65 
66  _connect();
67  return _status;
68  }
69 
70  /**************************************************************************/
75  /**************************************************************************/
76  const char *connectionType() { return "ethernet_wing"; }
77 
78 protected:
79  byte _mac[6] = {0xDE, 0xAD, 0xBE,
80  0xEF, 0xFE, 0xED};
82  EthernetClient *_client;
84  /**************************************************************************/
88  /**************************************************************************/
89  void _connect() {
90  if (Ethernet.begin(_mac) == 0) {
91  _status = AIO_NET_DISCONNECTED;
92  if (Ethernet.hardwareStatus() == EthernetNoHardware) {
93  AIO_DEBUG_PRINTLN("Ethernet FeatherWing not found! Please recheck "
94  "wiring connections.");
95  while (true)
96  delay(1); // do nothing, no point running without Ethernet hardware
97  }
98  } else {
99  _status = AIO_NET_CONNECTED;
100  }
101  }
102 
103  /**************************************************************************/
107  /**************************************************************************/
108  void _disconnect() {
109  _client->stop();
111  }
112 };
113 
114 #endif // ADAFRUITIO_ETHERNET_H
Class for interacting with Adafruit IO.
Definition: AdafruitIO.h:45
const char * _username
Definition: AdafruitIO.h:158
aio_status_t _status
Definition: AdafruitIO.h:138
byte _mac[6]
Definition: AdafruitIO_Ethernet.h:79
uint16_t _http_port
Definition: AdafruitIO.h:153
void _connect()
Attempts to connect Ethernet FeatherWing to Adafruit IO.
Definition: AdafruitIO_Ethernet.h:89
uint16_t _mqtt_eth_port
Definition: AdafruitIO.h:151
AdafruitIO_Ethernet(const char *user, const char *key)
Instanciates an Adafruit Ethernet FeatherWing.
Definition: AdafruitIO_Ethernet.h:47
#define AIO_NET_DISCONNECT_WAIT
Time to wait for a net disconnect to take effect.
Definition: AdafruitIO_Definitions.h:116
Adafruit_MQTT * _mqtt
Definition: AdafruitIO.h:144
Class for interfacing with the Adafruit Ethernet FeatherWing.
Definition: AdafruitIO_Ethernet.h:35
EthernetClient * _client
Definition: AdafruitIO_Ethernet.h:82
#define AIO_DEBUG_PRINTLN(...)
Prints line from debug output.
Definition: AdafruitIO_Definitions.h:89
aio_status_t networkStatus()
Checks the connection status between the Ethernet FeatherWing and Adafruit IO.
Definition: AdafruitIO_Ethernet.h:62
const char * _host
Definition: AdafruitIO.h:149
void _disconnect()
Disconnect the ethernet connection.
Definition: AdafruitIO_Ethernet.h:108
const char * connectionType()
Defines network module type.
Definition: AdafruitIO_Ethernet.h:76
aio_status_t
Definition: AdafruitIO_Definitions.h:142
const char * _key
Definition: AdafruitIO.h:159
HttpClient * _http
Definition: AdafruitIO.h:145