updated disconnect detection
parent
e219b9a6d8
commit
f5927619b0
|
|
@ -43,12 +43,13 @@ nymea operation:
|
|||
notes:
|
||||
DECKO Garage Door opener requires a ~ 3.3 Volt zener diode in series of the connection between the Garadget and the DECKO
|
||||
Garadget manual indicates the range of mtt is 1000 to 12000 ms but testing on v1.24 shows it currently only accepts 5000 to 60000 ms (nymea will request other values but Garadget may reject)
|
||||
The plugin will show connected as soon as the Garadget connects to the broker.
|
||||
The plugin will detect if the device is commanded to change broker connection or topic name and therefore set state to disconnected.
|
||||
The plugin may take 1 minute to show disconnects (power down or breakage).
|
||||
|
||||
Issues: Garadget operating a DECKO garage door opener (may not be issue with other garage door openers)
|
||||
the Garadget can get confused on the correct relay actions to take if you hit "stop" and then either "open" or "close" when operating a DECKO
|
||||
It is best to be in direct view of the door if you hit "stop" (the plugin image will be halfway up) to be sure you know where the door will go next.
|
||||
This confusion is an issue of the Garadget device and not of nymea-plugin.
|
||||
|
||||
The plugin will show connected as soon as the Garadget connects to the broker.
|
||||
The plugin will detect if the device is commanded to change broker connection or topic name and therefore set state to disconnected.
|
||||
The plugin may take 1 minute to show disconnects (power down or breakage).
|
||||
If nymead reboots rapidly, Garadget may not detect and show disconnected. In this case You may need to push the reset button on the Garadget
|
||||
|
|
|
|||
|
|
@ -44,7 +44,6 @@ void IntegrationPluginGaradget::setupThing(ThingSetupInfo *info)
|
|||
|
||||
QString device = thing->paramValue(garadgetThingDeviceNameParamTypeId).toString();
|
||||
|
||||
qCDebug(dcGaradget) << "entered setupThing" << thing->paramValue(garadgetThingDeviceNameParamTypeId) ;
|
||||
MqttClient *client = nullptr;
|
||||
client = hardwareManager()->mqttProvider()->createInternalClient(thing->id().toString());
|
||||
m_mqttClients.insert(thing, client);
|
||||
|
|
@ -58,7 +57,6 @@ void IntegrationPluginGaradget::setupThing(ThingSetupInfo *info)
|
|||
connect(client, &MqttClient::publishReceived, this, &IntegrationPluginGaradget::publishReceived);
|
||||
// In case we're already connected, manually call subscribe now
|
||||
if (client->isConnected()) {
|
||||
qCDebug(dcGaradget) << "entered is Connected" << client;
|
||||
subscribe(thing);
|
||||
}
|
||||
}
|
||||
|
|
@ -68,18 +66,24 @@ void IntegrationPluginGaradget::postSetupThing(Thing *thing)
|
|||
{
|
||||
|
||||
if (!m_pluginTimer) {
|
||||
uint updatetime = 30;
|
||||
int updatetime = 30;
|
||||
int lwtupdatetime = 300 / updatetime;
|
||||
m_pluginTimer = hardwareManager()->pluginTimerManager()->registerTimer(updatetime);
|
||||
connect(m_pluginTimer, &PluginTimer::timeout, this, [=](){
|
||||
m_statuscounter[thing] += 1;
|
||||
foreach (Thing *thing, myThings()) {
|
||||
if ((m_lastActivityTimeStamps[thing].msecsTo(QDateTime::currentDateTime()) > 1000 * updatetime) && (thing->stateValue(garadgetConnectedStateTypeId).toBool() == true)) {
|
||||
qCDebug(dcGaradget) << "disconnect garadget";
|
||||
if ((m_lastActivityTimeStamps[thing].msecsTo(QDateTime::currentDateTime()) > 2000 * updatetime) && (thing->stateValue(garadgetConnectedStateTypeId).toBool() == true)) {
|
||||
qCDebug(dcGaradget) << "disconnect device" << thing->paramValue(garadgetThingDeviceNameParamTypeId).toString();
|
||||
thing->setStateValue(garadgetConnectedStateTypeId, false);
|
||||
}
|
||||
if (thing->stateValue(garadgetConnectedStateTypeId).toBool() == true) {
|
||||
if ( (thing->stateValue(garadgetConnectedStateTypeId).toBool() == true) || m_statuscounter[thing] > lwtupdatetime) {
|
||||
m_mqttClients.value(thing)->publish("garadget/" + thing->paramValue(garadgetThingDeviceNameParamTypeId).toString() + "/command", "get-status");
|
||||
}
|
||||
}
|
||||
if (m_statuscounter[thing] > lwtupdatetime) {
|
||||
qCDebug(dcGaradget) << "reset statusCounter" << m_statuscounter;
|
||||
m_statuscounter[thing] = 1;
|
||||
}
|
||||
});
|
||||
connect(thing, &Thing::settingChanged, this, [=](const ParamTypeId &settingTypeId, const QVariant &value){
|
||||
foreach (Thing *thing, myThings()) {
|
||||
|
|
@ -104,7 +108,7 @@ void IntegrationPluginGaradget::postSetupThing(Thing *thing)
|
|||
|
||||
void IntegrationPluginGaradget::thingRemoved(Thing *thing)
|
||||
{
|
||||
qCDebug(dcGaradget) << thing << "Removed";
|
||||
qCDebug(dcGaradget) << "device " << thing->paramValue(garadgetThingDeviceNameParamTypeId).toString() << "Removed";
|
||||
m_mqttClients.take(thing)->deleteLater();
|
||||
if (m_pluginTimer && myThings().isEmpty()) {
|
||||
hardwareManager()->pluginTimerManager()->unregisterTimer(m_pluginTimer);
|
||||
|
|
@ -167,7 +171,6 @@ void IntegrationPluginGaradget::executeAction(ThingActionInfo *info)
|
|||
}
|
||||
}
|
||||
if (conftype != "") {
|
||||
qCDebug(dcGaradget) << "Processing config change" << conftype << "to" << action.paramValue( garadgetSrtActionSrtParamTypeId).toInt();
|
||||
name = name + "/set-config";
|
||||
QJsonObject garadgetobj;
|
||||
garadgetobj.insert(conftype, actint);
|
||||
|
|
@ -202,9 +205,6 @@ void IntegrationPluginGaradget::subscribe(Thing *thing)
|
|||
|
||||
void IntegrationPluginGaradget::publishReceived(const QString &topic, const QByteArray &payload, bool retained)
|
||||
{
|
||||
// qCDebug(dcGaradget) << "Received message from topic" << topic << "with msg" << payload << "retain flag" << retained;
|
||||
|
||||
|
||||
MqttClient* client = static_cast<MqttClient*>(sender());
|
||||
Thing *thing = m_mqttClients.key(client);
|
||||
if (!thing) {
|
||||
|
|
@ -213,7 +213,7 @@ void IntegrationPluginGaradget::publishReceived(const QString &topic, const QByt
|
|||
}
|
||||
if (topic.endsWith("/status")) {
|
||||
if (thing->stateValue(garadgetConnectedStateTypeId) == false) {
|
||||
qCDebug(dcGaradget) << "Setting Garadget to connected" ;
|
||||
qCDebug(dcGaradget) << "Setting" << thing->paramValue(garadgetThingDeviceNameParamTypeId).toString() << "to connected" ;
|
||||
thing->setStateValue(garadgetConnectedStateTypeId, true);
|
||||
}
|
||||
m_lastActivityTimeStamps[thing] = QDateTime::currentDateTime();
|
||||
|
|
@ -229,7 +229,7 @@ void IntegrationPluginGaradget::publishReceived(const QString &topic, const QByt
|
|||
thing->setStateValue(garadgetBrightlevelStateTypeId, jo.value(QString("bright")).toInt());
|
||||
if (jo.value(QString("status")).toString().contains(QString("stopped"))) {
|
||||
thing->setStateValue(garadgetStateStateTypeId, "intermediate");
|
||||
qCDebug(dcGaradget) << "Garadget is" << jo.value(QString("status")).toString() ;
|
||||
qCDebug(dcGaradget) << thing->paramValue(garadgetThingDeviceNameParamTypeId).toString() << "is" << jo.value(QString("status")).toString() ;
|
||||
} else {
|
||||
thing->setStateValue(garadgetStateStateTypeId, jo.value(QString("status")).toString());
|
||||
}
|
||||
|
|
@ -247,12 +247,12 @@ void IntegrationPluginGaradget::publishReceived(const QString &topic, const QByt
|
|||
thing->setStateValue(garadgetMttStateTypeId,jo.value(QString("mtt")).toInt());
|
||||
thing->setSettingValue(garadgetSettingsRdtParamTypeId,jo.value(QString("rdt")).toInt());
|
||||
thing->setSettingValue(garadgetSettingsRlpParamTypeId,jo.value(QString("rlp")).toInt());
|
||||
qCDebug(dcGaradget) << "System Configuration" << "srt =" << thing->stateValue(garadgetSrtStateTypeId).toInt() << "rlt =" << thing->stateValue(garadgetRltStateTypeId).toInt()<< "mtt =" << thing->stateValue(garadgetMttStateTypeId).toInt() << "rdt =" << thing->setting(garadgetSettingsRdtParamTypeId).toUInt() << "rlp =" << thing->setting(garadgetSettingsRlpParamTypeId).toUInt();
|
||||
qCDebug(dcGaradget) << thing->paramValue(garadgetThingDeviceNameParamTypeId).toString() << "System Configuration" << "srt =" << thing->stateValue(garadgetSrtStateTypeId).toInt() << "rlt =" << thing->stateValue(garadgetRltStateTypeId).toInt()<< "mtt =" << thing->stateValue(garadgetMttStateTypeId).toInt() << "rdt =" << thing->setting(garadgetSettingsRdtParamTypeId).toUInt() << "rlp =" << thing->setting(garadgetSettingsRlpParamTypeId).toUInt();
|
||||
}
|
||||
if (topic.endsWith("/set-config")){
|
||||
if ( (payload.contains("mqip")) or (payload.contains("mqpt")) or (payload.contains("nme")) ) {
|
||||
thing->setStateValue(garadgetConnectedStateTypeId, false);
|
||||
qCDebug(dcGaradget) << "Detected change of Broker msg - set connected to false";
|
||||
qCDebug(dcGaradget) << thing->paramValue(garadgetThingDeviceNameParamTypeId).toString() << "Detected change of Broker msg - set connected to false";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@
|
|||
class MqttClient;
|
||||
|
||||
class IntegrationPluginGaradget: public IntegrationPlugin
|
||||
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
|
@ -63,7 +64,7 @@ private:
|
|||
QHash<Thing*, MqttClient*> m_mqttClients;
|
||||
PluginTimer *m_pluginTimer = nullptr;
|
||||
QHash<Thing*, QDateTime> m_lastActivityTimeStamps;
|
||||
|
||||
QHash<Thing*, int> m_statuscounter;
|
||||
|
||||
private slots:
|
||||
void subscribe(Thing *thing);
|
||||
|
|
|
|||
Loading…
Reference in New Issue