Skip to content

Commit

Permalink
Pull request #483: Cli command to publish Unify Matter Bridge QR Code…
Browse files Browse the repository at this point in the history
… on MQTT

Merge in WMN_TOOLS/matter from cli_qr to silabs

Squashed commit of the following:

commit c2ad672b85c3f7e00c4f0b5ba09e3529eee1aabe
Author: Milind Dumbare <[email protected]>
Date:   Tue Jan 10 09:01:19 2023 +0100

    Correct the Attribute reading for endpoint 1 and 0

commit 7ef48ec0040712ea4a67450530fb793858279b4f
Author: Milind Dumbare <[email protected]>
Date:   Mon Jan 9 13:52:49 2023 +0100

    Cli command to publish Unify Matter Bridge QR Code on MQTT
  • Loading branch information
Milind Dumbare authored and jmartinez-silabs committed Oct 17, 2023
1 parent cac696c commit 2319209
Show file tree
Hide file tree
Showing 25 changed files with 36,623 additions and 34,103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
#include "app/server/Server.h"
#include "group_command_translator.hpp"
#include "matter_node_state_monitor.hpp"
#include "matter_bridge_qrcode_publisher.hpp"
#include <iostream>

using namespace chip;
using namespace unify::matter_bridge;
static matter_node_state_monitor * node_state_monitor = NULL;
static group_translator * group_mapping_instance = NULL;
static QRCodePublisher * qr_code_publisher = NULL;

#define LOG_TAG "matter_bridge_cli"

Expand All @@ -43,12 +45,22 @@ static sl_status_t close_commission_cli_func(const handle_args_t & arg)
return SL_STATUS_OK;
}

void set_qr_code_publisher(QRCodePublisher & p)
{
qr_code_publisher = &p;
}
void set_mapping_display_instance(matter_node_state_monitor & n, group_translator & m)
{
node_state_monitor = &n;
group_mapping_instance = &m;
}

static sl_status_t qr_code_publish_cli_func(const handle_args_t & arg)
{
qr_code_publisher->publish();
return SL_STATUS_OK;
}

static sl_status_t epmap_cli_func(const handle_args_t & arg)
{
sl_log_debug(LOG_TAG, "epmap_cli_func");
Expand All @@ -73,6 +85,7 @@ command_map_t unify_cli_commands = {
{ "commission", { "Open commissioning window", commission_cli_func } },
{ "closecommission", { "Close the commissioning window", close_commission_cli_func } },
{ "epmap", { "Show endpoint map", epmap_cli_func } },
{ "qr_code_publish", { "Publish Unify Matter Bridge QR code", qr_code_publish_cli_func} },
{ "groups_map", { "Show Matter vs Unify groups map", groups_map_cli_func } },
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "matter.h"
#include "matter_node_state_monitor.hpp"
#include "sl_status.h"
#include "matter_bridge_qrcode_publisher.hpp"

using namespace unify::matter_bridge;
/**
Expand All @@ -30,3 +31,4 @@ sl_status_t matter_bridge_cli_init();
* --> The group_translator instance is for group mapping display
*/
void set_mapping_display_instance(matter_node_state_monitor & n, group_translator & m);
void set_qr_code_publisher(QRCodePublisher & p);
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ int main(int argc, char * argv[])
TemperatureMeasurementAttributeAccess temperature_measurement_attribute_access(node_state_monitor, unify_mqtt_handler);

QRCodePublisher qr_code_publisher(unify_mqtt_handler);
set_qr_code_publisher(qr_code_publisher);

matter_running = true;
auto handle = run_unify();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
#include "app/server/OnboardingCodesUtil.h"
#include "setup_payload/QRCodeSetupPayloadGenerator.h"
#include "Options.h"
#include "sl_log.h"

constexpr const char * LOG_TAG = "unify_matter_bridge_qr_code_publisher";


namespace unify::matter_bridge {

Expand All @@ -28,6 +32,7 @@ QRCodePublisher::QRCodePublisher(UnifyMqtt& unify_mqtt ) : m_unify_mqtt(unify_mq

void QRCodePublisher::device_event(const chip::DeviceLayer::ChipDeviceEvent * event, intptr_t ptr) {

sl_log_debug(LOG_TAG, "device_event:%u", (unsigned int)event->Type);
switch(event->Type) {
case chip::DeviceLayer::DeviceEventType::kDnssdPlatformInitialized:
if(chip::Server::GetInstance().GetCommissioningWindowManager().IsCommissioningWindowOpen()) {
Expand All @@ -45,6 +50,7 @@ void QRCodePublisher::device_event(const chip::DeviceLayer::ChipDeviceEvent * ev
}

void QRCodePublisher::publish() {
sl_log_debug(LOG_TAG, "Publishing QR Code");
auto qrCode_str = qrcode();
if(!qrCode_str.empty()) {
m_unify_mqtt.Publish(
Expand All @@ -56,6 +62,7 @@ void QRCodePublisher::publish() {
}

void QRCodePublisher::unretain() {
sl_log_debug(LOG_TAG, "Unretaining QR Code");
auto qrCode_str = qrcode();
if(!qrCode_str.empty()) {
m_unify_mqtt.Publish("ucl/SmartStart/CommissionableDevice/"+qrCode_str,"",false);
Expand All @@ -72,4 +79,4 @@ std::string QRCodePublisher::qrcode() {
return "";
}
}
}
}
Loading

0 comments on commit 2319209

Please sign in to comment.