Skip to content

Commit

Permalink
Merge pull request #104 from sellensr/master
Browse files Browse the repository at this point in the history
Disconnect and ssid check
  • Loading branch information
brentru committed Jan 3, 2020
2 parents f7ecc16 + 58fd0c4 commit 512dc2e
Show file tree
Hide file tree
Showing 14 changed files with 349 additions and 149 deletions.
15 changes: 15 additions & 0 deletions src/AdafruitIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,21 @@ void AdafruitIO::connect()

}

/**************************************************************************/
/*!
@brief Disconnects from WiFi.
@return none
*/
/**************************************************************************/
void AdafruitIO::wifi_disconnect()
{

AIO_DEBUG_PRINTLN("AdafruitIO::wifi_disconnect()");

_disconnect();

}


/**************************************************************************/
/*!
Expand Down
2 changes: 2 additions & 0 deletions src/AdafruitIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class AdafruitIO {
virtual ~AdafruitIO();

void connect();
void wifi_disconnect();
aio_status_t run(uint16_t busywait_ms = 0, bool fail_fast = false);

AdafruitIO_Feed* feed(const char *name);
Expand All @@ -75,6 +76,7 @@ class AdafruitIO {

protected:
virtual void _connect() = 0;
virtual void _disconnect() = 0;
aio_status_t _status = AIO_IDLE;
uint32_t _last_ping = 0;
uint32_t _last_mqtt_connect = 0;
Expand Down
3 changes: 3 additions & 0 deletions src/AdafruitIO_Definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ class AdafruitIOGroupCallback {
#define AIO_MQTT_CONNECTION_TIMEOUT 60000
// Time to wait for a successful reconnection after network disconnect
#define AIO_NET_CONNECTION_TIMEOUT 60000
// Time to wait for a net disconnect to take effect
#define AIO_NET_DISCONNECT_WAIT 300

#define AIO_ERROR_TOPIC "/errors"
#define AIO_THROTTLE_TOPIC "/throttle"
Expand Down Expand Up @@ -105,6 +107,7 @@ typedef enum {
AIO_CONNECT_FAILED = 11, // Failed to connect to Adafruit IO
AIO_FINGERPRINT_INVALID = 12, // Unknown AIO_SSL_FINGERPRINT
AIO_AUTH_FAILED = 13, // Invalid Adafruit IO login credentials provided.
AIO_SSID_INVALID = 14, // SSID is "" or otherwise invalid, connection not attempted

// SUCCESS
AIO_NET_CONNECTED = 20, // Connected to Adafruit IO
Expand Down
50 changes: 34 additions & 16 deletions src/wifi/AdafruitIO_AIRLIFT.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,24 +158,42 @@ class AdafruitIO_AIRLIFT : public AdafruitIO {
/**************************************************************************/
void _connect()
{
// setup ESP32 pins
if (_ssPin != -1) {
WiFi.setPins(_ssPin, _ackPin, _rstPin, _gpio0Pin, _wifi);
if(strlen(_ssid) == 0) {
_status = AIO_SSID_INVALID;
} else {
_disconnect();
// setup ESP32 pins
if (_ssPin != -1) {
WiFi.setPins(_ssPin, _ackPin, _rstPin, _gpio0Pin, _wifi);
}

// check esp32 module version against NINAFWVER
firmwareCheck();

// check for esp32 module
if (WiFi.status() == WL_NO_MODULE)
{
AIO_DEBUG_PRINTLN("No ESP32 module detected!");
return;
}

WiFi.begin(_ssid, _pass);
_status = AIO_NET_DISCONNECTED;
}

// check esp32 module version against NINAFWVER
firmwareCheck();

// check for esp32 module
if (WiFi.status() == WL_NO_MODULE)
{
AIO_DEBUG_PRINTLN("No ESP32 module detected!");
return;
}

WiFi.begin(_ssid, _pass);
_status = AIO_NET_DISCONNECTED;
}

/**************************************************************************/
/*!
@brief Disconnect the wifi network.
@return none
*/
/**************************************************************************/
void _disconnect()
{
WiFi.disconnect();
delay(AIO_NET_DISCONNECT_WAIT);
}

};

