From fb4c09337d426ec60d4c8e078938737d2c352a73 Mon Sep 17 00:00:00 2001 From: "bernhard.trinnes" Date: Wed, 19 Aug 2020 17:27:41 +0200 Subject: [PATCH 1/8] added w1 support for temperature sensors --- onewire/integrationpluginonewire.cpp | 164 +++++++++++++++++---------- onewire/integrationpluginonewire.h | 8 +- onewire/onewire.pro | 7 +- onewire/{onewire.cpp => owfs.cpp} | 39 ++++--- onewire/{onewire.h => owfs.h} | 18 +-- onewire/w1.cpp | 91 +++++++++++++++ onewire/w1.h | 57 ++++++++++ 7 files changed, 291 insertions(+), 93 deletions(-) rename onewire/{onewire.cpp => owfs.cpp} (87%) rename onewire/{onewire.h => owfs.h} (91%) create mode 100644 onewire/w1.cpp create mode 100644 onewire/w1.h diff --git a/onewire/integrationpluginonewire.cpp b/onewire/integrationpluginonewire.cpp index aa355b1d..e10ed33a 100644 --- a/onewire/integrationpluginonewire.cpp +++ b/onewire/integrationpluginonewire.cpp @@ -43,17 +43,55 @@ void IntegrationPluginOneWire::discoverThings(ThingDiscoveryInfo *info) { ThingClassId deviceClassId = info->thingClassId(); + if (!m_w1Interface) { + m_w1Interface = new W1(this); + } + if (deviceClassId == temperatureSensorThingClassId || deviceClassId == singleChannelSwitchThingClassId || deviceClassId == dualChannelSwitchThingClassId || deviceClassId == eightChannelSwitchThingClassId) { if (myThings().filterByThingClassId(oneWireInterfaceThingClassId).isEmpty()) { - //No one wire interface intitialized - //: Error discovering one wire devices - return info->finish(Thing::ThingErrorHardwareNotAvailable, QT_TR_NOOP("No one wire interface initialized. Please set up a one wire interface first.")); + if (!m_w1Interface->interfaceIsAvailable()) { + return info->finish(Thing::ThingErrorHardwareNotAvailable, QT_TR_NOOP("No one wire interface initialized. Please set up a one wire interface first.")); + } + QStringList deviceList = m_w1Interface->discoverDevices(); + + Q_FOREACH(QString device, deviceList) { + if (device.startsWith("10") || + device.startsWith("22") || + device.startsWith("28") || + device.startsWith("3B", Qt::CaseInsensitive)) { + + QString type = "Unkown"; + if (device.startsWith("10")) { // + type = "DS18S20"; + } else if (device.startsWith("22")) { // + type = "DS1822"; + } else if (device.startsWith("28")) { // + type = "DS18B20"; + } else if (device.startsWith("3B", Qt::CaseInsensitive)) { //DS1825 + type = "DS1825"; + } + ThingDescriptor descriptor(temperatureSensorThingClassId, type, "One wire temperature sensor"); + ParamList params; + params.append(Param(temperatureSensorThingAddressParamTypeId, device)); + params.append(Param(temperatureSensorThingTypeParamTypeId, type)); + foreach (Thing *existingThing, myThings().filterByThingClassId(temperatureSensorThingClassId)){ + if (existingThing->paramValue(temperatureSensorThingAddressParamTypeId).toString() == device) { + descriptor.setThingId(existingThing->id()); + break; + } + } + descriptor.setParams(params); + info->addThingDescriptor(descriptor); + } + } + return info->finish(Thing::ThingErrorNoError); } + foreach(Thing *parentDevice, myThings().filterByThingClassId(oneWireInterfaceThingClassId)) { if (parentDevice->stateValue(oneWireInterfaceAutoAddStateTypeId).toBool()) { //devices cannot be discovered since auto mode is enabled @@ -64,18 +102,18 @@ void IntegrationPluginOneWire::discoverThings(ThingDiscoveryInfo *info) m_runningDiscoveries.remove(parentDevice); }); - if (m_oneWireInterface) - m_oneWireInterface->discoverDevices(); + if (m_owfsInterface) + m_owfsInterface->discoverDevices(); } if (m_runningDiscoveries.isEmpty()) { info->finish(Thing::ThingErrorNoError, QT_TR_NOOP("All configured one wire interfaces are set up to automatically add new devices.")); } return; + } else { + qCWarning(dcOneWire()) << "Discovery called for a deviceclass which does not support discovery? Device class ID:" << info->thingClassId().toString(); + info->finish(Thing::ThingErrorThingClassNotFound); } - - qCWarning(dcOneWire()) << "Discovery called for a deviceclass which does not support discovery? Device class ID:" << info->thingClassId().toString(); - info->finish(Thing::ThingErrorThingClassNotFound); } @@ -85,65 +123,71 @@ void IntegrationPluginOneWire::setupThing(ThingSetupInfo *info) if (thing->thingClassId() == oneWireInterfaceThingClassId) { qCDebug(dcOneWire) << "Setup one wire interface"; - if (m_oneWireInterface) { + if (m_owfsInterface) { qCWarning(dcOneWire) << "One wire interface already set up"; //: Error setting up thing return info->finish(Thing::ThingErrorThingInUse, QT_TR_NOOP("There can only be one one wire interface per system.")); } - m_oneWireInterface = new OneWire(this); + m_owfsInterface = new Owfs(this); QByteArray initArguments = thing->paramValue(oneWireInterfaceThingInitArgsParamTypeId).toByteArray(); - if (!m_oneWireInterface->init(initArguments)){ - m_oneWireInterface->deleteLater(); - m_oneWireInterface = nullptr; + if (!m_owfsInterface->init(initArguments)){ + m_owfsInterface->deleteLater(); + m_owfsInterface = nullptr; //: Error setting up thing return info->finish(Thing::ThingErrorHardwareFailure, QT_TR_NOOP("Error initializing one wire interface.")); } - connect(m_oneWireInterface, &OneWire::devicesDiscovered, this, &IntegrationPluginOneWire::onOneWireDevicesDiscovered); + connect(m_owfsInterface, &Owfs::devicesDiscovered, this, &IntegrationPluginOneWire::onOneWireDevicesDiscovered); return info->finish(Thing::ThingErrorNoError); } if (thing->thingClassId() == temperatureSensorThingClassId) { qCDebug(dcOneWire) << "Setup one wire temperature sensor" << thing->params(); - if (!m_oneWireInterface) { //in case the child was setup before the interface - double temperature = m_oneWireInterface->getTemperature(thing->paramValue(temperatureSensorThingAddressParamTypeId).toByteArray()); + if (m_owfsInterface) { //in case the child was setup before the interface + double temperature = m_owfsInterface->getTemperature(thing->paramValue(temperatureSensorThingAddressParamTypeId).toByteArray()); thing->setStateValue(temperatureSensorTemperatureStateTypeId, temperature); + return info->finish(Thing::ThingErrorNoError); + } else if (m_w1Interface) { + double temperature = m_w1Interface->getTemperature(thing->paramValue(temperatureSensorThingAddressParamTypeId).toByteArray()); + thing->setStateValue(temperatureSensorTemperatureStateTypeId, temperature); + return info->finish(Thing::ThingErrorNoError); + } else { + return info->finish(Thing::ThingErrorHardwareNotAvailable, tr("No 1-Wire interface available")); } - return info->finish(Thing::ThingErrorNoError); } if (thing->thingClassId() == singleChannelSwitchThingClassId) { qCDebug(dcOneWire) << "Setup one wire switch" << thing->params(); - if (!m_oneWireInterface) { + if (!m_owfsInterface) { QByteArray address = thing->paramValue(singleChannelSwitchThingAddressParamTypeId).toByteArray(); - thing->setStateValue(singleChannelSwitchDigitalOutputStateTypeId, m_oneWireInterface->getSwitchOutput(address, OneWire::SwitchChannel::PIO_A)); + thing->setStateValue(singleChannelSwitchDigitalOutputStateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_A)); } return info->finish(Thing::ThingErrorNoError); } if (thing->thingClassId() == dualChannelSwitchThingClassId) { qCDebug(dcOneWire) << "Setup one wire dual switch" << thing->params(); - if (!m_oneWireInterface) { + if (!m_owfsInterface) { QByteArray address = thing->paramValue(dualChannelSwitchThingAddressParamTypeId).toByteArray(); - thing->setStateValue(dualChannelSwitchDigitalOutput1StateTypeId, m_oneWireInterface->getSwitchOutput(address, OneWire::SwitchChannel::PIO_A)); - thing->setStateValue(dualChannelSwitchDigitalOutput2StateTypeId, m_oneWireInterface->getSwitchOutput(address, OneWire::SwitchChannel::PIO_B)); + thing->setStateValue(dualChannelSwitchDigitalOutput1StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_A)); + thing->setStateValue(dualChannelSwitchDigitalOutput2StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_B)); } return info->finish(Thing::ThingErrorNoError); } if (thing->thingClassId() == eightChannelSwitchThingClassId) { qCDebug(dcOneWire) << "Setup one wire eight channel switch" << thing->params(); - if (!m_oneWireInterface) { + if (!m_owfsInterface) { QByteArray address = thing->paramValue(eightChannelSwitchThingAddressParamTypeId).toByteArray(); - thing->setStateValue(eightChannelSwitchDigitalOutput1StateTypeId, m_oneWireInterface->getSwitchOutput(address, OneWire::SwitchChannel::PIO_A)); - thing->setStateValue(eightChannelSwitchDigitalOutput2StateTypeId, m_oneWireInterface->getSwitchOutput(address, OneWire::SwitchChannel::PIO_B)); - thing->setStateValue(eightChannelSwitchDigitalOutput3StateTypeId, m_oneWireInterface->getSwitchOutput(address, OneWire::SwitchChannel::PIO_C)); - thing->setStateValue(eightChannelSwitchDigitalOutput4StateTypeId, m_oneWireInterface->getSwitchOutput(address, OneWire::SwitchChannel::PIO_D)); - thing->setStateValue(eightChannelSwitchDigitalOutput5StateTypeId, m_oneWireInterface->getSwitchOutput(address, OneWire::SwitchChannel::PIO_E)); - thing->setStateValue(eightChannelSwitchDigitalOutput6StateTypeId, m_oneWireInterface->getSwitchOutput(address, OneWire::SwitchChannel::PIO_F)); - thing->setStateValue(eightChannelSwitchDigitalOutput7StateTypeId, m_oneWireInterface->getSwitchOutput(address, OneWire::SwitchChannel::PIO_G)); - thing->setStateValue(eightChannelSwitchDigitalOutput8StateTypeId, m_oneWireInterface->getSwitchOutput(address, OneWire::SwitchChannel::PIO_H)); + thing->setStateValue(eightChannelSwitchDigitalOutput1StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_A)); + thing->setStateValue(eightChannelSwitchDigitalOutput2StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_B)); + thing->setStateValue(eightChannelSwitchDigitalOutput3StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_C)); + thing->setStateValue(eightChannelSwitchDigitalOutput4StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_D)); + thing->setStateValue(eightChannelSwitchDigitalOutput5StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_E)); + thing->setStateValue(eightChannelSwitchDigitalOutput6StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_F)); + thing->setStateValue(eightChannelSwitchDigitalOutput7StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_G)); + thing->setStateValue(eightChannelSwitchDigitalOutput8StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_H)); } return info->finish(Thing::ThingErrorNoError); } @@ -175,7 +219,7 @@ void IntegrationPluginOneWire::executeAction(ThingActionInfo *info) if (thing->thingClassId() == singleChannelSwitchThingClassId) { if (action.actionTypeId() == singleChannelSwitchDigitalOutputActionTypeId){ - m_oneWireInterface->setSwitchOutput(thing->paramValue(singleChannelSwitchThingAddressParamTypeId).toByteArray(), OneWire::SwitchChannel::PIO_A, action.param(singleChannelSwitchDigitalOutputActionDigitalOutputParamTypeId).value().toBool()); + m_owfsInterface->setSwitchOutput(thing->paramValue(singleChannelSwitchThingAddressParamTypeId).toByteArray(), Owfs::SwitchChannel::PIO_A, action.param(singleChannelSwitchDigitalOutputActionDigitalOutputParamTypeId).value().toBool()); return info->finish(Thing::ThingErrorNoError); } @@ -184,11 +228,11 @@ void IntegrationPluginOneWire::executeAction(ThingActionInfo *info) if (thing->thingClassId() == dualChannelSwitchThingClassId) { if (action.actionTypeId() == dualChannelSwitchDigitalOutput1ActionTypeId){ - m_oneWireInterface->setSwitchOutput(thing->paramValue(dualChannelSwitchThingAddressParamTypeId).toByteArray(), OneWire::SwitchChannel::PIO_A, action.param(dualChannelSwitchDigitalOutput1ActionDigitalOutput1ParamTypeId).value().toBool()); + m_owfsInterface->setSwitchOutput(thing->paramValue(dualChannelSwitchThingAddressParamTypeId).toByteArray(), Owfs::SwitchChannel::PIO_A, action.param(dualChannelSwitchDigitalOutput1ActionDigitalOutput1ParamTypeId).value().toBool()); return info->finish(Thing::ThingErrorNoError); } if (action.actionTypeId() == dualChannelSwitchDigitalOutput2ActionTypeId){ - m_oneWireInterface->setSwitchOutput(thing->paramValue(dualChannelSwitchThingAddressParamTypeId).toByteArray(), OneWire::SwitchChannel::PIO_B, action.param(dualChannelSwitchDigitalOutput2ActionDigitalOutput2ParamTypeId).value().toBool()); + m_owfsInterface->setSwitchOutput(thing->paramValue(dualChannelSwitchThingAddressParamTypeId).toByteArray(), Owfs::SwitchChannel::PIO_B, action.param(dualChannelSwitchDigitalOutput2ActionDigitalOutput2ParamTypeId).value().toBool()); return info->finish(Thing::ThingErrorNoError); } return info->finish(Thing::ThingErrorActionTypeNotFound); @@ -196,35 +240,35 @@ void IntegrationPluginOneWire::executeAction(ThingActionInfo *info) if (thing->thingClassId() == eightChannelSwitchThingClassId) { if (action.actionTypeId() == eightChannelSwitchDigitalOutput1ActionTypeId){ - m_oneWireInterface->setSwitchOutput(thing->paramValue(eightChannelSwitchThingAddressParamTypeId).toByteArray(), OneWire::SwitchChannel::PIO_A, action.param(eightChannelSwitchDigitalOutput1ActionDigitalOutput1ParamTypeId).value().toBool()); + m_owfsInterface->setSwitchOutput(thing->paramValue(eightChannelSwitchThingAddressParamTypeId).toByteArray(), Owfs::SwitchChannel::PIO_A, action.param(eightChannelSwitchDigitalOutput1ActionDigitalOutput1ParamTypeId).value().toBool()); return info->finish(Thing::ThingErrorNoError); } if (action.actionTypeId() == eightChannelSwitchDigitalOutput2ActionTypeId){ - m_oneWireInterface->setSwitchOutput(thing->paramValue(eightChannelSwitchThingAddressParamTypeId).toByteArray(), OneWire::SwitchChannel::PIO_B, action.param(eightChannelSwitchDigitalOutput2ActionDigitalOutput2ParamTypeId).value().toBool()); + m_owfsInterface->setSwitchOutput(thing->paramValue(eightChannelSwitchThingAddressParamTypeId).toByteArray(), Owfs::SwitchChannel::PIO_B, action.param(eightChannelSwitchDigitalOutput2ActionDigitalOutput2ParamTypeId).value().toBool()); return info->finish(Thing::ThingErrorNoError); } if (action.actionTypeId() == eightChannelSwitchDigitalOutput3ActionTypeId){ - m_oneWireInterface->setSwitchOutput(thing->paramValue(eightChannelSwitchThingAddressParamTypeId).toByteArray(), OneWire::SwitchChannel::PIO_C, action.param(eightChannelSwitchDigitalOutput3ActionDigitalOutput3ParamTypeId).value().toBool()); + m_owfsInterface->setSwitchOutput(thing->paramValue(eightChannelSwitchThingAddressParamTypeId).toByteArray(), Owfs::SwitchChannel::PIO_C, action.param(eightChannelSwitchDigitalOutput3ActionDigitalOutput3ParamTypeId).value().toBool()); return info->finish(Thing::ThingErrorNoError); } if (action.actionTypeId() == eightChannelSwitchDigitalOutput4ActionTypeId){ - m_oneWireInterface->setSwitchOutput(thing->paramValue(eightChannelSwitchThingAddressParamTypeId).toByteArray(), OneWire::SwitchChannel::PIO_D, action.param(eightChannelSwitchDigitalOutput4ActionDigitalOutput4ParamTypeId).value().toBool()); + m_owfsInterface->setSwitchOutput(thing->paramValue(eightChannelSwitchThingAddressParamTypeId).toByteArray(), Owfs::SwitchChannel::PIO_D, action.param(eightChannelSwitchDigitalOutput4ActionDigitalOutput4ParamTypeId).value().toBool()); return info->finish(Thing::ThingErrorNoError); } if (action.actionTypeId() == eightChannelSwitchDigitalOutput5ActionTypeId){ - m_oneWireInterface->setSwitchOutput(thing->paramValue(eightChannelSwitchThingAddressParamTypeId).toByteArray(), OneWire::SwitchChannel::PIO_E, action.param(eightChannelSwitchDigitalOutput5ActionDigitalOutput5ParamTypeId).value().toBool()); + m_owfsInterface->setSwitchOutput(thing->paramValue(eightChannelSwitchThingAddressParamTypeId).toByteArray(), Owfs::SwitchChannel::PIO_E, action.param(eightChannelSwitchDigitalOutput5ActionDigitalOutput5ParamTypeId).value().toBool()); return info->finish(Thing::ThingErrorNoError); } if (action.actionTypeId() == eightChannelSwitchDigitalOutput6ActionTypeId){ - m_oneWireInterface->setSwitchOutput(thing->paramValue(eightChannelSwitchThingAddressParamTypeId).toByteArray(), OneWire::SwitchChannel::PIO_F, action.param(eightChannelSwitchDigitalOutput6ActionDigitalOutput6ParamTypeId).value().toBool()); + m_owfsInterface->setSwitchOutput(thing->paramValue(eightChannelSwitchThingAddressParamTypeId).toByteArray(), Owfs::SwitchChannel::PIO_F, action.param(eightChannelSwitchDigitalOutput6ActionDigitalOutput6ParamTypeId).value().toBool()); return info->finish(Thing::ThingErrorNoError); } if (action.actionTypeId() == eightChannelSwitchDigitalOutput7ActionTypeId){ - m_oneWireInterface->setSwitchOutput(thing->paramValue(eightChannelSwitchThingAddressParamTypeId).toByteArray(), OneWire::SwitchChannel::PIO_G, action.param(eightChannelSwitchDigitalOutput7ActionDigitalOutput7ParamTypeId).value().toBool()); + m_owfsInterface->setSwitchOutput(thing->paramValue(eightChannelSwitchThingAddressParamTypeId).toByteArray(), Owfs::SwitchChannel::PIO_G, action.param(eightChannelSwitchDigitalOutput7ActionDigitalOutput7ParamTypeId).value().toBool()); return info->finish(Thing::ThingErrorNoError); } if (action.actionTypeId() == eightChannelSwitchDigitalOutput8ActionTypeId){ - m_oneWireInterface->setSwitchOutput(thing->paramValue(eightChannelSwitchThingAddressParamTypeId).toByteArray(), OneWire::SwitchChannel::PIO_H, action.param(eightChannelSwitchDigitalOutput8ActionDigitalOutput8ParamTypeId).value().toBool()); + m_owfsInterface->setSwitchOutput(thing->paramValue(eightChannelSwitchThingAddressParamTypeId).toByteArray(), Owfs::SwitchChannel::PIO_H, action.param(eightChannelSwitchDigitalOutput8ActionDigitalOutput8ParamTypeId).value().toBool()); return info->finish(Thing::ThingErrorNoError); } return info->finish(Thing::ThingErrorActionTypeNotFound); @@ -236,8 +280,8 @@ void IntegrationPluginOneWire::executeAction(ThingActionInfo *info) void IntegrationPluginOneWire::thingRemoved(Thing *thing) { if (thing->thingClassId() == oneWireInterfaceThingClassId) { - m_oneWireInterface->deleteLater(); - m_oneWireInterface = nullptr; + m_owfsInterface->deleteLater(); + m_owfsInterface = nullptr; return; } @@ -252,52 +296,52 @@ void IntegrationPluginOneWire::onPluginTimer() { foreach (Thing *thing, myThings()) { if (thing->thingClassId() == oneWireInterfaceThingClassId) { - thing->setStateValue(oneWireInterfaceConnectedStateTypeId, m_oneWireInterface->interfaceIsAvailable()); + thing->setStateValue(oneWireInterfaceConnectedStateTypeId, m_owfsInterface->interfaceIsAvailable()); if (thing->stateValue(oneWireInterfaceAutoAddStateTypeId).toBool()) { - m_oneWireInterface->discoverDevices(); + m_owfsInterface->discoverDevices(); } } if (thing->thingClassId() == temperatureSensorThingClassId) { QByteArray address = thing->paramValue(temperatureSensorThingAddressParamTypeId).toByteArray(); - double temperature = m_oneWireInterface->getTemperature(address); + double temperature = m_owfsInterface->getTemperature(address); thing->setStateValue(temperatureSensorTemperatureStateTypeId, temperature); } if (thing->thingClassId() == singleChannelSwitchThingClassId) { QByteArray address = thing->paramValue(singleChannelSwitchThingAddressParamTypeId).toByteArray(); - thing->setStateValue(singleChannelSwitchDigitalOutputStateTypeId, m_oneWireInterface->getSwitchOutput(address, OneWire::SwitchChannel::PIO_A)); + thing->setStateValue(singleChannelSwitchDigitalOutputStateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_A)); } if (thing->thingClassId() == dualChannelSwitchThingClassId) { QByteArray address = thing->paramValue(dualChannelSwitchThingAddressParamTypeId).toByteArray(); - thing->setStateValue(dualChannelSwitchDigitalOutput1StateTypeId, m_oneWireInterface->getSwitchOutput(address, OneWire::SwitchChannel::PIO_A)); - thing->setStateValue(dualChannelSwitchDigitalOutput2StateTypeId, m_oneWireInterface->getSwitchOutput(address, OneWire::SwitchChannel::PIO_B)); + thing->setStateValue(dualChannelSwitchDigitalOutput1StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_A)); + thing->setStateValue(dualChannelSwitchDigitalOutput2StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_B)); } if (thing->thingClassId() == eightChannelSwitchThingClassId) { QByteArray address = thing->paramValue(eightChannelSwitchThingAddressParamTypeId).toByteArray(); - thing->setStateValue(eightChannelSwitchDigitalOutput1StateTypeId, m_oneWireInterface->getSwitchOutput(address, OneWire::SwitchChannel::PIO_A)); - thing->setStateValue(eightChannelSwitchDigitalOutput2StateTypeId, m_oneWireInterface->getSwitchOutput(address, OneWire::SwitchChannel::PIO_B)); - thing->setStateValue(eightChannelSwitchDigitalOutput3StateTypeId, m_oneWireInterface->getSwitchOutput(address, OneWire::SwitchChannel::PIO_C)); - thing->setStateValue(eightChannelSwitchDigitalOutput4StateTypeId, m_oneWireInterface->getSwitchOutput(address, OneWire::SwitchChannel::PIO_D)); - thing->setStateValue(eightChannelSwitchDigitalOutput5StateTypeId, m_oneWireInterface->getSwitchOutput(address, OneWire::SwitchChannel::PIO_E)); - thing->setStateValue(eightChannelSwitchDigitalOutput6StateTypeId, m_oneWireInterface->getSwitchOutput(address, OneWire::SwitchChannel::PIO_F)); - thing->setStateValue(eightChannelSwitchDigitalOutput7StateTypeId, m_oneWireInterface->getSwitchOutput(address, OneWire::SwitchChannel::PIO_G)); - thing->setStateValue(eightChannelSwitchDigitalOutput8StateTypeId, m_oneWireInterface->getSwitchOutput(address, OneWire::SwitchChannel::PIO_H)); + thing->setStateValue(eightChannelSwitchDigitalOutput1StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_A)); + thing->setStateValue(eightChannelSwitchDigitalOutput2StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_B)); + thing->setStateValue(eightChannelSwitchDigitalOutput3StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_C)); + thing->setStateValue(eightChannelSwitchDigitalOutput4StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_D)); + thing->setStateValue(eightChannelSwitchDigitalOutput5StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_E)); + thing->setStateValue(eightChannelSwitchDigitalOutput6StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_F)); + thing->setStateValue(eightChannelSwitchDigitalOutput7StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_G)); + thing->setStateValue(eightChannelSwitchDigitalOutput8StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_H)); } } } -void IntegrationPluginOneWire::onOneWireDevicesDiscovered(QList oneWireDevices) +void IntegrationPluginOneWire::onOneWireDevicesDiscovered(QList oneWireDevices) { foreach(Thing *parentDevice, myThings().filterByThingClassId(oneWireInterfaceThingClassId)) { bool autoDiscoverEnabled = parentDevice->stateValue(oneWireInterfaceAutoAddStateTypeId).toBool(); ThingDescriptors descriptors; - foreach (OneWire::OneWireDevice oneWireDevice, oneWireDevices){ + foreach (Owfs::OwfsDevice oneWireDevice, oneWireDevices){ switch (oneWireDevice.family) { //https://github.com/owfs/owfs-doc/wiki/1Wire-Device-List case 0x10: //DS18S20 diff --git a/onewire/integrationpluginonewire.h b/onewire/integrationpluginonewire.h index ebb50be3..6237bf31 100644 --- a/onewire/integrationpluginonewire.h +++ b/onewire/integrationpluginonewire.h @@ -33,7 +33,8 @@ #include "plugintimer.h" #include "integrations/integrationplugin.h" -#include "onewire.h" +#include "owfs.h" +#include "w1.h" #include @@ -54,13 +55,14 @@ public: private: PluginTimer *m_pluginTimer = nullptr; - OneWire *m_oneWireInterface = nullptr; + Owfs *m_owfsInterface = nullptr; + W1 *m_w1Interface = nullptr; QHash m_runningDiscoveries; private slots: void onPluginTimer(); - void onOneWireDevicesDiscovered(QList devices); + void onOneWireDevicesDiscovered(QList devices); }; #endif // INTEGRATIONPLUGINONEWIRE_H diff --git a/onewire/onewire.pro b/onewire/onewire.pro index 300254ac..8e786aba 100644 --- a/onewire/onewire.pro +++ b/onewire/onewire.pro @@ -8,10 +8,11 @@ LIBS += \ SOURCES += \ integrationpluginonewire.cpp \ - onewire.cpp \ + owfs.cpp \ + w1.cpp \ HEADERS += \ integrationpluginonewire.h \ - onewire.h \ - + owfs.h \ + w1.h \ diff --git a/onewire/onewire.cpp b/onewire/owfs.cpp similarity index 87% rename from onewire/onewire.cpp rename to onewire/owfs.cpp index c15a1342..739f82bb 100644 --- a/onewire/onewire.cpp +++ b/onewire/owfs.cpp @@ -28,21 +28,21 @@ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -#include "onewire.h" +#include "owfs.h" #include "extern-plugininfo.h" -OneWire::OneWire(QObject *parent) : +Owfs::Owfs(QObject *parent) : QObject(parent) { } -OneWire::~OneWire() +Owfs::~Owfs() { OW_finish(); } -bool OneWire::init(const QByteArray &owfsInitArguments) +bool Owfs::init(const QByteArray &owfsInitArguments) { //QByteArray initArguments; //Test OWFS arguments @@ -52,6 +52,9 @@ bool OneWire::init(const QByteArray &owfsInitArguments) //Test i2c //initArguments.append("--i2c=ALL:ALL"); + // W1 Kernel Module + //inifArguments.append("--w1"); + if (OW_init(owfsInitArguments) < 0) { qWarning(dcOneWire()) << "ERROR initialising one wire" << strerror(errno); return false; @@ -60,7 +63,7 @@ bool OneWire::init(const QByteArray &owfsInitArguments) return true; } -bool OneWire::discoverDevices() +bool Owfs::discoverDevices() { char *dirBuffer = nullptr; size_t dirLength ; @@ -75,7 +78,7 @@ bool OneWire::discoverDevices() dirMembers = QByteArray(dirBuffer, dirLength).split(','); free(dirBuffer); - QList oneWireDevices; + QList owfsDevices; foreach(QByteArray member, dirMembers) { /* Other system members: @@ -93,24 +96,24 @@ bool OneWire::discoverDevices() if (family != 0) { member.remove(member.indexOf('/'), 1); QByteArray type; - OneWireDevice thing; + OwfsDevice thing; thing.family = family; thing.address = member; thing.id = member.split('.').last(); thing.type = getValue(member, "type"); - oneWireDevices.append(thing); + owfsDevices.append(thing); } } - emit devicesDiscovered(oneWireDevices); + emit devicesDiscovered(owfsDevices); return true; } -bool OneWire::interfaceIsAvailable() +bool Owfs::interfaceIsAvailable() { return true; } -bool OneWire::isConnected(const QByteArray &address) +bool Owfs::isConnected(const QByteArray &address) { Q_UNUSED(address) QByteArray fullPath; @@ -125,7 +128,7 @@ bool OneWire::isConnected(const QByteArray &address) /* Takes a path and filename and prints the 1-wire value */ /* makes sure the bridging "/" in the path is correct */ /* watches for total length and free allocated space */ -QByteArray OneWire::getValue(const QByteArray &address, const QByteArray &type) +QByteArray Owfs::getValue(const QByteArray &address, const QByteArray &type) { char * getBuffer ; size_t getLength ; @@ -150,7 +153,7 @@ QByteArray OneWire::getValue(const QByteArray &address, const QByteArray &type) return value; } -void OneWire::setValue(const QByteArray &address, const QByteArray &type, const QByteArray &value) +void Owfs::setValue(const QByteArray &address, const QByteArray &type, const QByteArray &value) { Q_UNUSED(value) QByteArray devicePath; @@ -167,20 +170,20 @@ void OneWire::setValue(const QByteArray &address, const QByteArray &type, const } } -double OneWire::getTemperature(const QByteArray &address) +double Owfs::getTemperature(const QByteArray &address) { QByteArray temperature = getValue(address, "temperature"); qDebug(dcOneWire()) << "Temperature" << temperature << temperature.replace(',','.').toDouble(); return temperature.toDouble(); } -QByteArray OneWire::getType(const QByteArray &address) +QByteArray Owfs::getType(const QByteArray &address) { QByteArray type = getValue(address, "type"); return type; } -bool OneWire::getSwitchOutput(const QByteArray &address, SwitchChannel channel) +bool Owfs::getSwitchOutput(const QByteArray &address, SwitchChannel channel) { QByteArray c; c.append("PIO."); @@ -215,7 +218,7 @@ bool OneWire::getSwitchOutput(const QByteArray &address, SwitchChannel channel) return state.toInt(); } -bool OneWire::getSwitchInput(const QByteArray &address, SwitchChannel channel) +bool Owfs::getSwitchInput(const QByteArray &address, SwitchChannel channel) { QByteArray c; c.append("sensed."); @@ -250,7 +253,7 @@ bool OneWire::getSwitchInput(const QByteArray &address, SwitchChannel channel) return state.toInt(); } -void OneWire::setSwitchOutput(const QByteArray &address, SwitchChannel channel, bool state) +void Owfs::setSwitchOutput(const QByteArray &address, SwitchChannel channel, bool state) { QByteArray c; c.append("PIO."); diff --git a/onewire/onewire.h b/onewire/owfs.h similarity index 91% rename from onewire/onewire.h rename to onewire/owfs.h index 035d7daa..cc1ba129 100644 --- a/onewire/onewire.h +++ b/onewire/owfs.h @@ -28,18 +28,18 @@ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -#ifndef ONEWIRE_H -#define ONEWIRE_H +#ifndef OWFS_H +#define OWFS_H #include "owcapi.h" #include -class OneWire : public QObject +class Owfs : public QObject { Q_OBJECT public: - enum OneWireProperty { + enum OwfsProperty { Address, //The entire 64-bit unique ID Crc, //The 8-bit error correction Family, //The 8-bit family code @@ -59,15 +59,15 @@ public: PIO_H }; - struct OneWireDevice { + struct OwfsDevice { QByteArray address; int family; QByteArray id; QByteArray type; }; - explicit OneWire(QObject *parent = nullptr); - ~OneWire(); + explicit Owfs(QObject *parent = nullptr); + ~Owfs(); bool init(const QByteArray &owfsInitArguments); QByteArray getPath(); @@ -87,7 +87,7 @@ private: void setValue(const QByteArray &address, const QByteArray &deviceType, const QByteArray &value); signals: - void devicesDiscovered(QList devices); + void devicesDiscovered(QList devices); }; -#endif // ONEWIRE_H +#endif // OWFS_H diff --git a/onewire/w1.cpp b/onewire/w1.cpp new file mode 100644 index 00000000..3722e181 --- /dev/null +++ b/onewire/w1.cpp @@ -0,0 +1,91 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +* +* Copyright 2013 - 2020, nymea GmbH +* Contact: contact@nymea.io +* +* This file is part of nymea. +* This project including source code and documentation is protected by +* copyright law, and remains the property of nymea GmbH. All rights, including +* reproduction, publication, editing and translation, are reserved. The use of +* this project is subject to the terms of a license agreement to be concluded +* with nymea GmbH in accordance with the terms of use of nymea GmbH, available +* under https://nymea.io/license +* +* GNU Lesser General Public License Usage +* Alternatively, this project may be redistributed and/or modified under the +* terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; version 3. This project is distributed in the hope that +* it will be useful, but WITHOUT ANY WARRANTY; without even the implied +* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this project. If not, see . +* +* For any further details and any questions please contact us under +* contact@nymea.io or see our FAQ/Licensing Information on +* https://nymea.io/license/faq +* +* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#include "w1.h" +#include "extern-plugininfo.h" + +W1::W1(QObject *parent) : + QObject(parent) +{ + +} + +QStringList W1::discoverDevices() +{ + QStringList deviceList; + + QDir w1SysFSDir("/sys/bus/w1/devices/"); + if (!w1SysFSDir.exists()) { + qCDebug(dcOneWire()) << "W1 kernel not loaded"; + return deviceList; + } + w1SysFSDir.setFilter(QDir::Dirs | QDir::NoSymLinks); + w1SysFSDir.setSorting(QDir::Name); + + QFileInfoList list = w1SysFSDir.entryInfoList(); + for (int i = 0; i < list.size(); ++i) { + QFileInfo fileInfo = list.at(i); + qCDebug(dcOneWire()) << "Found W1 bus master" << fileInfo.fileName() << fileInfo.filePath(); + m_w1BusMasters.append(QDir(fileInfo.filePath())); + } + + Q_FOREACH(QDir busMaster, m_w1BusMasters) { + busMaster.setFilter(QDir::Dirs | QDir::NoSymLinks); + busMaster.setSorting(QDir::Name); + QFileInfoList list = busMaster.entryInfoList(); + for (int i = 0; i < list.size(); ++i) { + QFileInfo fileInfo = list.at(i); + deviceList.append(fileInfo.fileName()); + } + + } + return deviceList; +} + +bool W1::interfaceIsAvailable() +{ + QDir w1SysFSDir("/sys/bus/w1/devices/"); + return w1SysFSDir.exists(); +} + +double W1::getTemperature(const QString &address) +{ + Q_FOREACH(QDir busMaster, m_w1BusMasters) { + QDir temperatureSensor(busMaster.dirName()+address); + if (temperatureSensor.exists()) { + qCDebug(dcOneWire()) << "Temperature" << address; + QFile temperature(temperatureSensor.dirName()+"/temperature"); + if (!temperature.open(QIODevice::ReadOnly | QIODevice::Text)) + return 0; + return temperature.readLine().toInt()/1000.00; + } + } + return 0; +} diff --git a/onewire/w1.h b/onewire/w1.h new file mode 100644 index 00000000..d95417e5 --- /dev/null +++ b/onewire/w1.h @@ -0,0 +1,57 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +* +* Copyright 2013 - 2020, nymea GmbH +* Contact: contact@nymea.io +* +* This file is part of nymea. +* This project including source code and documentation is protected by +* copyright law, and remains the property of nymea GmbH. All rights, including +* reproduction, publication, editing and translation, are reserved. The use of +* this project is subject to the terms of a license agreement to be concluded +* with nymea GmbH in accordance with the terms of use of nymea GmbH, available +* under https://nymea.io/license +* +* GNU Lesser General Public License Usage +* Alternatively, this project may be redistributed and/or modified under the +* terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; version 3. This project is distributed in the hope that +* it will be useful, but WITHOUT ANY WARRANTY; without even the implied +* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this project. If not, see . +* +* For any further details and any questions please contact us under +* contact@nymea.io or see our FAQ/Licensing Information on +* https://nymea.io/license/faq +* +* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef W1_H +#define W1_H + +#include +#include +#include + +class W1 : public QObject +{ + Q_OBJECT +public: + + explicit W1(QObject *parent = nullptr); + ~W1(); + + QString getPath(); + QStringList discoverDevices(); + bool interfaceIsAvailable(); + + double getTemperature(const QString &address); + + QList m_w1BusMasters; + +private: + QByteArray m_path; +}; +#endif // W1_H From 3286471e509ec66b47098f7153d0b38f00f61fcd Mon Sep 17 00:00:00 2001 From: "bernhard.trinnes" Date: Wed, 19 Aug 2020 20:23:10 +0200 Subject: [PATCH 2/8] renamed onewire interface --- onewire/integrationpluginonewire.json | 2 +- onewire/w1.h | 7 +------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/onewire/integrationpluginonewire.json b/onewire/integrationpluginonewire.json index cfce8fe0..834091c7 100644 --- a/onewire/integrationpluginonewire.json +++ b/onewire/integrationpluginonewire.json @@ -11,7 +11,7 @@ { "id": "c36c68d9-6182-4ae1-972d-b8b5e0cf185f", "name": "oneWireInterface", - "displayName": "One wire interface", + "displayName": "OWFS interface", "interfaces": ["gateway"], "createMethods": ["user"], "paramTypes": [ diff --git a/onewire/w1.h b/onewire/w1.h index d95417e5..2d009784 100644 --- a/onewire/w1.h +++ b/onewire/w1.h @@ -41,17 +41,12 @@ class W1 : public QObject public: explicit W1(QObject *parent = nullptr); - ~W1(); - QString getPath(); QStringList discoverDevices(); bool interfaceIsAvailable(); - double getTemperature(const QString &address); - QList m_w1BusMasters; - private: - QByteArray m_path; + QList m_w1BusMasters; }; #endif // W1_H From a2bb2ccf10119a705b350e0b849ab3dce87a2ba5 Mon Sep 17 00:00:00 2001 From: "bernhard.trinnes" Date: Wed, 19 Aug 2020 20:55:54 +0200 Subject: [PATCH 3/8] fixed segfault --- onewire/integrationpluginonewire.cpp | 32 ++++++++++++++++--------- onewire/w1.cpp | 36 +++++++++++++--------------- 2 files changed, 37 insertions(+), 31 deletions(-) diff --git a/onewire/integrationpluginonewire.cpp b/onewire/integrationpluginonewire.cpp index e10ed33a..a423bde2 100644 --- a/onewire/integrationpluginonewire.cpp +++ b/onewire/integrationpluginonewire.cpp @@ -139,9 +139,12 @@ void IntegrationPluginOneWire::setupThing(ThingSetupInfo *info) } connect(m_owfsInterface, &Owfs::devicesDiscovered, this, &IntegrationPluginOneWire::onOneWireDevicesDiscovered); return info->finish(Thing::ThingErrorNoError); - } - if (thing->thingClassId() == temperatureSensorThingClassId) { + } else if (thing->thingClassId() == temperatureSensorThingClassId) { + + if (!m_w1Interface) { + m_w1Interface = new W1(this); + } qCDebug(dcOneWire) << "Setup one wire temperature sensor" << thing->params(); if (m_owfsInterface) { //in case the child was setup before the interface @@ -155,18 +158,16 @@ void IntegrationPluginOneWire::setupThing(ThingSetupInfo *info) } else { return info->finish(Thing::ThingErrorHardwareNotAvailable, tr("No 1-Wire interface available")); } - } - if (thing->thingClassId() == singleChannelSwitchThingClassId) { + } else if (thing->thingClassId() == singleChannelSwitchThingClassId) { qCDebug(dcOneWire) << "Setup one wire switch" << thing->params(); if (!m_owfsInterface) { QByteArray address = thing->paramValue(singleChannelSwitchThingAddressParamTypeId).toByteArray(); thing->setStateValue(singleChannelSwitchDigitalOutputStateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_A)); } return info->finish(Thing::ThingErrorNoError); - } - if (thing->thingClassId() == dualChannelSwitchThingClassId) { + } else if (thing->thingClassId() == dualChannelSwitchThingClassId) { qCDebug(dcOneWire) << "Setup one wire dual switch" << thing->params(); if (!m_owfsInterface) { QByteArray address = thing->paramValue(dualChannelSwitchThingAddressParamTypeId).toByteArray(); @@ -174,9 +175,8 @@ void IntegrationPluginOneWire::setupThing(ThingSetupInfo *info) thing->setStateValue(dualChannelSwitchDigitalOutput2StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_B)); } return info->finish(Thing::ThingErrorNoError); - } - if (thing->thingClassId() == eightChannelSwitchThingClassId) { + } else if (thing->thingClassId() == eightChannelSwitchThingClassId) { qCDebug(dcOneWire) << "Setup one wire eight channel switch" << thing->params(); if (!m_owfsInterface) { QByteArray address = thing->paramValue(eightChannelSwitchThingAddressParamTypeId).toByteArray(); @@ -190,8 +190,9 @@ void IntegrationPluginOneWire::setupThing(ThingSetupInfo *info) thing->setStateValue(eightChannelSwitchDigitalOutput8StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_H)); } return info->finish(Thing::ThingErrorNoError); + } else { + return info->finish(Thing::ThingErrorThingNotFound); } - return info->finish(Thing::ThingErrorThingNotFound); } void IntegrationPluginOneWire::postSetupThing(Thing *thing) @@ -285,6 +286,11 @@ void IntegrationPluginOneWire::thingRemoved(Thing *thing) return; } + if (myThings().filterByThingClassId(temperatureSensorThingClassId).isEmpty()) { + m_w1Interface->deleteLater(); + m_w1Interface = nullptr; + } + if (myThings().empty()) { hardwareManager()->pluginTimerManager()->unregisterTimer(m_pluginTimer); m_pluginTimer = nullptr; @@ -305,8 +311,12 @@ void IntegrationPluginOneWire::onPluginTimer() if (thing->thingClassId() == temperatureSensorThingClassId) { QByteArray address = thing->paramValue(temperatureSensorThingAddressParamTypeId).toByteArray(); - - double temperature = m_owfsInterface->getTemperature(address); + double temperature = 0; + if (m_owfsInterface) { + temperature = m_owfsInterface->getTemperature(address); + } else if (m_w1Interface) { + temperature = m_w1Interface->getTemperature(address); + } thing->setStateValue(temperatureSensorTemperatureStateTypeId, temperature); } diff --git a/onewire/w1.cpp b/onewire/w1.cpp index 3722e181..1d93d991 100644 --- a/onewire/w1.cpp +++ b/onewire/w1.cpp @@ -46,25 +46,16 @@ QStringList W1::discoverDevices() qCDebug(dcOneWire()) << "W1 kernel not loaded"; return deviceList; } - w1SysFSDir.setFilter(QDir::Dirs | QDir::NoSymLinks); + w1SysFSDir.setFilter(QDir::Dirs | QDir::NoDotAndDotDot); w1SysFSDir.setSorting(QDir::Name); QFileInfoList list = w1SysFSDir.entryInfoList(); for (int i = 0; i < list.size(); ++i) { QFileInfo fileInfo = list.at(i); - qCDebug(dcOneWire()) << "Found W1 bus master" << fileInfo.fileName() << fileInfo.filePath(); - m_w1BusMasters.append(QDir(fileInfo.filePath())); - } - - Q_FOREACH(QDir busMaster, m_w1BusMasters) { - busMaster.setFilter(QDir::Dirs | QDir::NoSymLinks); - busMaster.setSorting(QDir::Name); - QFileInfoList list = busMaster.entryInfoList(); - for (int i = 0; i < list.size(); ++i) { - QFileInfo fileInfo = list.at(i); + if(fileInfo.fileName()[2] == '-') { + qCDebug(dcOneWire()) << "Found one wire device" << fileInfo.filePath(); deviceList.append(fileInfo.fileName()); } - } return deviceList; } @@ -77,15 +68,20 @@ bool W1::interfaceIsAvailable() double W1::getTemperature(const QString &address) { - Q_FOREACH(QDir busMaster, m_w1BusMasters) { - QDir temperatureSensor(busMaster.dirName()+address); - if (temperatureSensor.exists()) { - qCDebug(dcOneWire()) << "Temperature" << address; - QFile temperature(temperatureSensor.dirName()+"/temperature"); - if (!temperature.open(QIODevice::ReadOnly | QIODevice::Text)) - return 0; - return temperature.readLine().toInt()/1000.00; + QDir temperatureSensor("/sys/bus/w1/devices/"+address); + if (temperatureSensor.exists()) { + qCDebug(dcOneWire()) << "Temperature" << address; + QFile temperature(temperatureSensor.dirName()+"/temperature"); + if (!temperature.exists()) { + qCWarning(dcOneWire()) << "Directory doesn't exist" << temperature.fileName(); } + if (!temperature.open(QIODevice::ReadOnly | QIODevice::Text)){ + qCWarning(dcOneWire()) << "Could not open file" << temperature.fileName(); + return 0; + } + return temperature.readLine().toInt()/1000.00; + } else { + qCWarning(dcOneWire()) << "Could not find device" << temperatureSensor; } return 0; } From bb28d3417edfe9ce6bcc184124e24086f8837019 Mon Sep 17 00:00:00 2001 From: "bernhard.trinnes" Date: Wed, 19 Aug 2020 21:17:43 +0200 Subject: [PATCH 4/8] added connected state to all one wire devices --- onewire/integrationpluginonewire.cpp | 7 ++++++ onewire/integrationpluginonewire.json | 34 ++++++++++++++++++++++++++- onewire/owfs.cpp | 7 +++++- onewire/w1.cpp | 9 +++++-- onewire/w1.h | 1 + 5 files changed, 54 insertions(+), 4 deletions(-) diff --git a/onewire/integrationpluginonewire.cpp b/onewire/integrationpluginonewire.cpp index a423bde2..958ebe12 100644 --- a/onewire/integrationpluginonewire.cpp +++ b/onewire/integrationpluginonewire.cpp @@ -312,23 +312,29 @@ void IntegrationPluginOneWire::onPluginTimer() if (thing->thingClassId() == temperatureSensorThingClassId) { QByteArray address = thing->paramValue(temperatureSensorThingAddressParamTypeId).toByteArray(); double temperature = 0; + bool connected = false; if (m_owfsInterface) { temperature = m_owfsInterface->getTemperature(address); + connected = m_owfsInterface->isConnected(address); } else if (m_w1Interface) { temperature = m_w1Interface->getTemperature(address); + connected = m_w1Interface->deviceAvailable(address); } thing->setStateValue(temperatureSensorTemperatureStateTypeId, temperature); + thing->setStateValue(temperatureSensorConnectedStateTypeId, connected); } if (thing->thingClassId() == singleChannelSwitchThingClassId) { QByteArray address = thing->paramValue(singleChannelSwitchThingAddressParamTypeId).toByteArray(); thing->setStateValue(singleChannelSwitchDigitalOutputStateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_A)); + thing->setStateValue(singleChannelSwitchConnectedStateTypeId, m_owfsInterface->isConnected(address)); } if (thing->thingClassId() == dualChannelSwitchThingClassId) { QByteArray address = thing->paramValue(dualChannelSwitchThingAddressParamTypeId).toByteArray(); thing->setStateValue(dualChannelSwitchDigitalOutput1StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_A)); thing->setStateValue(dualChannelSwitchDigitalOutput2StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_B)); + thing->setStateValue(dualChannelSwitchConnectedStateTypeId, m_owfsInterface->isConnected(address)); } if (thing->thingClassId() == eightChannelSwitchThingClassId) { @@ -341,6 +347,7 @@ void IntegrationPluginOneWire::onPluginTimer() thing->setStateValue(eightChannelSwitchDigitalOutput6StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_F)); thing->setStateValue(eightChannelSwitchDigitalOutput7StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_G)); thing->setStateValue(eightChannelSwitchDigitalOutput8StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_H)); + thing->setStateValue(eightChannelSwitchConnectedStateTypeId, m_owfsInterface->isConnected(address)); } } } diff --git a/onewire/integrationpluginonewire.json b/onewire/integrationpluginonewire.json index 834091c7..f4979797 100644 --- a/onewire/integrationpluginonewire.json +++ b/onewire/integrationpluginonewire.json @@ -68,6 +68,14 @@ } ], "stateTypes": [ + { + "id": "32305a16-b042-4574-8bd7-ad99d9e8e5da", + "name": "connected", + "displayName": "connected", + "displayNameEvent": "connected changed", + "defaultValue": false, + "type": "bool" + }, { "id": "b04ee2a5-9b27-4ffc-9e12-7e05f5a41690", "name": "temperature", @@ -102,7 +110,15 @@ "readOnly": true } ], - "stateTypes": [ + "stateTypes": [ + { + "id": "16bae8e8-bfe1-4648-9018-f6ce610f4236", + "name": "connected", + "displayName": "connected", + "displayNameEvent": "connected changed", + "defaultValue": false, + "type": "bool" + }, { "id": "ca10a9fd-e4e0-4608-a2d2-6a4ce9644f40", "name": "digitalOutput", @@ -139,6 +155,14 @@ } ], "stateTypes": [ + { + "id": "fb6e63db-316b-4959-a349-0ff58a679f71", + "name": "connected", + "displayName": "connected", + "displayNameEvent": "connected changed", + "defaultValue": false, + "type": "bool" + }, { "id": "f8b6b4a7-355c-4580-a676-8a4d0d619ff9", "name": "digitalOutput1", @@ -186,6 +210,14 @@ } ], "stateTypes": [ + { + "id": "b99585e0-5147-46e3-9474-fba555bac68a", + "name": "connected", + "displayName": "connected", + "displayNameEvent": "connected changed", + "defaultValue": false, + "type": "bool" + }, { "id": "78fa12c0-246c-4112-8be6-5943d3c3cda5", "name": "digitalOutput1", diff --git a/onewire/owfs.cpp b/onewire/owfs.cpp index 739f82bb..701fedac 100644 --- a/onewire/owfs.cpp +++ b/onewire/owfs.cpp @@ -111,11 +111,16 @@ bool Owfs::discoverDevices() bool Owfs::interfaceIsAvailable() { return true; + //TODO + //QByteArray fullPath; + //fullPath.append(m_path); + //if(OW_present(fullPath) < 0) + // return false; + //return true; } bool Owfs::isConnected(const QByteArray &address) { - Q_UNUSED(address) QByteArray fullPath; fullPath.append(m_path); fullPath.append(address); diff --git a/onewire/w1.cpp b/onewire/w1.cpp index 1d93d991..34ea7c11 100644 --- a/onewire/w1.cpp +++ b/onewire/w1.cpp @@ -66,12 +66,17 @@ bool W1::interfaceIsAvailable() return w1SysFSDir.exists(); } +bool W1::deviceAvailable(const QString &address) +{ + QDir temperatureSensor("/sys/bus/w1/devices/"+address); + return temperatureSensor.exists(); +} + double W1::getTemperature(const QString &address) { QDir temperatureSensor("/sys/bus/w1/devices/"+address); if (temperatureSensor.exists()) { - qCDebug(dcOneWire()) << "Temperature" << address; - QFile temperature(temperatureSensor.dirName()+"/temperature"); + QFile temperature(temperatureSensor.path() +"/temperature"); if (!temperature.exists()) { qCWarning(dcOneWire()) << "Directory doesn't exist" << temperature.fileName(); } diff --git a/onewire/w1.h b/onewire/w1.h index 2d009784..597eb307 100644 --- a/onewire/w1.h +++ b/onewire/w1.h @@ -44,6 +44,7 @@ public: QStringList discoverDevices(); bool interfaceIsAvailable(); + bool deviceAvailable(const QString &address); double getTemperature(const QString &address); private: From dcee82ec7f075fa93d4b1bb6ff5a96e8f48fcb4d Mon Sep 17 00:00:00 2001 From: "bernhard.trinnes" Date: Wed, 19 Aug 2020 21:24:09 +0200 Subject: [PATCH 5/8] added connected state to all one wire devices --- onewire/integrationpluginonewire.cpp | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/onewire/integrationpluginonewire.cpp b/onewire/integrationpluginonewire.cpp index 958ebe12..e61ccf2b 100644 --- a/onewire/integrationpluginonewire.cpp +++ b/onewire/integrationpluginonewire.cpp @@ -147,13 +147,14 @@ void IntegrationPluginOneWire::setupThing(ThingSetupInfo *info) } qCDebug(dcOneWire) << "Setup one wire temperature sensor" << thing->params(); + QString address = thing->paramValue(temperatureSensorThingAddressParamTypeId).toByteArray(); if (m_owfsInterface) { //in case the child was setup before the interface - double temperature = m_owfsInterface->getTemperature(thing->paramValue(temperatureSensorThingAddressParamTypeId).toByteArray()); - thing->setStateValue(temperatureSensorTemperatureStateTypeId, temperature); + thing->setStateValue(temperatureSensorConnectedStateTypeId, m_owfsInterface->isConnected(address.toUtf8())); + thing->setStateValue(temperatureSensorTemperatureStateTypeId, m_owfsInterface->getTemperature(address.toUtf8())); return info->finish(Thing::ThingErrorNoError); } else if (m_w1Interface) { - double temperature = m_w1Interface->getTemperature(thing->paramValue(temperatureSensorThingAddressParamTypeId).toByteArray()); - thing->setStateValue(temperatureSensorTemperatureStateTypeId, temperature); + thing->setStateValue(temperatureSensorConnectedStateTypeId, m_w1Interface->deviceAvailable(address)); + thing->setStateValue(temperatureSensorTemperatureStateTypeId, m_w1Interface->getTemperature(address)); return info->finish(Thing::ThingErrorNoError); } else { return info->finish(Thing::ThingErrorHardwareNotAvailable, tr("No 1-Wire interface available")); @@ -161,24 +162,26 @@ void IntegrationPluginOneWire::setupThing(ThingSetupInfo *info) } else if (thing->thingClassId() == singleChannelSwitchThingClassId) { qCDebug(dcOneWire) << "Setup one wire switch" << thing->params(); - if (!m_owfsInterface) { + if (m_owfsInterface) { QByteArray address = thing->paramValue(singleChannelSwitchThingAddressParamTypeId).toByteArray(); thing->setStateValue(singleChannelSwitchDigitalOutputStateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_A)); + thing->setStateValue(singleChannelSwitchConnectedStateTypeId, m_owfsInterface->isConnected(address)); } return info->finish(Thing::ThingErrorNoError); } else if (thing->thingClassId() == dualChannelSwitchThingClassId) { qCDebug(dcOneWire) << "Setup one wire dual switch" << thing->params(); - if (!m_owfsInterface) { + if (m_owfsInterface) { QByteArray address = thing->paramValue(dualChannelSwitchThingAddressParamTypeId).toByteArray(); thing->setStateValue(dualChannelSwitchDigitalOutput1StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_A)); thing->setStateValue(dualChannelSwitchDigitalOutput2StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_B)); + thing->setStateValue(dualChannelSwitchConnectedStateTypeId, m_owfsInterface->isConnected(address)); } return info->finish(Thing::ThingErrorNoError); } else if (thing->thingClassId() == eightChannelSwitchThingClassId) { qCDebug(dcOneWire) << "Setup one wire eight channel switch" << thing->params(); - if (!m_owfsInterface) { + if (m_owfsInterface) { QByteArray address = thing->paramValue(eightChannelSwitchThingAddressParamTypeId).toByteArray(); thing->setStateValue(eightChannelSwitchDigitalOutput1StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_A)); thing->setStateValue(eightChannelSwitchDigitalOutput2StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_B)); @@ -188,6 +191,7 @@ void IntegrationPluginOneWire::setupThing(ThingSetupInfo *info) thing->setStateValue(eightChannelSwitchDigitalOutput6StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_F)); thing->setStateValue(eightChannelSwitchDigitalOutput7StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_G)); thing->setStateValue(eightChannelSwitchDigitalOutput8StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_H)); + thing->setStateValue(eightChannelSwitchConnectedStateTypeId, m_owfsInterface->isConnected(address)); } return info->finish(Thing::ThingErrorNoError); } else { @@ -314,12 +318,12 @@ void IntegrationPluginOneWire::onPluginTimer() double temperature = 0; bool connected = false; if (m_owfsInterface) { - temperature = m_owfsInterface->getTemperature(address); - connected = m_owfsInterface->isConnected(address); + temperature = m_owfsInterface->getTemperature(address); + connected = m_owfsInterface->isConnected(address); } else if (m_w1Interface) { temperature = m_w1Interface->getTemperature(address); connected = m_w1Interface->deviceAvailable(address); - } + } thing->setStateValue(temperatureSensorTemperatureStateTypeId, temperature); thing->setStateValue(temperatureSensorConnectedStateTypeId, connected); } @@ -327,7 +331,7 @@ void IntegrationPluginOneWire::onPluginTimer() if (thing->thingClassId() == singleChannelSwitchThingClassId) { QByteArray address = thing->paramValue(singleChannelSwitchThingAddressParamTypeId).toByteArray(); thing->setStateValue(singleChannelSwitchDigitalOutputStateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_A)); - thing->setStateValue(singleChannelSwitchConnectedStateTypeId, m_owfsInterface->isConnected(address)); + thing->setStateValue(singleChannelSwitchConnectedStateTypeId, m_owfsInterface->isConnected(address)); } if (thing->thingClassId() == dualChannelSwitchThingClassId) { From 2c1a10653deff024c25a894c1d12aa7e1bc2b413 Mon Sep 17 00:00:00 2001 From: "bernhard.trinnes" Date: Wed, 19 Aug 2020 21:49:52 +0200 Subject: [PATCH 6/8] added german translation --- onewire/integrationpluginonewire.json | 24 +- ...2c697fb7-0645-466d-9cb9-aa1922c85bee-de.ts | 451 ++++++++++++++++++ ...97fb7-0645-466d-9cb9-aa1922c85bee-en_US.ts | 272 ++++++----- onewire/w1.cpp | 2 +- 4 files changed, 620 insertions(+), 129 deletions(-) create mode 100644 onewire/translations/2c697fb7-0645-466d-9cb9-aa1922c85bee-de.ts diff --git a/onewire/integrationpluginonewire.json b/onewire/integrationpluginonewire.json index f4979797..3dd69846 100644 --- a/onewire/integrationpluginonewire.json +++ b/onewire/integrationpluginonewire.json @@ -27,8 +27,8 @@ { "id": "d0ded173-c382-4ee3-8e24-3647b4e16afa", "name": "connected", - "displayName": "connected", - "displayNameEvent": "connected changed", + "displayName": "Connected", + "displayNameEvent": "Connected changed", "defaultValue": false, "type": "bool" }, @@ -71,16 +71,16 @@ { "id": "32305a16-b042-4574-8bd7-ad99d9e8e5da", "name": "connected", - "displayName": "connected", - "displayNameEvent": "connected changed", + "displayName": "Connected", + "displayNameEvent": "Connected changed", "defaultValue": false, "type": "bool" }, { "id": "b04ee2a5-9b27-4ffc-9e12-7e05f5a41690", "name": "temperature", - "displayName": "temperature", - "displayNameEvent": "temperature changed", + "displayName": "Temperature", + "displayNameEvent": "Temperature changed", "unit": "DegreeCelsius", "type": "double", "defaultValue": 0 @@ -114,8 +114,8 @@ { "id": "16bae8e8-bfe1-4648-9018-f6ce610f4236", "name": "connected", - "displayName": "connected", - "displayNameEvent": "connected changed", + "displayName": "Connected", + "displayNameEvent": "Connected changed", "defaultValue": false, "type": "bool" }, @@ -158,8 +158,8 @@ { "id": "fb6e63db-316b-4959-a349-0ff58a679f71", "name": "connected", - "displayName": "connected", - "displayNameEvent": "connected changed", + "displayName": "Connected", + "displayNameEvent": "Connected changed", "defaultValue": false, "type": "bool" }, @@ -213,8 +213,8 @@ { "id": "b99585e0-5147-46e3-9474-fba555bac68a", "name": "connected", - "displayName": "connected", - "displayNameEvent": "connected changed", + "displayName": "Connected", + "displayNameEvent": "Connected changed", "defaultValue": false, "type": "bool" }, diff --git a/onewire/translations/2c697fb7-0645-466d-9cb9-aa1922c85bee-de.ts b/onewire/translations/2c697fb7-0645-466d-9cb9-aa1922c85bee-de.ts new file mode 100644 index 00000000..47393ec6 --- /dev/null +++ b/onewire/translations/2c697fb7-0645-466d-9cb9-aa1922c85bee-de.ts @@ -0,0 +1,451 @@ + + + + + IntegrationPluginOneWire + + + No one wire interface initialized. Please set up a one wire interface first. + Es wurde keine OWFS Schnittstelle initialisiert. Bitte richten Sie zuerst eine OWFS Schnittstelle ein. + + + + All configured one wire interfaces are set up to automatically add new devices. + Alle konfigurierten OWFS-Schnittstellen sind so eingerichtet, dass automatisch neue Geräte hinzugefügt werden. + + + + There can only be one one wire interface per system. + Error setting up thing + Es kann nur eine One-Wire-Schnittstelle pro System geben. + + + + Error initializing one wire interface. + Error setting up thing + Fehler beim Initialisieren der One-Wire-Schnittstelle. + + + + No 1-Wire interface available + Keine One-Wire-Schnittstelle verfügbar + + + + OneWire + + + 1-channel switch + The name of the ThingClass ({6db42501-5451-4aac-9525-5f886b3188e2}) + 1-Kanal Schalter + + + + 2-channel switch + The name of the ThingClass ({023f2b93-61e1-4422-97f5-3d5c14a6628f}) + 2-Kanal Schalter + + + + 8-channel switch + The name of the ThingClass ({71691119-3bda-4424-b853-1a00f21086e1}) + 8-Kanal Schalter + + + + + + + Address + The name of the ParamType (ThingClass: eightChannelSwitch, Type: thing, ID: {e3e6e596-0cd4-42a3-8401-ccf6349314b7}) +---------- +The name of the ParamType (ThingClass: dualChannelSwitch, Type: thing, ID: {b9a1a23d-1fbf-4849-8aa2-2855e7deaf84}) +---------- +The name of the ParamType (ThingClass: singleChannelSwitch, Type: thing, ID: {c9d6b7fd-fa21-473a-b5ed-9c5227749f06}) +---------- +The name of the ParamType (ThingClass: temperatureSensor, Type: thing, ID: {b4368f34-d9bb-496f-84ba-091bd4b6a332}) + Adresse + + + + + + Auto add one wire devices + The name of the ParamType (ThingClass: oneWireInterface, ActionType: autoAdd, ID: {64baf50e-8ed4-4526-8b92-7e4662d6fa39}) +---------- +The name of the ParamType (ThingClass: oneWireInterface, EventType: autoAdd, ID: {64baf50e-8ed4-4526-8b92-7e4662d6fa39}) +---------- +The name of the StateType ({64baf50e-8ed4-4526-8b92-7e4662d6fa39}) of ThingClass oneWireInterface + Automatisches hinzufügen von One-Wire-Geräten + + + + Auto add one wire devices changed + The name of the EventType ({64baf50e-8ed4-4526-8b92-7e4662d6fa39}) of ThingClass oneWireInterface + Automatisches hinzufügen von One-Wire-Geräten geändert + + + + + + + + + + + + + Connected + The name of the ParamType (ThingClass: eightChannelSwitch, EventType: connected, ID: {b99585e0-5147-46e3-9474-fba555bac68a}) +---------- +The name of the StateType ({b99585e0-5147-46e3-9474-fba555bac68a}) of ThingClass eightChannelSwitch +---------- +The name of the ParamType (ThingClass: dualChannelSwitch, EventType: connected, ID: {fb6e63db-316b-4959-a349-0ff58a679f71}) +---------- +The name of the StateType ({fb6e63db-316b-4959-a349-0ff58a679f71}) of ThingClass dualChannelSwitch +---------- +The name of the ParamType (ThingClass: singleChannelSwitch, EventType: connected, ID: {16bae8e8-bfe1-4648-9018-f6ce610f4236}) +---------- +The name of the StateType ({16bae8e8-bfe1-4648-9018-f6ce610f4236}) of ThingClass singleChannelSwitch +---------- +The name of the ParamType (ThingClass: temperatureSensor, EventType: connected, ID: {32305a16-b042-4574-8bd7-ad99d9e8e5da}) +---------- +The name of the StateType ({32305a16-b042-4574-8bd7-ad99d9e8e5da}) of ThingClass temperatureSensor +---------- +The name of the ParamType (ThingClass: oneWireInterface, EventType: connected, ID: {d0ded173-c382-4ee3-8e24-3647b4e16afa}) +---------- +The name of the StateType ({d0ded173-c382-4ee3-8e24-3647b4e16afa}) of ThingClass oneWireInterface + Verbunden + + + + + + + + Connected changed + The name of the EventType ({b99585e0-5147-46e3-9474-fba555bac68a}) of ThingClass eightChannelSwitch +---------- +The name of the EventType ({fb6e63db-316b-4959-a349-0ff58a679f71}) of ThingClass dualChannelSwitch +---------- +The name of the EventType ({16bae8e8-bfe1-4648-9018-f6ce610f4236}) of ThingClass singleChannelSwitch +---------- +The name of the EventType ({32305a16-b042-4574-8bd7-ad99d9e8e5da}) of ThingClass temperatureSensor +---------- +The name of the EventType ({d0ded173-c382-4ee3-8e24-3647b4e16afa}) of ThingClass oneWireInterface + Verbunden geändert + + + + + + Digital output + The name of the ParamType (ThingClass: singleChannelSwitch, ActionType: digitalOutput, ID: {ca10a9fd-e4e0-4608-a2d2-6a4ce9644f40}) +---------- +The name of the ParamType (ThingClass: singleChannelSwitch, EventType: digitalOutput, ID: {ca10a9fd-e4e0-4608-a2d2-6a4ce9644f40}) +---------- +The name of the StateType ({ca10a9fd-e4e0-4608-a2d2-6a4ce9644f40}) of ThingClass singleChannelSwitch + Digitaler Ausgang + + + + + + + + + Digital output 1 + The name of the ParamType (ThingClass: eightChannelSwitch, ActionType: digitalOutput1, ID: {78fa12c0-246c-4112-8be6-5943d3c3cda5}) +---------- +The name of the ParamType (ThingClass: eightChannelSwitch, EventType: digitalOutput1, ID: {78fa12c0-246c-4112-8be6-5943d3c3cda5}) +---------- +The name of the StateType ({78fa12c0-246c-4112-8be6-5943d3c3cda5}) of ThingClass eightChannelSwitch +---------- +The name of the ParamType (ThingClass: dualChannelSwitch, ActionType: digitalOutput1, ID: {f8b6b4a7-355c-4580-a676-8a4d0d619ff9}) +---------- +The name of the ParamType (ThingClass: dualChannelSwitch, EventType: digitalOutput1, ID: {f8b6b4a7-355c-4580-a676-8a4d0d619ff9}) +---------- +The name of the StateType ({f8b6b4a7-355c-4580-a676-8a4d0d619ff9}) of ThingClass dualChannelSwitch + Digitaler Ausgang 1 + + + + + Digital output 1 changed + The name of the EventType ({78fa12c0-246c-4112-8be6-5943d3c3cda5}) of ThingClass eightChannelSwitch +---------- +The name of the EventType ({f8b6b4a7-355c-4580-a676-8a4d0d619ff9}) of ThingClass dualChannelSwitch + Digitaler Ausgang 1 geändert + + + + + + + + + Digital output 2 + The name of the ParamType (ThingClass: eightChannelSwitch, ActionType: digitalOutput2, ID: {c7d2f4a8-2b13-4a48-81a8-72f4908c775b}) +---------- +The name of the ParamType (ThingClass: eightChannelSwitch, EventType: digitalOutput2, ID: {c7d2f4a8-2b13-4a48-81a8-72f4908c775b}) +---------- +The name of the StateType ({c7d2f4a8-2b13-4a48-81a8-72f4908c775b}) of ThingClass eightChannelSwitch +---------- +The name of the ParamType (ThingClass: dualChannelSwitch, ActionType: digitalOutput2, ID: {82a78aed-5994-4af5-aecb-1806be5de1f3}) +---------- +The name of the ParamType (ThingClass: dualChannelSwitch, EventType: digitalOutput2, ID: {82a78aed-5994-4af5-aecb-1806be5de1f3}) +---------- +The name of the StateType ({82a78aed-5994-4af5-aecb-1806be5de1f3}) of ThingClass dualChannelSwitch + Digitaler Ausgang 2 + + + + + Digital output 2 changed + The name of the EventType ({c7d2f4a8-2b13-4a48-81a8-72f4908c775b}) of ThingClass eightChannelSwitch +---------- +The name of the EventType ({82a78aed-5994-4af5-aecb-1806be5de1f3}) of ThingClass dualChannelSwitch + Digitaler Ausgang 2 geändert + + + + + + Digital output 3 + The name of the ParamType (ThingClass: eightChannelSwitch, ActionType: digitalOutput3, ID: {4b2ac595-eba9-4364-8cd7-00ff8bccda5a}) +---------- +The name of the ParamType (ThingClass: eightChannelSwitch, EventType: digitalOutput3, ID: {4b2ac595-eba9-4364-8cd7-00ff8bccda5a}) +---------- +The name of the StateType ({4b2ac595-eba9-4364-8cd7-00ff8bccda5a}) of ThingClass eightChannelSwitch + Digitaler Ausgang 3 + + + + Digital output 3 changed + The name of the EventType ({4b2ac595-eba9-4364-8cd7-00ff8bccda5a}) of ThingClass eightChannelSwitch + Digitaler Ausgang 3 geändert + + + + + + Digital output 4 + The name of the ParamType (ThingClass: eightChannelSwitch, ActionType: digitalOutput4, ID: {bbbd1863-ef04-4687-803d-3c9ccdfc8d8f}) +---------- +The name of the ParamType (ThingClass: eightChannelSwitch, EventType: digitalOutput4, ID: {bbbd1863-ef04-4687-803d-3c9ccdfc8d8f}) +---------- +The name of the StateType ({bbbd1863-ef04-4687-803d-3c9ccdfc8d8f}) of ThingClass eightChannelSwitch + Digitaler Ausgang 4 + + + + Digital output 4 changed + The name of the EventType ({bbbd1863-ef04-4687-803d-3c9ccdfc8d8f}) of ThingClass eightChannelSwitch + Digitaler Ausgang 4 geändert + + + + + + Digital output 5 + The name of the ParamType (ThingClass: eightChannelSwitch, ActionType: digitalOutput5, ID: {50855d2b-a700-4030-8674-fee00cc0b4e2}) +---------- +The name of the ParamType (ThingClass: eightChannelSwitch, EventType: digitalOutput5, ID: {50855d2b-a700-4030-8674-fee00cc0b4e2}) +---------- +The name of the StateType ({50855d2b-a700-4030-8674-fee00cc0b4e2}) of ThingClass eightChannelSwitch + Digitaler Ausgang 5 + + + + Digital output 5 changed + The name of the EventType ({50855d2b-a700-4030-8674-fee00cc0b4e2}) of ThingClass eightChannelSwitch + Digitaler Ausgang 5 geändert + + + + + + Digital output 6 + The name of the ParamType (ThingClass: eightChannelSwitch, ActionType: digitalOutput6, ID: {a91ce593-09ba-4754-8a2e-e3f507313585}) +---------- +The name of the ParamType (ThingClass: eightChannelSwitch, EventType: digitalOutput6, ID: {a91ce593-09ba-4754-8a2e-e3f507313585}) +---------- +The name of the StateType ({a91ce593-09ba-4754-8a2e-e3f507313585}) of ThingClass eightChannelSwitch + Digitaler Ausgang 6 + + + + Digital output 6 changed + The name of the EventType ({a91ce593-09ba-4754-8a2e-e3f507313585}) of ThingClass eightChannelSwitch + Digitaler Ausgang 6 geändert + + + + + + Digital output 7 + The name of the ParamType (ThingClass: eightChannelSwitch, ActionType: digitalOutput7, ID: {5f46047c-b00d-486f-b169-b738fbc89cdb}) +---------- +The name of the ParamType (ThingClass: eightChannelSwitch, EventType: digitalOutput7, ID: {5f46047c-b00d-486f-b169-b738fbc89cdb}) +---------- +The name of the StateType ({5f46047c-b00d-486f-b169-b738fbc89cdb}) of ThingClass eightChannelSwitch + Digitaler Ausgang 7 + + + + Digital output 7 changed + The name of the EventType ({5f46047c-b00d-486f-b169-b738fbc89cdb}) of ThingClass eightChannelSwitch + Digitaler Ausgang 7 geändert + + + + + + Digital output 8 + The name of the ParamType (ThingClass: eightChannelSwitch, ActionType: digitalOutput8, ID: {63334a17-0847-4f53-8007-1b5e72b88aa8}) +---------- +The name of the ParamType (ThingClass: eightChannelSwitch, EventType: digitalOutput8, ID: {63334a17-0847-4f53-8007-1b5e72b88aa8}) +---------- +The name of the StateType ({63334a17-0847-4f53-8007-1b5e72b88aa8}) of ThingClass eightChannelSwitch + Digitaler Ausgang 8 + + + + Digital output 8 changed + The name of the EventType ({63334a17-0847-4f53-8007-1b5e72b88aa8}) of ThingClass eightChannelSwitch + Digitaler Ausgang 8 geändert + + + + Digital output changed + The name of the EventType ({ca10a9fd-e4e0-4608-a2d2-6a4ce9644f40}) of ThingClass singleChannelSwitch + Digitaler Ausgang geändert + + + + OWFS init arguments + The name of the ParamType (ThingClass: oneWireInterface, Type: thing, ID: {a0e773ff-fd19-499e-96f0-830168229cd3}) + OWFS-Init-Argumente + + + + OWFS interface + The name of the ThingClass ({c36c68d9-6182-4ae1-972d-b8b5e0cf185f}) + OWFS Schnittstelle + + + + One Wire + The name of the plugin OneWire ({2c697fb7-0645-466d-9cb9-aa1922c85bee}) + One Wire + + + + One wire + The name of the vendor ({cecc5fae-29cf-40c0-b1f8-0af2dc8e8a63}) + One Wire + + + + Set auto add mode + The name of the ActionType ({64baf50e-8ed4-4526-8b92-7e4662d6fa39}) of ThingClass oneWireInterface + Setze automatischen Add-Modus + + + + Set digital output + The name of the ActionType ({ca10a9fd-e4e0-4608-a2d2-6a4ce9644f40}) of ThingClass singleChannelSwitch + Setze digitalen Ausgang + + + + + Set digital output 1 + The name of the ActionType ({78fa12c0-246c-4112-8be6-5943d3c3cda5}) of ThingClass eightChannelSwitch +---------- +The name of the ActionType ({f8b6b4a7-355c-4580-a676-8a4d0d619ff9}) of ThingClass dualChannelSwitch + Setze digitalen Ausgang 1 + + + + + Set digital output 2 + The name of the ActionType ({c7d2f4a8-2b13-4a48-81a8-72f4908c775b}) of ThingClass eightChannelSwitch +---------- +The name of the ActionType ({82a78aed-5994-4af5-aecb-1806be5de1f3}) of ThingClass dualChannelSwitch + Setze digitalen Ausgang 2 + + + + Set digital output 3 + The name of the ActionType ({4b2ac595-eba9-4364-8cd7-00ff8bccda5a}) of ThingClass eightChannelSwitch + Setze digitalen Ausgang 3 + + + + Set digital output 4 + The name of the ActionType ({bbbd1863-ef04-4687-803d-3c9ccdfc8d8f}) of ThingClass eightChannelSwitch + Setze digitalen Ausgang 4 + + + + Set digital output 5 + The name of the ActionType ({50855d2b-a700-4030-8674-fee00cc0b4e2}) of ThingClass eightChannelSwitch + Setze digitalen Ausgang 5 + + + + Set digital output 6 + The name of the ActionType ({a91ce593-09ba-4754-8a2e-e3f507313585}) of ThingClass eightChannelSwitch + Setze digitalen Ausgang 6 + + + + Set digital output 7 + The name of the ActionType ({5f46047c-b00d-486f-b169-b738fbc89cdb}) of ThingClass eightChannelSwitch + Setze digitalen Ausgang 7 + + + + Set digital output 8 + The name of the ActionType ({63334a17-0847-4f53-8007-1b5e72b88aa8}) of ThingClass eightChannelSwitch + Setze digitalen Ausgang 8 + + + + + Temperature + The name of the ParamType (ThingClass: temperatureSensor, EventType: temperature, ID: {b04ee2a5-9b27-4ffc-9e12-7e05f5a41690}) +---------- +The name of the StateType ({b04ee2a5-9b27-4ffc-9e12-7e05f5a41690}) of ThingClass temperatureSensor + Temperatur + + + + Temperature Sensor + The name of the ThingClass ({e13beb24-953c-48b3-9262-7cde31d42ef5}) + Termperatursensor + + + + Temperature changed + The name of the EventType ({b04ee2a5-9b27-4ffc-9e12-7e05f5a41690}) of ThingClass temperatureSensor + Temperatur geändert + + + + + + + Type + The name of the ParamType (ThingClass: eightChannelSwitch, Type: thing, ID: {34c8f771-4141-4183-9eaf-becbaf362ac8}) +---------- +The name of the ParamType (ThingClass: dualChannelSwitch, Type: thing, ID: {b71ed57b-e768-4119-829e-a0f2c9fa5e18}) +---------- +The name of the ParamType (ThingClass: singleChannelSwitch, Type: thing, ID: {6efc8cb6-81ae-45c0-8910-708401d1ba68}) +---------- +The name of the ParamType (ThingClass: temperatureSensor, Type: thing, ID: {5005822d-6a32-4bb8-9b77-f79da7382f76}) + Typ + + + diff --git a/onewire/translations/2c697fb7-0645-466d-9cb9-aa1922c85bee-en_US.ts b/onewire/translations/2c697fb7-0645-466d-9cb9-aa1922c85bee-en_US.ts index 47fa3071..2e1cf25e 100644 --- a/onewire/translations/2c697fb7-0645-466d-9cb9-aa1922c85bee-en_US.ts +++ b/onewire/translations/2c697fb7-0645-466d-9cb9-aa1922c85bee-en_US.ts @@ -4,54 +4,58 @@ IntegrationPluginOneWire - + No one wire interface initialized. Please set up a one wire interface first. - Error discovering one wire devices - + All configured one wire interfaces are set up to automatically add new devices. - + There can only be one one wire interface per system. Error setting up thing - + Error initializing one wire interface. Error setting up thing + + + No 1-Wire interface available + + OneWire - + 1-channel switch The name of the ThingClass ({6db42501-5451-4aac-9525-5f886b3188e2}) - + 2-channel switch The name of the ThingClass ({023f2b93-61e1-4422-97f5-3d5c14a6628f}) - + 8-channel switch The name of the ThingClass ({71691119-3bda-4424-b853-1a00f21086e1}) - - - - + + + + Address The name of the ParamType (ThingClass: eightChannelSwitch, Type: thing, ID: {e3e6e596-0cd4-42a3-8401-ccf6349314b7}) ---------- @@ -63,9 +67,9 @@ The name of the ParamType (ThingClass: temperatureSensor, Type: thing, ID: {b436 - - - + + + Auto add one wire devices The name of the ParamType (ThingClass: oneWireInterface, ActionType: autoAdd, ID: {64baf50e-8ed4-4526-8b92-7e4662d6fa39}) ---------- @@ -75,15 +79,66 @@ The name of the StateType ({64baf50e-8ed4-4526-8b92-7e4662d6fa39}) of ThingClass - + Auto add one wire devices changed The name of the EventType ({64baf50e-8ed4-4526-8b92-7e4662d6fa39}) of ThingClass oneWireInterface - - - + + + + + + + + + + + Connected + The name of the ParamType (ThingClass: eightChannelSwitch, EventType: connected, ID: {b99585e0-5147-46e3-9474-fba555bac68a}) +---------- +The name of the StateType ({b99585e0-5147-46e3-9474-fba555bac68a}) of ThingClass eightChannelSwitch +---------- +The name of the ParamType (ThingClass: dualChannelSwitch, EventType: connected, ID: {fb6e63db-316b-4959-a349-0ff58a679f71}) +---------- +The name of the StateType ({fb6e63db-316b-4959-a349-0ff58a679f71}) of ThingClass dualChannelSwitch +---------- +The name of the ParamType (ThingClass: singleChannelSwitch, EventType: connected, ID: {16bae8e8-bfe1-4648-9018-f6ce610f4236}) +---------- +The name of the StateType ({16bae8e8-bfe1-4648-9018-f6ce610f4236}) of ThingClass singleChannelSwitch +---------- +The name of the ParamType (ThingClass: temperatureSensor, EventType: connected, ID: {32305a16-b042-4574-8bd7-ad99d9e8e5da}) +---------- +The name of the StateType ({32305a16-b042-4574-8bd7-ad99d9e8e5da}) of ThingClass temperatureSensor +---------- +The name of the ParamType (ThingClass: oneWireInterface, EventType: connected, ID: {d0ded173-c382-4ee3-8e24-3647b4e16afa}) +---------- +The name of the StateType ({d0ded173-c382-4ee3-8e24-3647b4e16afa}) of ThingClass oneWireInterface + + + + + + + + + Connected changed + The name of the EventType ({b99585e0-5147-46e3-9474-fba555bac68a}) of ThingClass eightChannelSwitch +---------- +The name of the EventType ({fb6e63db-316b-4959-a349-0ff58a679f71}) of ThingClass dualChannelSwitch +---------- +The name of the EventType ({16bae8e8-bfe1-4648-9018-f6ce610f4236}) of ThingClass singleChannelSwitch +---------- +The name of the EventType ({32305a16-b042-4574-8bd7-ad99d9e8e5da}) of ThingClass temperatureSensor +---------- +The name of the EventType ({d0ded173-c382-4ee3-8e24-3647b4e16afa}) of ThingClass oneWireInterface + + + + + + Digital output The name of the ParamType (ThingClass: singleChannelSwitch, ActionType: digitalOutput, ID: {ca10a9fd-e4e0-4608-a2d2-6a4ce9644f40}) ---------- @@ -93,12 +148,12 @@ The name of the StateType ({ca10a9fd-e4e0-4608-a2d2-6a4ce9644f40}) of ThingClass - - - - - - + + + + + + Digital output 1 The name of the ParamType (ThingClass: eightChannelSwitch, ActionType: digitalOutput1, ID: {78fa12c0-246c-4112-8be6-5943d3c3cda5}) ---------- @@ -114,8 +169,8 @@ The name of the StateType ({f8b6b4a7-355c-4580-a676-8a4d0d619ff9}) of ThingClass - - + + Digital output 1 changed The name of the EventType ({78fa12c0-246c-4112-8be6-5943d3c3cda5}) of ThingClass eightChannelSwitch ---------- @@ -123,12 +178,12 @@ The name of the EventType ({f8b6b4a7-355c-4580-a676-8a4d0d619ff9}) of ThingClass - - - - - - + + + + + + Digital output 2 The name of the ParamType (ThingClass: eightChannelSwitch, ActionType: digitalOutput2, ID: {c7d2f4a8-2b13-4a48-81a8-72f4908c775b}) ---------- @@ -144,8 +199,8 @@ The name of the StateType ({82a78aed-5994-4af5-aecb-1806be5de1f3}) of ThingClass - - + + Digital output 2 changed The name of the EventType ({c7d2f4a8-2b13-4a48-81a8-72f4908c775b}) of ThingClass eightChannelSwitch ---------- @@ -153,9 +208,9 @@ The name of the EventType ({82a78aed-5994-4af5-aecb-1806be5de1f3}) of ThingClass - - - + + + Digital output 3 The name of the ParamType (ThingClass: eightChannelSwitch, ActionType: digitalOutput3, ID: {4b2ac595-eba9-4364-8cd7-00ff8bccda5a}) ---------- @@ -165,15 +220,15 @@ The name of the StateType ({4b2ac595-eba9-4364-8cd7-00ff8bccda5a}) of ThingClass - + Digital output 3 changed The name of the EventType ({4b2ac595-eba9-4364-8cd7-00ff8bccda5a}) of ThingClass eightChannelSwitch - - - + + + Digital output 4 The name of the ParamType (ThingClass: eightChannelSwitch, ActionType: digitalOutput4, ID: {bbbd1863-ef04-4687-803d-3c9ccdfc8d8f}) ---------- @@ -183,15 +238,15 @@ The name of the StateType ({bbbd1863-ef04-4687-803d-3c9ccdfc8d8f}) of ThingClass - + Digital output 4 changed The name of the EventType ({bbbd1863-ef04-4687-803d-3c9ccdfc8d8f}) of ThingClass eightChannelSwitch - - - + + + Digital output 5 The name of the ParamType (ThingClass: eightChannelSwitch, ActionType: digitalOutput5, ID: {50855d2b-a700-4030-8674-fee00cc0b4e2}) ---------- @@ -201,15 +256,15 @@ The name of the StateType ({50855d2b-a700-4030-8674-fee00cc0b4e2}) of ThingClass - + Digital output 5 changed The name of the EventType ({50855d2b-a700-4030-8674-fee00cc0b4e2}) of ThingClass eightChannelSwitch - - - + + + Digital output 6 The name of the ParamType (ThingClass: eightChannelSwitch, ActionType: digitalOutput6, ID: {a91ce593-09ba-4754-8a2e-e3f507313585}) ---------- @@ -219,15 +274,15 @@ The name of the StateType ({a91ce593-09ba-4754-8a2e-e3f507313585}) of ThingClass - + Digital output 6 changed The name of the EventType ({a91ce593-09ba-4754-8a2e-e3f507313585}) of ThingClass eightChannelSwitch - - - + + + Digital output 7 The name of the ParamType (ThingClass: eightChannelSwitch, ActionType: digitalOutput7, ID: {5f46047c-b00d-486f-b169-b738fbc89cdb}) ---------- @@ -237,15 +292,15 @@ The name of the StateType ({5f46047c-b00d-486f-b169-b738fbc89cdb}) of ThingClass - + Digital output 7 changed The name of the EventType ({5f46047c-b00d-486f-b169-b738fbc89cdb}) of ThingClass eightChannelSwitch - - - + + + Digital output 8 The name of the ParamType (ThingClass: eightChannelSwitch, ActionType: digitalOutput8, ID: {63334a17-0847-4f53-8007-1b5e72b88aa8}) ---------- @@ -255,56 +310,56 @@ The name of the StateType ({63334a17-0847-4f53-8007-1b5e72b88aa8}) of ThingClass - + Digital output 8 changed The name of the EventType ({63334a17-0847-4f53-8007-1b5e72b88aa8}) of ThingClass eightChannelSwitch - + Digital output changed The name of the EventType ({ca10a9fd-e4e0-4608-a2d2-6a4ce9644f40}) of ThingClass singleChannelSwitch - + OWFS init arguments The name of the ParamType (ThingClass: oneWireInterface, Type: thing, ID: {a0e773ff-fd19-499e-96f0-830168229cd3}) - + + OWFS interface + The name of the ThingClass ({c36c68d9-6182-4ae1-972d-b8b5e0cf185f}) + + + + One Wire The name of the plugin OneWire ({2c697fb7-0645-466d-9cb9-aa1922c85bee}) - + One wire The name of the vendor ({cecc5fae-29cf-40c0-b1f8-0af2dc8e8a63}) - - One wire interface - The name of the ThingClass ({c36c68d9-6182-4ae1-972d-b8b5e0cf185f}) - - - - + Set auto add mode The name of the ActionType ({64baf50e-8ed4-4526-8b92-7e4662d6fa39}) of ThingClass oneWireInterface - + Set digital output The name of the ActionType ({ca10a9fd-e4e0-4608-a2d2-6a4ce9644f40}) of ThingClass singleChannelSwitch - - + + Set digital output 1 The name of the ActionType ({78fa12c0-246c-4112-8be6-5943d3c3cda5}) of ThingClass eightChannelSwitch ---------- @@ -312,8 +367,8 @@ The name of the ActionType ({f8b6b4a7-355c-4580-a676-8a4d0d619ff9}) of ThingClas - - + + Set digital output 2 The name of the ActionType ({c7d2f4a8-2b13-4a48-81a8-72f4908c775b}) of ThingClass eightChannelSwitch ---------- @@ -321,52 +376,67 @@ The name of the ActionType ({82a78aed-5994-4af5-aecb-1806be5de1f3}) of ThingClas - + Set digital output 3 The name of the ActionType ({4b2ac595-eba9-4364-8cd7-00ff8bccda5a}) of ThingClass eightChannelSwitch - + Set digital output 4 The name of the ActionType ({bbbd1863-ef04-4687-803d-3c9ccdfc8d8f}) of ThingClass eightChannelSwitch - + Set digital output 5 The name of the ActionType ({50855d2b-a700-4030-8674-fee00cc0b4e2}) of ThingClass eightChannelSwitch - + Set digital output 6 The name of the ActionType ({a91ce593-09ba-4754-8a2e-e3f507313585}) of ThingClass eightChannelSwitch - + Set digital output 7 The name of the ActionType ({5f46047c-b00d-486f-b169-b738fbc89cdb}) of ThingClass eightChannelSwitch - + Set digital output 8 The name of the ActionType ({63334a17-0847-4f53-8007-1b5e72b88aa8}) of ThingClass eightChannelSwitch - + + + Temperature + The name of the ParamType (ThingClass: temperatureSensor, EventType: temperature, ID: {b04ee2a5-9b27-4ffc-9e12-7e05f5a41690}) +---------- +The name of the StateType ({b04ee2a5-9b27-4ffc-9e12-7e05f5a41690}) of ThingClass temperatureSensor + + + + Temperature Sensor The name of the ThingClass ({e13beb24-953c-48b3-9262-7cde31d42ef5}) - - - - + + Temperature changed + The name of the EventType ({b04ee2a5-9b27-4ffc-9e12-7e05f5a41690}) of ThingClass temperatureSensor + + + + + + + Type The name of the ParamType (ThingClass: eightChannelSwitch, Type: thing, ID: {34c8f771-4141-4183-9eaf-becbaf362ac8}) ---------- @@ -377,35 +447,5 @@ The name of the ParamType (ThingClass: singleChannelSwitch, Type: thing, ID: {6e The name of the ParamType (ThingClass: temperatureSensor, Type: thing, ID: {5005822d-6a32-4bb8-9b77-f79da7382f76}) - - - - connected - The name of the ParamType (ThingClass: oneWireInterface, EventType: connected, ID: {d0ded173-c382-4ee3-8e24-3647b4e16afa}) ----------- -The name of the StateType ({d0ded173-c382-4ee3-8e24-3647b4e16afa}) of ThingClass oneWireInterface - - - - - connected changed - The name of the EventType ({d0ded173-c382-4ee3-8e24-3647b4e16afa}) of ThingClass oneWireInterface - - - - - - temperature - The name of the ParamType (ThingClass: temperatureSensor, EventType: temperature, ID: {b04ee2a5-9b27-4ffc-9e12-7e05f5a41690}) ----------- -The name of the StateType ({b04ee2a5-9b27-4ffc-9e12-7e05f5a41690}) of ThingClass temperatureSensor - - - - - temperature changed - The name of the EventType ({b04ee2a5-9b27-4ffc-9e12-7e05f5a41690}) of ThingClass temperatureSensor - - diff --git a/onewire/w1.cpp b/onewire/w1.cpp index 34ea7c11..ccd2ace1 100644 --- a/onewire/w1.cpp +++ b/onewire/w1.cpp @@ -86,7 +86,7 @@ double W1::getTemperature(const QString &address) } return temperature.readLine().toInt()/1000.00; } else { - qCWarning(dcOneWire()) << "Could not find device" << temperatureSensor; + qCWarning(dcOneWire()) << "Could not find device" << temperatureSensor.currentPath(); } return 0; } From 0d16bf6f81d832bdfbaa7cadb7b741d42954737f Mon Sep 17 00:00:00 2001 From: "bernhard.trinnes" Date: Wed, 19 Aug 2020 21:54:36 +0200 Subject: [PATCH 7/8] updated readme --- onewire/README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/onewire/README.md b/onewire/README.md index 71aa816b..f260753d 100644 --- a/onewire/README.md +++ b/onewire/README.md @@ -38,7 +38,8 @@ This integration plugin allows to integrate one-wire devices like temperature se * DS2408 ## Usage - + +### OWFS Interface First step is to setup the "One wire interface". During the device setup it is required to enter the OWFS init arguments. Default arguments are "--i2c=ALL:ALL", means OWFS is about to scan for one-wire bus masters on all I2C interfaces. You can simulate one-wire device with following init argument: "--fake=10,22,28,05" @@ -49,6 +50,10 @@ The "One wire interface" thing has the toggle button to "Auto add one wire devic NOTE: As long as the "Auto add one wire devices" feature is activated you won't be able to manually discover devices. +### W1 Kernel Driver +Install the kernel driver w1. Raspberry Pi users can use rasp-config to enable 'one wire' which enables W1. There are not further steps necessary, temperature sensors will be discovered if the driver has been loaded successfully. + + ## Requirements * The package “nymea-plugin-onewire” must be installed. From 5a5818f078eeb703d10c8b86c4d4482f70ded45b Mon Sep 17 00:00:00 2001 From: "bernhard.trinnes" Date: Mon, 7 Sep 2020 18:51:24 +0200 Subject: [PATCH 8/8] support W1 and OWFS simultaniously --- onewire/integrationpluginonewire.cpp | 125 ++++++++++++++------------- 1 file changed, 66 insertions(+), 59 deletions(-) diff --git a/onewire/integrationpluginonewire.cpp b/onewire/integrationpluginonewire.cpp index e61ccf2b..d3520d23 100644 --- a/onewire/integrationpluginonewire.cpp +++ b/onewire/integrationpluginonewire.cpp @@ -142,22 +142,28 @@ void IntegrationPluginOneWire::setupThing(ThingSetupInfo *info) } else if (thing->thingClassId() == temperatureSensorThingClassId) { - if (!m_w1Interface) { - m_w1Interface = new W1(this); - } - qCDebug(dcOneWire) << "Setup one wire temperature sensor" << thing->params(); QString address = thing->paramValue(temperatureSensorThingAddressParamTypeId).toByteArray(); - if (m_owfsInterface) { //in case the child was setup before the interface - thing->setStateValue(temperatureSensorConnectedStateTypeId, m_owfsInterface->isConnected(address.toUtf8())); - thing->setStateValue(temperatureSensorTemperatureStateTypeId, m_owfsInterface->getTemperature(address.toUtf8())); - return info->finish(Thing::ThingErrorNoError); - } else if (m_w1Interface) { - thing->setStateValue(temperatureSensorConnectedStateTypeId, m_w1Interface->deviceAvailable(address)); - thing->setStateValue(temperatureSensorTemperatureStateTypeId, m_w1Interface->getTemperature(address)); - return info->finish(Thing::ThingErrorNoError); + if (myThings().findById(thing->parentId())->thingClassId() == oneWireInterfaceThingClassId) { + if (m_owfsInterface) { + thing->setStateValue(temperatureSensorConnectedStateTypeId, m_owfsInterface->isConnected(address.toUtf8())); + thing->setStateValue(temperatureSensorTemperatureStateTypeId, m_owfsInterface->getTemperature(address.toUtf8())); + return info->finish(Thing::ThingErrorNoError); + } else { + //OWFS Interface is not yet initialized try a setup in 3 seconds + QTimer::singleShot(3000, this, [this, info]{setupThing(info);}); + } } else { - return info->finish(Thing::ThingErrorHardwareNotAvailable, tr("No 1-Wire interface available")); + if (!m_w1Interface) { + m_w1Interface = new W1(this); + } + if (m_w1Interface->interfaceIsAvailable()) { + thing->setStateValue(temperatureSensorConnectedStateTypeId, m_w1Interface->deviceAvailable(address)); + thing->setStateValue(temperatureSensorTemperatureStateTypeId, m_w1Interface->getTemperature(address)); + return info->finish(Thing::ThingErrorNoError); + } else { + qCWarning(dcOneWire()) << "W1 interface is not available"; + } } } else if (thing->thingClassId() == singleChannelSwitchThingClassId) { @@ -214,71 +220,67 @@ void IntegrationPluginOneWire::executeAction(ThingActionInfo *info) Thing *thing = info->thing(); Action action = info->action(); + if (!m_owfsInterface) { + //All current things with actions require an OWFS interface + info->finish(Thing::ThingErrorHardwareNotAvailable, QT_TR_NOOP("OWFS interface is not available.")); + } + if (thing->thingClassId() == oneWireInterfaceThingClassId) { if (action.actionTypeId() == oneWireInterfaceAutoAddActionTypeId){ thing->setStateValue(oneWireInterfaceAutoAddStateTypeId, action.param(oneWireInterfaceAutoAddActionAutoAddParamTypeId).value()); return info->finish(Thing::ThingErrorNoError); } return info->finish(Thing::ThingErrorActionTypeNotFound); - } - if (thing->thingClassId() == singleChannelSwitchThingClassId) { + } else if (thing->thingClassId() == singleChannelSwitchThingClassId) { if (action.actionTypeId() == singleChannelSwitchDigitalOutputActionTypeId){ m_owfsInterface->setSwitchOutput(thing->paramValue(singleChannelSwitchThingAddressParamTypeId).toByteArray(), Owfs::SwitchChannel::PIO_A, action.param(singleChannelSwitchDigitalOutputActionDigitalOutputParamTypeId).value().toBool()); return info->finish(Thing::ThingErrorNoError); + } else { + return info->finish(Thing::ThingErrorActionTypeNotFound); } - return info->finish(Thing::ThingErrorActionTypeNotFound); - } - - if (thing->thingClassId() == dualChannelSwitchThingClassId) { + } else if (thing->thingClassId() == dualChannelSwitchThingClassId) { if (action.actionTypeId() == dualChannelSwitchDigitalOutput1ActionTypeId){ m_owfsInterface->setSwitchOutput(thing->paramValue(dualChannelSwitchThingAddressParamTypeId).toByteArray(), Owfs::SwitchChannel::PIO_A, action.param(dualChannelSwitchDigitalOutput1ActionDigitalOutput1ParamTypeId).value().toBool()); return info->finish(Thing::ThingErrorNoError); - } - if (action.actionTypeId() == dualChannelSwitchDigitalOutput2ActionTypeId){ + } else if (action.actionTypeId() == dualChannelSwitchDigitalOutput2ActionTypeId){ m_owfsInterface->setSwitchOutput(thing->paramValue(dualChannelSwitchThingAddressParamTypeId).toByteArray(), Owfs::SwitchChannel::PIO_B, action.param(dualChannelSwitchDigitalOutput2ActionDigitalOutput2ParamTypeId).value().toBool()); return info->finish(Thing::ThingErrorNoError); + } else { + return info->finish(Thing::ThingErrorActionTypeNotFound); } - return info->finish(Thing::ThingErrorActionTypeNotFound); - } - - if (thing->thingClassId() == eightChannelSwitchThingClassId) { + } else if (thing->thingClassId() == eightChannelSwitchThingClassId) { if (action.actionTypeId() == eightChannelSwitchDigitalOutput1ActionTypeId){ m_owfsInterface->setSwitchOutput(thing->paramValue(eightChannelSwitchThingAddressParamTypeId).toByteArray(), Owfs::SwitchChannel::PIO_A, action.param(eightChannelSwitchDigitalOutput1ActionDigitalOutput1ParamTypeId).value().toBool()); return info->finish(Thing::ThingErrorNoError); - } - if (action.actionTypeId() == eightChannelSwitchDigitalOutput2ActionTypeId){ + } else if (action.actionTypeId() == eightChannelSwitchDigitalOutput2ActionTypeId){ m_owfsInterface->setSwitchOutput(thing->paramValue(eightChannelSwitchThingAddressParamTypeId).toByteArray(), Owfs::SwitchChannel::PIO_B, action.param(eightChannelSwitchDigitalOutput2ActionDigitalOutput2ParamTypeId).value().toBool()); return info->finish(Thing::ThingErrorNoError); - } - if (action.actionTypeId() == eightChannelSwitchDigitalOutput3ActionTypeId){ + } else if (action.actionTypeId() == eightChannelSwitchDigitalOutput3ActionTypeId){ m_owfsInterface->setSwitchOutput(thing->paramValue(eightChannelSwitchThingAddressParamTypeId).toByteArray(), Owfs::SwitchChannel::PIO_C, action.param(eightChannelSwitchDigitalOutput3ActionDigitalOutput3ParamTypeId).value().toBool()); return info->finish(Thing::ThingErrorNoError); - } - if (action.actionTypeId() == eightChannelSwitchDigitalOutput4ActionTypeId){ + } else if (action.actionTypeId() == eightChannelSwitchDigitalOutput4ActionTypeId){ m_owfsInterface->setSwitchOutput(thing->paramValue(eightChannelSwitchThingAddressParamTypeId).toByteArray(), Owfs::SwitchChannel::PIO_D, action.param(eightChannelSwitchDigitalOutput4ActionDigitalOutput4ParamTypeId).value().toBool()); return info->finish(Thing::ThingErrorNoError); - } - if (action.actionTypeId() == eightChannelSwitchDigitalOutput5ActionTypeId){ + } else if (action.actionTypeId() == eightChannelSwitchDigitalOutput5ActionTypeId){ m_owfsInterface->setSwitchOutput(thing->paramValue(eightChannelSwitchThingAddressParamTypeId).toByteArray(), Owfs::SwitchChannel::PIO_E, action.param(eightChannelSwitchDigitalOutput5ActionDigitalOutput5ParamTypeId).value().toBool()); return info->finish(Thing::ThingErrorNoError); - } - if (action.actionTypeId() == eightChannelSwitchDigitalOutput6ActionTypeId){ + } else if (action.actionTypeId() == eightChannelSwitchDigitalOutput6ActionTypeId){ m_owfsInterface->setSwitchOutput(thing->paramValue(eightChannelSwitchThingAddressParamTypeId).toByteArray(), Owfs::SwitchChannel::PIO_F, action.param(eightChannelSwitchDigitalOutput6ActionDigitalOutput6ParamTypeId).value().toBool()); return info->finish(Thing::ThingErrorNoError); - } - if (action.actionTypeId() == eightChannelSwitchDigitalOutput7ActionTypeId){ + } else if (action.actionTypeId() == eightChannelSwitchDigitalOutput7ActionTypeId){ m_owfsInterface->setSwitchOutput(thing->paramValue(eightChannelSwitchThingAddressParamTypeId).toByteArray(), Owfs::SwitchChannel::PIO_G, action.param(eightChannelSwitchDigitalOutput7ActionDigitalOutput7ParamTypeId).value().toBool()); return info->finish(Thing::ThingErrorNoError); - } - if (action.actionTypeId() == eightChannelSwitchDigitalOutput8ActionTypeId){ + } else if (action.actionTypeId() == eightChannelSwitchDigitalOutput8ActionTypeId){ m_owfsInterface->setSwitchOutput(thing->paramValue(eightChannelSwitchThingAddressParamTypeId).toByteArray(), Owfs::SwitchChannel::PIO_H, action.param(eightChannelSwitchDigitalOutput8ActionDigitalOutput8ParamTypeId).value().toBool()); return info->finish(Thing::ThingErrorNoError); + } else { + return info->finish(Thing::ThingErrorActionTypeNotFound); } - return info->finish(Thing::ThingErrorActionTypeNotFound); + } else { + return info->finish(Thing::ThingErrorNoError); } - return info->finish(Thing::ThingErrorNoError); } @@ -311,37 +313,42 @@ void IntegrationPluginOneWire::onPluginTimer() if (thing->stateValue(oneWireInterfaceAutoAddStateTypeId).toBool()) { m_owfsInterface->discoverDevices(); } - } - - if (thing->thingClassId() == temperatureSensorThingClassId) { + } else if (thing->thingClassId() == temperatureSensorThingClassId) { QByteArray address = thing->paramValue(temperatureSensorThingAddressParamTypeId).toByteArray(); double temperature = 0; bool connected = false; - if (m_owfsInterface) { - temperature = m_owfsInterface->getTemperature(address); - connected = m_owfsInterface->isConnected(address); - } else if (m_w1Interface) { - temperature = m_w1Interface->getTemperature(address); - connected = m_w1Interface->deviceAvailable(address); + + if (myThings().findById(thing->parentId())->thingClassId() == oneWireInterfaceThingClassId) { + if (m_owfsInterface) { + temperature = m_owfsInterface->getTemperature(address); + connected = m_owfsInterface->isConnected(address); + } else { + qCWarning(dcOneWire()) << "onPlugInTimer: OWFS interface not setup yet for thing" << thing->name(); + } + + } else { + temperature = m_w1Interface->getTemperature(address); + connected = m_w1Interface->deviceAvailable(address); } + thing->setStateValue(temperatureSensorTemperatureStateTypeId, temperature); thing->setStateValue(temperatureSensorConnectedStateTypeId, connected); - } - - if (thing->thingClassId() == singleChannelSwitchThingClassId) { + } else if (thing->thingClassId() == singleChannelSwitchThingClassId) { + if (!m_owfsInterface) + continue; QByteArray address = thing->paramValue(singleChannelSwitchThingAddressParamTypeId).toByteArray(); thing->setStateValue(singleChannelSwitchDigitalOutputStateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_A)); thing->setStateValue(singleChannelSwitchConnectedStateTypeId, m_owfsInterface->isConnected(address)); - } - - if (thing->thingClassId() == dualChannelSwitchThingClassId) { + } else if (thing->thingClassId() == dualChannelSwitchThingClassId) { + if (!m_owfsInterface) + continue; QByteArray address = thing->paramValue(dualChannelSwitchThingAddressParamTypeId).toByteArray(); thing->setStateValue(dualChannelSwitchDigitalOutput1StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_A)); thing->setStateValue(dualChannelSwitchDigitalOutput2StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_B)); thing->setStateValue(dualChannelSwitchConnectedStateTypeId, m_owfsInterface->isConnected(address)); - } - - if (thing->thingClassId() == eightChannelSwitchThingClassId) { + } else if (thing->thingClassId() == eightChannelSwitchThingClassId) { + if (!m_owfsInterface) + continue; QByteArray address = thing->paramValue(eightChannelSwitchThingAddressParamTypeId).toByteArray(); thing->setStateValue(eightChannelSwitchDigitalOutput1StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_A)); thing->setStateValue(eightChannelSwitchDigitalOutput2StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_B));