Skip to content

Commit

Permalink
Merge pull request #355 from sivar2311/master
Browse files Browse the repository at this point in the history
Fix for #348
  • Loading branch information
sivar2311 authored Nov 30, 2023
2 parents 443cdd2 + f8b7b6f commit 7b097ae
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 10 deletions.
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# Changelog
## Version 3.0.1
Fixed:
- SinricPro.isConnected() still returns true if the connection was lost
- onDisconnectCallback does not fire if the connection is lost.

## Version 3.0.0
- BREAKING CHANGE: Remove PowerStateController from Air Quality, Contact, Motion and Temperature sensor.
- Fix examples
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"maintainer": true
}
],
"version": "3.0.0",
"version": "3.0.1",
"frameworks": "arduino",
"platforms": [
"espressif8266",
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=SinricPro
version=3.0.0
version=3.0.1
author=Boris Jaeger <sivar2311@gmail.com>
maintainer=Boris Jaeger <sivar2311@gmail.com>
sentence=Library for https://sinric.pro - simple way to connect your device to alexa
Expand Down
8 changes: 3 additions & 5 deletions src/SinricPro.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,9 @@ void SinricProClass::handle() {
return;
}

if (WiFi.isConnected()) {
if (!isConnected()) connect();
_websocketListener.handle();
_udpListener.handle();
}
if (!isConnected()) connect();
_websocketListener.handle();
_udpListener.handle();

handleReceiveQueue();
handleSendQueue();
Expand Down
2 changes: 1 addition & 1 deletion src/SinricProVersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Version Configuration
#define SINRICPRO_VERSION_MAJOR 3
#define SINRICPRO_VERSION_MINOR 0
#define SINRICPRO_VERSION_REVISION 0
#define SINRICPRO_VERSION_REVISION 1
#define SINRICPRO_VERSION STR(SINRICPRO_VERSION_MAJOR) "." STR(SINRICPRO_VERSION_MINOR) "." STR(SINRICPRO_VERSION_REVISION)
#define SINRICPRO_VERSION_STR "SinricPro (v" SINRICPRO_VERSION ")"
#define SINRICPRO_VERISON_INT SINRICPRO_VERSION_MAJOR * 1000000 + SINRICPRO_VERSION_MINOR * 1000 + SINRICPRO_VERSION_REVISION
16 changes: 14 additions & 2 deletions src/SinricProWebsocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
#include "SinricProQueue.h"
namespace SINRICPRO_NAMESPACE {

enum class ConnectionState {
disconnected,
connecting,
connected
};

#if !defined(WEBSOCKETS_VERSION_INT) || (WEBSOCKETS_VERSION_INT < 2003005)
#error "Wrong WebSockets Version! Minimum Version is 2.3.5!!!"
#endif
Expand Down Expand Up @@ -53,6 +59,7 @@ class WebsocketListener : protected WebSocketsClient {
protected:
bool _begin;
bool restoreDeviceStates;
ConnectionState connectionState;

wsConnectedCallback _wsConnectedCb;
wsDisconnectedCallback _wsDisconnectedCb;
Expand All @@ -69,6 +76,7 @@ class WebsocketListener : protected WebSocketsClient {
WebsocketListener::WebsocketListener()
: _begin(false)
, restoreDeviceStates(false)
, connectionState(ConnectionState::disconnected)
, _wsConnectedCb(nullptr)
, _wsDisconnectedCb(nullptr)
, _wsPongCb(nullptr) {}
Expand Down Expand Up @@ -105,6 +113,7 @@ void WebsocketListener::setExtraHeaders() {
void WebsocketListener::begin(String server, String appKey, String deviceIds, SinricProQueue_t* receiveQueue) {
if (_begin) return;
_begin = true;
connectionState = ConnectionState::connecting;

this->receiveQueue = receiveQueue;
this->appKey = appKey;
Expand Down Expand Up @@ -133,6 +142,7 @@ void WebsocketListener::handle() {
void WebsocketListener::stop() {
disconnect();
_begin = false;
connectionState = ConnectionState::disconnected;
}

void WebsocketListener::setRestoreDeviceStates(bool flag) {
Expand Down Expand Up @@ -161,8 +171,9 @@ void WebsocketListener::runCbEvent(WStype_t type, uint8_t* payload, size_t lengt
switch (type) {
case WStype_DISCONNECTED: {
DEBUG_SINRIC("[SinricPro:Websocket]: disconnected\r\n");
if (_wsDisconnectedCb) _wsDisconnectedCb();
}
if (connectionState == ConnectionState::connected && _wsDisconnectedCb) _wsDisconnectedCb();
connectionState = ConnectionState::disconnected;
}
break;

case WStype_CONNECTED:
Expand All @@ -172,6 +183,7 @@ void WebsocketListener::runCbEvent(WStype_t type, uint8_t* payload, size_t lengt
restoreDeviceStates = false;
setExtraHeaders();
}
connectionState = ConnectionState::connected;
break;

case WStype_TEXT: {
Expand Down

0 comments on commit 7b097ae

Please sign in to comment.