Skip to content

Commit 7b097ae

Browse files
authored
Merge pull request #355 from sivar2311/master
Fix for #348
2 parents 443cdd2 + f8b7b6f commit 7b097ae

File tree

6 files changed

+25
-10
lines changed

6 files changed

+25
-10
lines changed

changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
# Changelog
2+
## Version 3.0.1
3+
Fixed:
4+
- SinricPro.isConnected() still returns true if the connection was lost
5+
- onDisconnectCallback does not fire if the connection is lost.
6+
27
## Version 3.0.0
38
- BREAKING CHANGE: Remove PowerStateController from Air Quality, Contact, Motion and Temperature sensor.
49
- Fix examples

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"maintainer": true
1414
}
1515
],
16-
"version": "3.0.0",
16+
"version": "3.0.1",
1717
"frameworks": "arduino",
1818
"platforms": [
1919
"espressif8266",

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=SinricPro
2-
version=3.0.0
2+
version=3.0.1
33
author=Boris Jaeger <[email protected]>
44
maintainer=Boris Jaeger <[email protected]>
55
sentence=Library for https://sinric.pro - simple way to connect your device to alexa

src/SinricPro.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,11 +243,9 @@ void SinricProClass::handle() {
243243
return;
244244
}
245245

246-
if (WiFi.isConnected()) {
247-
if (!isConnected()) connect();
248-
_websocketListener.handle();
249-
_udpListener.handle();
250-
}
246+
if (!isConnected()) connect();
247+
_websocketListener.handle();
248+
_udpListener.handle();
251249

252250
handleReceiveQueue();
253251
handleSendQueue();

src/SinricProVersion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// Version Configuration
77
#define SINRICPRO_VERSION_MAJOR 3
88
#define SINRICPRO_VERSION_MINOR 0
9-
#define SINRICPRO_VERSION_REVISION 0
9+
#define SINRICPRO_VERSION_REVISION 1
1010
#define SINRICPRO_VERSION STR(SINRICPRO_VERSION_MAJOR) "." STR(SINRICPRO_VERSION_MINOR) "." STR(SINRICPRO_VERSION_REVISION)
1111
#define SINRICPRO_VERSION_STR "SinricPro (v" SINRICPRO_VERSION ")"
1212
#define SINRICPRO_VERISON_INT SINRICPRO_VERSION_MAJOR * 1000000 + SINRICPRO_VERSION_MINOR * 1000 + SINRICPRO_VERSION_REVISION

src/SinricProWebsocket.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
#include "SinricProQueue.h"
2424
namespace SINRICPRO_NAMESPACE {
2525

26+
enum class ConnectionState {
27+
disconnected,
28+
connecting,
29+
connected
30+
};
31+
2632
#if !defined(WEBSOCKETS_VERSION_INT) || (WEBSOCKETS_VERSION_INT < 2003005)
2733
#error "Wrong WebSockets Version! Minimum Version is 2.3.5!!!"
2834
#endif
@@ -53,6 +59,7 @@ class WebsocketListener : protected WebSocketsClient {
5359
protected:
5460
bool _begin;
5561
bool restoreDeviceStates;
62+
ConnectionState connectionState;
5663

5764
wsConnectedCallback _wsConnectedCb;
5865
wsDisconnectedCallback _wsDisconnectedCb;
@@ -69,6 +76,7 @@ class WebsocketListener : protected WebSocketsClient {
6976
WebsocketListener::WebsocketListener()
7077
: _begin(false)
7178
, restoreDeviceStates(false)
79+
, connectionState(ConnectionState::disconnected)
7280
, _wsConnectedCb(nullptr)
7381
, _wsDisconnectedCb(nullptr)
7482
, _wsPongCb(nullptr) {}
@@ -105,6 +113,7 @@ void WebsocketListener::setExtraHeaders() {
105113
void WebsocketListener::begin(String server, String appKey, String deviceIds, SinricProQueue_t* receiveQueue) {
106114
if (_begin) return;
107115
_begin = true;
116+
connectionState = ConnectionState::connecting;
108117

109118
this->receiveQueue = receiveQueue;
110119
this->appKey = appKey;
@@ -133,6 +142,7 @@ void WebsocketListener::handle() {
133142
void WebsocketListener::stop() {
134143
disconnect();
135144
_begin = false;
145+
connectionState = ConnectionState::disconnected;
136146
}
137147

138148
void WebsocketListener::setRestoreDeviceStates(bool flag) {
@@ -161,8 +171,9 @@ void WebsocketListener::runCbEvent(WStype_t type, uint8_t* payload, size_t lengt
161171
switch (type) {
162172
case WStype_DISCONNECTED: {
163173
DEBUG_SINRIC("[SinricPro:Websocket]: disconnected\r\n");
164-
if (_wsDisconnectedCb) _wsDisconnectedCb();
165-
}
174+
if (connectionState == ConnectionState::connected && _wsDisconnectedCb) _wsDisconnectedCb();
175+
connectionState = ConnectionState::disconnected;
176+
}
166177
break;
167178

168179
case WStype_CONNECTED:
@@ -172,6 +183,7 @@ void WebsocketListener::runCbEvent(WStype_t type, uint8_t* payload, size_t lengt
172183
restoreDeviceStates = false;
173184
setExtraHeaders();
174185
}
186+
connectionState = ConnectionState::connected;
175187
break;
176188

177189
case WStype_TEXT: {

0 commit comments

Comments
 (0)