Skip to content

Commit 185d2e2

Browse files
authored
Merge pull request #7 from adafruit/esp32
ESP32 Support
2 parents 0daa4e1 + c46865e commit 185d2e2

File tree

5 files changed

+127
-1
lines changed

5 files changed

+127
-1
lines changed

src/AdafruitIO_WiFi.h

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

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

2732
#include "wifi/AdafruitIO_ESP8266.h"

src/util/AdafruitIO_Board.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ char AdafruitIO_Board::_id[64] = "";
2121
const char AdafruitIO_Board::_type[] = "feather_32u4";
2222
#elif defined(ARDUINO_STM32_FEATHER)
2323
const char AdafruitIO_Board::_type[] = "feather_wiced";
24+
#elif defined(ARDUINO_ARCH_ESP32)
25+
#include <WiFi.h>
26+
const char AdafruitIO_Board::_type[] = "esp32";
2427
#elif defined(ESP8266)
2528
const char AdafruitIO_Board::_type[] = "esp8266";
2629
#else
@@ -61,6 +64,18 @@ const char* AdafruitIO_Board::type()
6164
return AdafruitIO_Board::_id;
6265
}
6366

67+
#elif defined(ARDUINO_ARCH_ESP32)
68+
69+
char* AdafruitIO_Board::id()
70+
{
71+
byte mac[6];
72+
WiFi.macAddress(mac);
73+
for(int i=0; i < 6; i++) {
74+
sprintf(&AdafruitIO_Board::_id[i*2],"%02x", mac[i]);
75+
}
76+
return AdafruitIO_Board::_id;
77+
}
78+
6479
#elif defined(ESP8266)
6580

6681
char* AdafruitIO_Board::id()

src/util/AdafruitIO_Board.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ class AdafruitIO_Board {
2828
static const char _type[];
2929
static const char* type();
3030

31-
3231
};
3332

3433
#endif // ADAFRUITIO_BOARD_H

src/wifi/AdafruitIO_ESP32.cpp

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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 WiFiClientSecure;
21+
_mqtt = new Adafruit_MQTT_Client(_client, _host, _mqtt_port);
22+
_http = new HttpClient(*_client, _host, _http_port);
23+
}
24+
25+
AdafruitIO_ESP32::~AdafruitIO_ESP32()
26+
{
27+
if(_client)
28+
delete _client;
29+
if(_mqtt)
30+
delete _mqtt;
31+
}
32+
33+
void AdafruitIO_ESP32::_connect()
34+
{
35+
36+
delay(100);
37+
WiFi.begin(_ssid, _pass);
38+
delay(100);
39+
_status = AIO_NET_DISCONNECTED;
40+
41+
}
42+
43+
aio_status_t AdafruitIO_ESP32::networkStatus()
44+
{
45+
46+
switch(WiFi.status()) {
47+
case WL_CONNECTED:
48+
return AIO_NET_CONNECTED;
49+
case WL_CONNECT_FAILED:
50+
return AIO_NET_CONNECT_FAILED;
51+
case WL_IDLE_STATUS:
52+
return AIO_IDLE;
53+
default:
54+
return AIO_NET_DISCONNECTED;
55+
}
56+
57+
}
58+
59+
const char* AdafruitIO_ESP32::connectionType()
60+
{
61+
return "wifi";
62+
}
63+
64+
#endif // ESP32

src/wifi/AdafruitIO_ESP32.h

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

0 commit comments

Comments
 (0)