Skip to content

Commit 17e5a2a

Browse files
committed
add esp32 support
1 parent 8b4cd34 commit 17e5a2a

File tree

3 files changed

+113
-0
lines changed

3 files changed

+113
-0
lines changed

AdafruitIO_ESP32.cpp

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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+
#ifdef ARDUINO_ARCH_ESP32
13+
14+
#include "AdafruitIO_ESP32.h"
15+
16+
AdafruitIO_ESP32::AdafruitIO_ESP32(const char *user, const char *key, const char *ssid, const char *pass):AdafruitIO(user, key)
17+
{
18+
_ssid = ssid;
19+
_pass = pass;
20+
_client = new WiFiClient;
21+
_mqtt = new Adafruit_MQTT_Client(_client, _host, _port);
22+
}
23+
24+
AdafruitIO_ESP32::AdafruitIO_ESP32(const __FlashStringHelper *user, const __FlashStringHelper *key, const __FlashStringHelper *ssid, const __FlashStringHelper *pass):AdafruitIO(user, key)
25+
{
26+
_ssid = (const char*)ssid;
27+
_pass = (const char*)pass;
28+
_client = new WiFiClient;
29+
_mqtt = new Adafruit_MQTT_Client(_client, _host, _port);
30+
}
31+
32+
AdafruitIO_ESP32::~AdafruitIO_ESP32()
33+
{
34+
if(_client)
35+
delete _client;
36+
if(_mqtt)
37+
delete _mqtt;
38+
}
39+
40+
void AdafruitIO_ESP32::_connect()
41+
{
42+
43+
delay(100);
44+
WiFi.begin(_ssid, _pass);
45+
delay(100);
46+
_status = AIO_NET_DISCONNECTED;
47+
48+
}
49+
50+
aio_status_t AdafruitIO_ESP32::networkStatus()
51+
{
52+
53+
switch(WiFi.status()) {
54+
case WL_CONNECTED:
55+
return AIO_NET_CONNECTED;
56+
case WL_CONNECT_FAILED:
57+
return AIO_NET_CONNECT_FAILED;
58+
case WL_IDLE_STATUS:
59+
return AIO_IDLE;
60+
default:
61+
return AIO_NET_DISCONNECTED;
62+
}
63+
64+
}
65+
66+
#endif // ESP32

AdafruitIO_ESP32.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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_ESP32_H
13+
#define ADAFRUITIO_ESP32_H
14+
15+
#ifdef ARDUINO_ARCH_ESP32
16+
17+
#include "Arduino.h"
18+
#include "AdafruitIO.h"
19+
#include <WiFi.h>
20+
#include "Adafruit_MQTT.h"
21+
#include "Adafruit_MQTT_Client.h"
22+
23+
class AdafruitIO_ESP32 : public AdafruitIO {
24+
25+
public:
26+
AdafruitIO_ESP32(const char *user, const char *key, const char *ssid, const char *pass);
27+
AdafruitIO_ESP32(const __FlashStringHelper *user, const __FlashStringHelper *key, const __FlashStringHelper *ssid, const __FlashStringHelper *pass);
28+
~AdafruitIO_ESP32();
29+
30+
aio_status_t networkStatus();
31+
32+
protected:
33+
void _connect();
34+
35+
const char *_ssid;
36+
const char *_pass;
37+
WiFiClient *_client;
38+
39+
};
40+
41+
#endif //ESP32
42+
#endif // ADAFRUITIO_ESP32_H

AdafruitIO_WiFi.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
#include "AdafruitIO_WINC1500.h"
2323
typedef AdafruitIO_WINC1500 AdafruitIO_WiFi;
2424

25+
#elif defined(ARDUINO_ARCH_ESP32)
26+
27+
#include "AdafruitIO_ESP32.h"
28+
typedef AdafruitIO_ESP32 AdafruitIO_WiFi;
29+
2530
#elif defined(ESP8266)
2631

2732
#include "AdafruitIO_ESP8266.h"

0 commit comments

Comments
 (0)