Skip to content

Commit 7699c98

Browse files
committed
Improve Zigbee network startup
In some setup the initial network formation fails due interference which results in 'Not In Network' state. This commit will attempt to reconnect the network repeadedly. If the user requests to Leave the network the process is paused until Join is clicked again.
1 parent 30fad8f commit 7699c98

File tree

4 files changed

+42
-13
lines changed

4 files changed

+42
-13
lines changed

database.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,8 @@ static int sqliteLoadConfigCallback(void *user, int ncols, char **colval , char
963963
}
964964
else if (strcmp(colval[0], "rfconnect") == 0)
965965
{
966-
if (!val.isEmpty())
966+
// only reload from database if auto reconnect is disabled
967+
if (!val.isEmpty() && deCONZ::appArgumentNumeric("--auto-connect", 1) == 0)
967968
{
968969
int conn = val.toInt(&ok);
969970
if (ok && ((conn == 0) || (conn == 1)))

de_web_plugin.cpp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14152,6 +14152,12 @@ void DeRestPlugin::idleTimerFired()
1415214152

1415314153
if (!d->isInNetwork())
1415414154
{
14155+
// automatically try reconnect network
14156+
if (d->networkState == DeRestPluginPrivate::MaintainNetwork && d->gwRfConnectedExpected)
14157+
{
14158+
d->networkConnectedBefore = d->gwRfConnectedExpected;
14159+
d->startReconnectNetwork(RECONNECT_CHECK_DELAY);
14160+
}
1415514161
return;
1415614162
}
1415714163

@@ -16037,11 +16043,6 @@ void DeRestPluginPrivate::pollDatabaseWifiTimerFired()
1603716043

1603816044
void DeRestPluginPrivate::restartAppTimerFired()
1603916045
{
16040-
reconnectTimer = new QTimer(this);
16041-
reconnectTimer->setSingleShot(true);
16042-
connect(reconnectTimer, SIGNAL(timeout()),
16043-
this, SLOT(reconnectTimerFired()));
16044-
1604516046
// deCONZ will be restarted after reconnect
1604616047
genericDisconnectNetwork();
1604716048
}
@@ -16182,7 +16183,7 @@ void DeRestPluginPrivate::pollNextDevice()
1618216183
*/
1618316184
void DeRestPluginPrivate::genericDisconnectNetwork()
1618416185
{
16185-
DBG_Assert(apsCtrl != 0);
16186+
DBG_Assert(apsCtrl != nullptr);
1618616187

1618716188
if (!apsCtrl)
1618816189
{
@@ -16225,7 +16226,7 @@ void DeRestPluginPrivate::checkNetworkDisconnected()
1622516226
}
1622616227
else
1622716228
{
16228-
DBG_Assert(apsCtrl != 0);
16229+
DBG_Assert(apsCtrl != nullptr);
1622916230
if (apsCtrl)
1623016231
{
1623116232
DBG_Printf(DBG_INFO, "disconnect from network failed, try again\n");
@@ -16244,6 +16245,14 @@ void DeRestPluginPrivate::checkNetworkDisconnected()
1624416245
*/
1624516246
void DeRestPluginPrivate::startReconnectNetwork(int delay)
1624616247
{
16248+
if (!reconnectTimer)
16249+
{
16250+
reconnectTimer = new QTimer(this);
16251+
reconnectTimer->setSingleShot(true);
16252+
connect(reconnectTimer, SIGNAL(timeout()),
16253+
this, SLOT(reconnectTimerFired()));
16254+
}
16255+
1624716256
networkState = ReconnectNetwork;
1624816257
DBG_Printf(DBG_INFO_L2, "networkState: CC_ReconnectNetwork\n");
1624916258
networkReconnectAttempts = NETWORK_ATTEMPS;
@@ -16309,7 +16318,8 @@ void DeRestPluginPrivate::reconnectNetwork()
1630916318
}
1631016319
else
1631116320
{
16312-
DBG_Printf(DBG_INFO, "reconnect network failed\n");
16321+
DBG_Printf(DBG_INFO, "reconnect network failed, try later\n");
16322+
networkState = MaintainNetwork;
1631316323
}
1631416324
}
1631516325

de_web_plugin_private.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,7 @@ public Q_SLOTS:
10181018
void gpDataIndication(const deCONZ::GpDataIndication &ind);
10191019
void gpProcessButtonEvent(const deCONZ::GpDataIndication &ind);
10201020
void configurationChanged();
1021+
void networkStateChangeRequest(bool shouldConnect);
10211022
int taskCountForAddress(const deCONZ::Address &address);
10221023
void processTasks();
10231024
void processGroupTasks();
@@ -1614,14 +1615,15 @@ public Q_SLOTS:
16141615
uint8_t channelChangeApsRequestId;
16151616

16161617
// generic network reconnect state machine
1617-
enum networkReconnectState
1618+
enum NetworkReconnectState
16181619
{
16191620
DisconnectingNetwork,
1620-
ReconnectNetwork
1621+
ReconnectNetwork,
1622+
MaintainNetwork
16211623
};
16221624

1623-
QTimer *reconnectTimer;
1624-
networkReconnectState networkState;
1625+
QTimer *reconnectTimer = nullptr;
1626+
NetworkReconnectState networkState = MaintainNetwork;
16251627
int networkDisconnectAttempts;
16261628
int networkReconnectAttempts;
16271629
bool networkConnectedBefore;

rest_configuration.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,11 @@ void DeRestPluginPrivate::initConfig()
231231

232232
connect(deCONZ::ApsController::instance(), &deCONZ::ApsController::configurationChanged,
233233
this, &DeRestPluginPrivate::configurationChanged);
234+
235+
#if DECONZ_LIB_VERSION >= 0x010C00
236+
connect(deCONZ::ApsController::instance(), &deCONZ::ApsController::networkStateChangeRequest,
237+
this, &DeRestPluginPrivate::networkStateChangeRequest);
238+
#endif
234239
}
235240

236241
/*! Init timezone. */
@@ -554,6 +559,17 @@ void DeRestPluginPrivate::configurationChanged()
554559
}
555560
}
556561

562+
/*! Network state change request received from deCONZ core (e.g. Join/Leave clicked)
563+
*/
564+
void DeRestPluginPrivate::networkStateChangeRequest(bool shouldConnect)
565+
{
566+
if (gwRfConnectedExpected != shouldConnect)
567+
{
568+
gwRfConnectedExpected = shouldConnect;
569+
queSaveDb(DB_CONFIG, DB_SHORT_SAVE_DELAY);
570+
}
571+
}
572+
557573
/*! Configuration REST API broker.
558574
\param req - request data
559575
\param rsp - response data

0 commit comments

Comments
 (0)