Skip to content

Commit b370eef

Browse files
authored
Merge pull request #47 from ubidefeo/master
ESP32 support + example fix (AVR DebugUtils removal)
2 parents dbfb0e2 + 61e3a2a commit b370eef

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

examples/ConnectionHandlerDemo/ConnectionHandlerDemo.ino

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ void setup() {
3434
Serial.begin(9600);
3535
/* Give a few seconds for the Serial connection to be available */
3636
delay(4000);
37-
37+
#ifndef __AVR__
3838
setDebugMessageLevel(DBG_INFO);
39-
39+
#endif
4040
conMan.addCallback(NetworkConnectionEvent::CONNECTED, onNetworkConnect);
4141
conMan.addCallback(NetworkConnectionEvent::DISCONNECTED, onNetworkDisconnect);
4242
conMan.addCallback(NetworkConnectionEvent::ERROR, onNetworkError);

src/Arduino_ConnectionHandler.h

+11
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,17 @@
114114
#define WIFI_FIRMWARE_VERSION_REQUIRED WIFI_FIRMWARE_REQUIRED
115115
#endif
116116

117+
#if defined(ESP32)
118+
#include <WiFi.h>
119+
#include <WiFiUdp.h>
120+
#define BOARD_HAS_WIFI
121+
#define NETWORK_HARDWARE_ERROR WL_NO_SHIELD
122+
#define NETWORK_IDLE_STATUS WL_IDLE_STATUS
123+
#define NETWORK_CONNECTED WL_CONNECTED
124+
#define WIFI_FIRMWARE_VERSION_REQUIRED WIFI_FIRMWARE_REQUIRED
125+
126+
#endif
127+
117128
/******************************************************************************
118129
INCLUDES
119130
******************************************************************************/

src/Arduino_WiFiConnectionHandler.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ WiFiConnectionHandler::WiFiConnectionHandler(char const * ssid, char const * pas
4141

4242
unsigned long WiFiConnectionHandler::getTime()
4343
{
44-
#if !defined(BOARD_ESP8266)
44+
#if !defined(BOARD_ESP8266) && !defined(ESP32)
4545
return WiFi.getTime();
4646
#else
4747
return 0;
@@ -54,7 +54,7 @@ unsigned long WiFiConnectionHandler::getTime()
5454

5555
NetworkConnectionState WiFiConnectionHandler::update_handleInit()
5656
{
57-
#ifndef BOARD_ESP8266
57+
#if !defined(BOARD_ESP8266) && !defined(ESP32)
5858
#if !defined(__AVR__)
5959
Debug.print(DBG_INFO, F("WiFi.status(): %d"), WiFi.status());
6060
#endif
@@ -87,14 +87,14 @@ NetworkConnectionState WiFiConnectionHandler::update_handleInit()
8787
delay(300);
8888
WiFi.begin(_ssid, _pass);
8989
delay(1000);
90-
#endif /* ifndef BOARD_ESP8266 */
90+
#endif /* #if !defined(BOARD_ESP8266) && !defined(ESP32) */
9191

9292
return NetworkConnectionState::CONNECTING;
9393
}
9494

9595
NetworkConnectionState WiFiConnectionHandler::update_handleConnecting()
9696
{
97-
#ifndef BOARD_ESP8266
97+
#if !defined(BOARD_ESP8266) && !defined(ESP32)
9898
if (WiFi.status() != WL_CONNECTED)
9999
{
100100
WiFi.begin(_ssid, _pass);
@@ -114,7 +114,7 @@ NetworkConnectionState WiFiConnectionHandler::update_handleConnecting()
114114
#if !defined(__AVR__)
115115
Debug.print(DBG_INFO, F("Connected to \"%s\""), _ssid);
116116
#endif
117-
#ifdef BOARD_ESP8266
117+
#if defined(BOARD_ESP8266) || defined(ESP32)
118118
configTime(0, 0, "time.arduino.cc", "pool.ntp.org", "time.nist.gov");
119119
#endif
120120
return NetworkConnectionState::CONNECTED;
@@ -149,7 +149,7 @@ NetworkConnectionState WiFiConnectionHandler::update_handleDisconnecting()
149149

150150
NetworkConnectionState WiFiConnectionHandler::update_handleDisconnected()
151151
{
152-
#ifndef BOARD_ESP8266
152+
#if !defined(BOARD_ESP8266) && !defined(ESP32)
153153
WiFi.end();
154154
#endif /* ifndef BOARD_ESP8266 */
155155
if (_keep_alive)

0 commit comments

Comments
 (0)