Experiment with binding and attribute report configuration
This commit is contained in:
parent
18d607319e
commit
16bc4684e1
@ -400,9 +400,9 @@ void ZigbeeManager::addNetwork(ZigbeeNetwork *network)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ZigbeeNodeInitializer *nodeInitializer = m_zigbeeNodeInitializers.value(network->networkUuid());
|
ZigbeeNodeInitializer *nodeInitializer = m_zigbeeNodeInitializers.value(network->networkUuid());
|
||||||
// nodeInitializer->initializeNode(node);
|
nodeInitializer->initializeNode(node);
|
||||||
// TODO: emit node added once initialized so the plugins can use it
|
//TODO: emit node added once initialized so the plugins can use it
|
||||||
|
|
||||||
emit nodeAdded(network->networkUuid(), node);
|
emit nodeAdded(network->networkUuid(), node);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -39,6 +39,7 @@ ZigbeeNodeInitializer::ZigbeeNodeInitializer(ZigbeeNetwork *network, QObject *pa
|
|||||||
QObject(parent),
|
QObject(parent),
|
||||||
m_network(network)
|
m_network(network)
|
||||||
{
|
{
|
||||||
|
// Bind the coordinator to group 0x0000
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,38 +47,54 @@ void ZigbeeNodeInitializer::initializeNode(ZigbeeNode *node)
|
|||||||
{
|
{
|
||||||
qCDebug(dcZigbee()) << "Start initializing node internally" << node;
|
qCDebug(dcZigbee()) << "Start initializing node internally" << node;
|
||||||
|
|
||||||
|
m_network->coordinatorNode()->deviceObject()->requestBindShortAddress(0x01, ZigbeeClusterLibrary::ClusterIdOnOff, 0x0000);
|
||||||
|
|
||||||
|
|
||||||
// Initialize and configure server clusters
|
// Initialize and configure server clusters
|
||||||
foreach (ZigbeeNodeEndpoint *endpoint, node->endpoints()) {
|
foreach (ZigbeeNodeEndpoint *endpoint, node->endpoints()) {
|
||||||
// Configure attribute reporting
|
// Configure attribute reporting
|
||||||
if (endpoint->hasInputCluster(ZigbeeClusterLibrary::ClusterIdPowerConfiguration)) {
|
if (endpoint->hasInputCluster(ZigbeeClusterLibrary::ClusterIdPowerConfiguration)) {
|
||||||
|
|
||||||
// Read current battery remaining
|
// Read current battery remaining
|
||||||
|
qCDebug(dcZigbee()) << "Read power configuration cluster attributes" << node;
|
||||||
ZigbeeClusterReply *readAttributeReply = endpoint->getInputCluster(ZigbeeClusterLibrary::ClusterIdPowerConfiguration)->readAttributes({ZigbeeClusterPowerConfiguration::AttributeBatteryPercentageRemaining});
|
ZigbeeClusterReply *readAttributeReply = endpoint->getInputCluster(ZigbeeClusterLibrary::ClusterIdPowerConfiguration)->readAttributes({ZigbeeClusterPowerConfiguration::AttributeBatteryPercentageRemaining});
|
||||||
connect(readAttributeReply, &ZigbeeClusterReply::finished, this, [this, node, readAttributeReply](){
|
connect(readAttributeReply, &ZigbeeClusterReply::finished, node, [=](){
|
||||||
if (readAttributeReply->error() != ZigbeeClusterReply::ErrorNoError) {
|
if (readAttributeReply->error() != ZigbeeClusterReply::ErrorNoError) {
|
||||||
qCWarning(dcZigbee()) << "Failed to read power cluster attributes" << readAttributeReply->error();
|
qCWarning(dcZigbee()) << "Failed to read power cluster attributes" << readAttributeReply->error();
|
||||||
emit nodeInitialized(node);
|
//emit nodeInitialized(node);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
});
|
qCDebug(dcZigbee()) << "Read power configuration cluster attributes finished successfully";
|
||||||
|
|
||||||
|
// Bind the cluster to the coordinator
|
||||||
|
qCDebug(dcZigbee()) << "Bind power configuration cluster to coordinaotr";
|
||||||
|
ZigbeeDeviceObjectReply * zdoReply = node->deviceObject()->requestBindIeeeAddress(endpoint->endpointId(), ZigbeeClusterLibrary::ClusterIdPowerConfiguration, m_network->coordinatorNode()->extendedAddress(), 0x01);
|
||||||
|
connect(zdoReply, &ZigbeeDeviceObjectReply::finished, node, [=](){
|
||||||
|
if (zdoReply->error() != ZigbeeDeviceObjectReply::ErrorNoError) {
|
||||||
|
qCWarning(dcZigbee()) << "Failed to bind power cluster to coordinator" << readAttributeReply->error();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
qCDebug(dcZigbee()) << "Bind power configuration cluster to coordinaotr finished successfully";
|
||||||
|
|
||||||
// Configure attribute rporting for battery remaining
|
// Configure attribute rporting for battery remaining
|
||||||
ZigbeeClusterLibrary::AttributeReportingConfiguration reportingConfig;
|
ZigbeeClusterLibrary::AttributeReportingConfiguration reportingConfig;
|
||||||
reportingConfig.attributeId = ZigbeeClusterPowerConfiguration::AttributeBatteryPercentageRemaining;
|
reportingConfig.attributeId = ZigbeeClusterPowerConfiguration::AttributeBatteryPercentageRemaining;
|
||||||
reportingConfig.dataType = Zigbee::Uint8;
|
reportingConfig.dataType = Zigbee::Uint8;
|
||||||
reportingConfig.minReportingInterval = 300;
|
reportingConfig.minReportingInterval = 300;
|
||||||
reportingConfig.maxReportingInterval = 2700;
|
reportingConfig.maxReportingInterval = 2700;
|
||||||
reportingConfig.reportableChange = ZigbeeDataType(static_cast<quint8>(1)).data();
|
reportingConfig.reportableChange = ZigbeeDataType(static_cast<quint8>(14)).data();
|
||||||
|
|
||||||
ZigbeeClusterReply *reportingReply = endpoint->getInputCluster(ZigbeeClusterLibrary::ClusterIdPowerConfiguration)->configureReporting({reportingConfig});
|
qCDebug(dcZigbee()) << "Configure attribute reporting for power configuration cluster to coordinator";
|
||||||
connect(reportingReply, &ZigbeeClusterReply::finished, this, [reportingReply](){
|
ZigbeeClusterReply *reportingReply = endpoint->getInputCluster(ZigbeeClusterLibrary::ClusterIdPowerConfiguration)->configureReporting({reportingConfig});
|
||||||
if (reportingReply->error() != ZigbeeClusterReply::ErrorNoError) {
|
connect(reportingReply, &ZigbeeClusterReply::finished, this, [reportingReply](){
|
||||||
qCWarning(dcZigbee()) << "Failed to read power cluster attributes" << reportingReply->error();
|
if (reportingReply->error() != ZigbeeClusterReply::ErrorNoError) {
|
||||||
return;
|
qCWarning(dcZigbee()) << "Failed to read power cluster attributes" << reportingReply->error();
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
qCDebug(dcZigbee()) << "Reporting config finished" << ZigbeeClusterLibrary::parseAttributeReportingStatusRecords(reportingReply->responseFrame().payload);
|
qCDebug(dcZigbee()) << "Reporting config finished" << ZigbeeClusterLibrary::parseAttributeReportingStatusRecords(reportingReply->responseFrame().payload);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -88,7 +105,7 @@ void ZigbeeNodeInitializer::initializeNode(ZigbeeNode *node)
|
|||||||
|
|
||||||
if (endpoint->hasOutputCluster(ZigbeeClusterLibrary::ClusterIdOnOff)) {
|
if (endpoint->hasOutputCluster(ZigbeeClusterLibrary::ClusterIdOnOff)) {
|
||||||
// Bind command
|
// Bind command
|
||||||
ZigbeeDeviceObjectReply *zdoReply = node->deviceObject()->requestBindIeeeAddress(endpoint->endpointId(), ZigbeeClusterLibrary::ClusterIdOnOff, m_network->coordinatorNode()->extendedAddress(), 0x01);
|
ZigbeeDeviceObjectReply *zdoReply = node->deviceObject()->requestBindShortAddress(endpoint->endpointId(), ZigbeeClusterLibrary::ClusterIdOnOff, m_network->coordinatorNode()->shortAddress());
|
||||||
connect(zdoReply, &ZigbeeDeviceObjectReply::finished, this, [zdoReply](){
|
connect(zdoReply, &ZigbeeDeviceObjectReply::finished, this, [zdoReply](){
|
||||||
if (zdoReply->error() != ZigbeeDeviceObjectReply::ErrorNoError) {
|
if (zdoReply->error() != ZigbeeDeviceObjectReply::ErrorNoError) {
|
||||||
qCWarning(dcZigbee()) << "Failed to bind OnOff cluster attributes" << zdoReply->error();
|
qCWarning(dcZigbee()) << "Failed to bind OnOff cluster attributes" << zdoReply->error();
|
||||||
@ -99,7 +116,7 @@ void ZigbeeNodeInitializer::initializeNode(ZigbeeNode *node)
|
|||||||
|
|
||||||
if (endpoint->hasOutputCluster(ZigbeeClusterLibrary::ClusterIdLevelControl)) {
|
if (endpoint->hasOutputCluster(ZigbeeClusterLibrary::ClusterIdLevelControl)) {
|
||||||
// Bind command
|
// Bind command
|
||||||
ZigbeeDeviceObjectReply *zdoReply = node->deviceObject()->requestBindIeeeAddress(endpoint->endpointId(), ZigbeeClusterLibrary::ClusterIdLevelControl, m_network->coordinatorNode()->extendedAddress(), 0x01);
|
ZigbeeDeviceObjectReply *zdoReply = node->deviceObject()->requestBindShortAddress(endpoint->endpointId(), ZigbeeClusterLibrary::ClusterIdLevelControl, m_network->coordinatorNode()->shortAddress());
|
||||||
connect(zdoReply, &ZigbeeDeviceObjectReply::finished, this, [this, node, zdoReply](){
|
connect(zdoReply, &ZigbeeDeviceObjectReply::finished, this, [this, node, zdoReply](){
|
||||||
if (zdoReply->error() != ZigbeeDeviceObjectReply::ErrorNoError) {
|
if (zdoReply->error() != ZigbeeDeviceObjectReply::ErrorNoError) {
|
||||||
qCWarning(dcZigbee()) << "Failed to bind Level cluster attributes" << zdoReply->error();
|
qCWarning(dcZigbee()) << "Failed to bind Level cluster attributes" << zdoReply->error();
|
||||||
|
|||||||
Reference in New Issue
Block a user