#endif // ADAFRUITIO_AIRLIFT_H
48 changes: 33 additions & 15 deletions src/wifi/AdafruitIO_ESP32.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
//
// Adafruit invests time and resources providing this open source code.
// Please support Adafruit and open source hardware by purchasing
// products from Adafruit!
//
// Copyright (c) 2015-2016 Adafruit Industries
// Authors: Tony DiCola, Todd Treece
// Licensed under the MIT license.
//
// All text above must be included in any redistribution.
//
/*!
* @file AdafruitIO_ESP32.cpp
*
* Adafruit invests time and resources providing this open source code.
* Please support Adafruit and open source hardware by purchasing
* products from Adafruit!
*
* Copyright (c) 2015-2016 Adafruit Industries
* Authors: Tony DiCola, Todd Treece
* Licensed under the MIT license.
*
* All text above must be included in any redistribution.
*/
#ifdef ARDUINO_ARCH_ESP32

#include "AdafruitIO_ESP32.h"
Expand All @@ -32,12 +34,28 @@ AdafruitIO_ESP32::~AdafruitIO_ESP32()

void AdafruitIO_ESP32::_connect()
{
if(strlen(_ssid) == 0) {
_status = AIO_SSID_INVALID;
} else {
_disconnect();
delay(100);
WiFi.begin(_ssid, _pass);
delay(100);
_status = AIO_NET_DISCONNECTED;
}

delay(100);
WiFi.begin(_ssid, _pass);
delay(100);
_status = AIO_NET_DISCONNECTED;
}

/**************************************************************************/
/*!
@brief Disconnect the wifi network.
@return none
*/
/**************************************************************************/
void AdafruitIO_ESP32::_disconnect()
{
WiFi.disconnect();
delay(AIO_NET_DISCONNECT_WAIT);
}

aio_status_t AdafruitIO_ESP32::networkStatus()
Expand Down
26 changes: 15 additions & 11 deletions src/wifi/AdafruitIO_ESP32.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
//
// Adafruit invests time and resources providing this open source code.
// Please support Adafruit and open source hardware by purchasing
// products from Adafruit!
//
// Copyright (c) 2015-2016 Adafruit Industries
// Authors: Tony DiCola, Todd Treece
// Licensed under the MIT license.
//
// All text above must be included in any redistribution.
//
/*!
* @file AdafruitIO_ESP32.h
*
* Adafruit invests time and resources providing this open source code.
* Please support Adafruit and open source hardware by purchasing
* products from Adafruit!
*
* Copyright (c) 2015-2016 Adafruit Industries
* Authors: Tony DiCola, Todd Treece
* Licensed under the MIT license.
*
* All text above must be included in any redistribution.
*/

#ifndef ADAFRUITIO_ESP32_H
#define ADAFRUITIO_ESP32_H

