Skip to content

Commit 43f3a96

Browse files
committed
add ethernet class
1 parent b3ec783 commit 43f3a96

File tree

2 files changed

+96
-0
lines changed

2 files changed

+96
-0
lines changed

AdafruitIO_Ethernet.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//
2+
// Adafruit invests time and resources providing this open source code.
3+
// Please support Adafruit and open source hardware by purchasing
4+
// products from Adafruit!
5+
//
6+
// Copyright (c) 2015-2016 Adafruit Industries
7+
// Authors: Tony DiCola, Todd Treece
8+
// Licensed under the MIT license.
9+
//
10+
// All text above must be included in any redistribution.
11+
//
12+
#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_SAMD)
13+
14+
#include "AdafruitIO_Ethernet.h"
15+
16+
AdafruitIO_Ethernet::AdafruitIO_Ethernet(const char *user, const char *key):AdafruitIO(user, key)
17+
{
18+
_client = new EthernetClient();
19+
_mqtt = new Adafruit_MQTT_Client(_client, _host, _port);
20+
}
21+
22+
AdafruitIO_Ethernet::AdafruitIO_Ethernet(const __FlashStringHelper *user, const __FlashStringHelper *key):AdafruitIO(user, key)
23+
{
24+
_client = new EthernetClient();
25+
_mqtt = new Adafruit_MQTT_Client(_client, _host, _port);
26+
}
27+
28+
void AdafruitIO_Ethernet::_connect()
29+
{
30+
31+
if(Ethernet.begin(_mac) == 0)
32+
_status = AIO_NET_DISCONNECTED;
33+
else
34+
_status = AIO_NET_CONNECTED;
35+
36+
}
37+
38+
aio_status_t AdafruitIO_Ethernet::networkStatus()
39+
{
40+
if(_status == AIO_NET_CONNECTED)
41+
return _status;
42+
43+
_connect();
44+
return _status;
45+
}
46+
47+
#endif // ARDUINO_ARCH_AVR || ARDUINO_ARCH_SAMD

AdafruitIO_Ethernet.h

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//
2+
// Adafruit invests time and resources providing this open source code.
3+
// Please support Adafruit and open source hardware by purchasing
4+
// products from Adafruit!
5+
//
6+
// Copyright (c) 2015-2016 Adafruit Industries
7+
// Authors: Tony DiCola, Todd Treece
8+
// Licensed under the MIT license.
9+
//
10+
// All text above must be included in any redistribution.
11+
//
12+
#ifndef ADAFRUITIO_Ethernet_H
13+
#define ADAFRUITIO_Ethernet_H
14+
15+
#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_SAMD)
16+
17+
#include "Arduino.h"
18+
#include <SPI.h>
19+
#include "Adafruit_MQTT.h"
20+
#include "Adafruit_MQTT_Client.h"
21+
22+
#include <Ethernet2.h>
23+
#include <EthernetClient.h>
24+
#include <Dns.h>
25+
#include <Dhcp.h>
26+
27+
#include "AdafruitIO.h"
28+
29+
class AdafruitIO_Ethernet : public AdafruitIO {
30+
31+
public:
32+
AdafruitIO_Ethernet(const char *user, const char *key);
33+
AdafruitIO_Ethernet(const __FlashStringHelper *user, const __FlashStringHelper *key);
34+
35+
aio_status_t networkStatus();
36+
37+
protected:
38+
void _connect();
39+
40+
byte _mac[6] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
41+
uint16_t _port = 1883;
42+
43+
EthernetClient *_client;
44+
45+
};
46+
47+
#endif // ARDUINO_ARCH_AVR || ARDUINO_ARCH_SAMD
48+
49+
#endif // ADAFRUITIO_Ethernet_H

0 commit comments

Comments
 (0)