|
| 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 |
0 commit comments