Expand All @@ -32,6 +35,7 @@ class AdafruitIO_ESP32 : public AdafruitIO {

protected:
void _connect();
void _disconnect();

const char *_ssid;
const char *_pass;
Expand Down
49 changes: 34 additions & 15 deletions src/wifi/AdafruitIO_ESP8266.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
//
// Adafruit invests time and resources providing this open source code.
// Please support Adafruit and open source hardware by purchasing
// products from Adafruit!
//
// Copyright (c) 2015-2016 Adafruit Industries
// Authors: Tony DiCola, Todd Treece
// Licensed under the MIT license.
//
// All text above must be included in any redistribution.
//
/*!
* @file AdafruitIO_8266.cpp
*
* Adafruit invests time and resources providing this open source code.
* Please support Adafruit and open source hardware by purchasing
* products from Adafruit!
*
* Copyright (c) 2015-2016 Adafruit Industries
* Authors: Tony DiCola, Todd Treece
* Licensed under the MIT license.
*
* All text above must be included in any redistribution.
*/

#ifdef ESP8266

#include "AdafruitIO_ESP8266.h"
Expand All @@ -33,12 +36,28 @@ AdafruitIO_ESP8266::~AdafruitIO_ESP8266()

void AdafruitIO_ESP8266::_connect()
{
if(strlen(_ssid) == 0) {
_status = AIO_SSID_INVALID;
} else {
_disconnect();
delay(100);
WiFi.begin(_ssid, _pass);
delay(100);
_status = AIO_NET_DISCONNECTED;
}

delay(100);
WiFi.begin(_ssid, _pass);
delay(100);
_status = AIO_NET_DISCONNECTED;
}

/**************************************************************************/
/*!
@brief Disconnect the wifi network.
@return none
*/
/**************************************************************************/
void AdafruitIO_ESP8266::_disconnect()
{
WiFi.disconnect();
delay(AIO_NET_DISCONNECT_WAIT);
}

aio_status_t AdafruitIO_ESP8266::networkStatus()
Expand Down
26 changes: 15 additions & 11 deletions src/wifi/AdafruitIO_ESP8266.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
//
// Adafruit invests time and resources providing this open source code.
// Please support Adafruit and open source hardware by purchasing
// products from Adafruit!
//
// Copyright (c) 2015-2016 Adafruit Industries
// Authors: Tony DiCola, Todd Treece
// Licensed under the MIT license.
//
// All text above must be included in any redistribution.
//
/*!
* @file AdafruitIO_ESP8266.h
*
* Adafruit invests time and resources providing this open source code.
* Please support Adafruit and open source hardware by purchasing
* products from Adafruit!
*
* Copyright (c) 2015-2016 Adafruit Industries
* Authors: Tony DiCola, Todd Treece
* Licensed under the MIT license.
*
* All text above must be included in any redistribution.
*/

#ifndef ADAFRUITIO_ESP8266_H
#define ADAFRUITIO_ESP8266_H

Expand All @@ -32,6 +35,7 @@ class AdafruitIO_ESP8266 : public AdafruitIO {

protected:
void _connect();
void _disconnect();

const char *_ssid;
const char *_pass;
Expand Down
52 changes: 36 additions & 16 deletions src/wifi/AdafruitIO_MKR1000.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
//
// Adafruit invests time and resources providing this open source code.
// Please support Adafruit and open source hardware by purchasing
// products from Adafruit!
//
// Copyright (c) 2015-2016 Adafruit Industries
// Authors: Tony DiCola, Todd Treece
// Licensed under the MIT license.
//
// All text above must be included in any redistribution.
//
/*!
* @file AdafruitIO_MKR1000.cpp
*
* Adafruit invests time and resources providing this open source code.
* Please support Adafruit and open source hardware by purchasing
* products from Adafruit!
*
* Copyright (c) 2015-2016 Adafruit Industries
* Authors: Tony DiCola, Todd Treece
* Licensed under the MIT license.
*
* All text above must be included in any redistribution.
*/

#if defined(ARDUINO_SAMD_MKR1000)

#include "AdafruitIO_MKR1000.h"
Expand All @@ -32,14 +35,31 @@ AdafruitIO_MKR1000::~AdafruitIO_MKR1000()

void AdafruitIO_MKR1000::_connect()
{
if(strlen(_ssid) == 0) {
_status = AIO_SSID_INVALID;
} else {
// no shield? bail
if(WiFi.status() == WL_NO_SHIELD)
return;

// no shield? bail
if(WiFi.status() == WL_NO_SHIELD)
return;
_disconnect();

WiFi.begin(_ssid, _pass);
_status = AIO_NET_DISCONNECTED;
WiFi.begin(_ssid, _pass);
_status = AIO_NET_DISCONNECTED;
}

}

/**************************************************************************/
/*!
@brief Disconnect the wifi network.
@return none
*/
/**************************************************************************/
void AdafruitIO_MKR1000::_disconnect()
{
WiFi.disconnect();
delay(AIO_NET_DISCONNECT_WAIT);
}

aio_status_t AdafruitIO_MKR1000::networkStatus()
Expand Down

0 comments on commit 512dc2e

Please sign in to comment.