Skip to content

Commit

Permalink
Merge branch 'fix/matter_controller_invoke_cmd_structure' into 'master'
Browse files Browse the repository at this point in the history
matter_controller:updated the json parsing for invoke command structure changes

See merge request app-frameworks/esp-rainmaker!421
  • Loading branch information
dhrishi committed Feb 1, 2024
2 parents eaa455d + 8a201e0 commit 909c7f0
Show file tree
Hide file tree
Showing 9 changed files with 164 additions and 179 deletions.
3 changes: 1 addition & 2 deletions examples/matter/matter_controller/main/app_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@ void on_device_list_update()

static void send_toggle_command(intptr_t context)
{
const char* cmd_data[] = { "0x6" /* on-off-cluster*/, "0x2" /* toggle */ };
if (s_selected_device) {
esp_matter::controller::send_invoke_cluster_command(s_selected_device->node_id, s_selected_device->endpoints[0].endpoint_id,
2, (char**)cmd_data);
OnOff::Id, OnOff::Commands::Toggle::Id, NULL);
}
}

Expand Down
16 changes: 8 additions & 8 deletions examples/matter/matter_controller_on_esp32_s3_box/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,26 @@

```
$ cd $RMAKER_PATH/cli
$ ./rainmaker.py login --email <rainmaker-account-email>
$ ./rainmaker.py getparams <rainmaker-node-id-of-controller>
$ ./rainmaker.py login --email <rainmaker-account-email>
$ ./rainmaker.py getparams <rainmaker-node-id-of-controller>
```
**Note**:
**Note**:
1) Please use the same account credentials that are used to claim the controller and signed into the Rainmaker app.
2) Get the rainmaker-node-id-of-controller by logging into [ESP Rainmaker Dashboard](https://dashboard.rainmaker.espressif.com/login).
2) Get the rainmaker-node-id-of-controller by logging into [ESP Rainmaker Dashboard](https://dashboard.rainmaker.espressif.com/login).

## Controlling the devices remotely using rainmaker cli:

```
$ cd $RMAKER_PATH/cli
$ ./rainmaker.py login --email <rainmaker-account-email>
$ ./rainmaker.py login --email <rainmaker-account-email>
```
_Toggle command:_
```
$ ./rainmaker.py setparams --data '{"matter-controller":{"matter-controller-data":{"matter-nodes":[{"matter-node-id": "<matter-node-id-of-device>","endpoints":[{"endpoint-id":"0x1","clusters":[{"cluster-id":"0x6","commands":[{"command-id":"0x2"}]}]}]}]}}}' <rainmaker-node-id-of-controller>
$ ./rainmaker.py setparams --data '{"Matter-Controller":{"Matter-Devices":{"matter-nodes":[{"matter-node-id":"<matter-node-id-of-device>","endpoints":[{"endpoint-id":"0x1","clusters":[{"cluster-id":"0x6","commands":[{"command-id":"0x2"}]}]}]}]}}}' <rainmaker-node-id-of-controller>
```
_Set Brightness command:_
```
./rainmaker.py setparams --data '{"matter-controller":{"matter-controller-data":{"matter-nodes":[{"matter-node-id":"<matter-node-id-of-device>","endpoints":[{"endpoint-id":"0x1","clusters":[{"cluster-id":"0x8","commands":[{"command-id":"0x0","data":{"0":"10","1":"0","2":"0","3":"0"}}]}]}]}]}}}' <rainmaker-node-id-of-controller>
$ ./rainmaker.py setparams --data '{"Matter-Controller":{"Matter-Devices":{"matter-nodes":[{"matter-node-id":"<matter-node-id-of-device>","endpoints":[{"endpoint-id":"0x1","clusters":[{"cluster-id":"0x8","commands":[{"command-id":"0x0","data":{"0:U8": 10, "1:U16": 0, "2:U8": 0, "3:U8": 0}}]}]}]}]}}}' <rainmaker-node-id-of-controller>
```
**Note**:
**Note**:
1) Get the matter-node-id-of-device from the details reported by the controller using getparams command.
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,9 @@ static void send_command_cb(intptr_t arg)
{
device_list_lock my_device_lock;
node_endpoint_id_list_t *ptr = (node_endpoint_id_list_t *)arg;
const char *cmd_data[] = {"0x6" /* on-off-cluster*/, "0x2" /* toggle */};
if (ptr) {
ESP_LOGI(TAG, "send command to node %llx endpoint %d", ptr->node_id, ptr->endpoint_id);
esp_matter::controller::send_invoke_cluster_command(ptr->node_id, ptr->endpoint_id, 2, (char **)cmd_data);
esp_matter::controller::send_invoke_cluster_command(ptr->node_id, ptr->endpoint_id,OnOff::Id, OnOff::Commands::Toggle::Id, NULL);
} else
ESP_LOGE(TAG, "send command with null ptr");
}
Expand Down Expand Up @@ -526,7 +525,7 @@ void read_dev_info(void)
std::vector<uint64_t> nid_list;
node_endpoint_id_list_t *dev_ptr = device_to_control.dev_list;
while (dev_ptr) {
//if (dev_ptr->is_Rainmaker_device && dev_ptr->is_online && !dev_ptr->is_subscribed)
//if (dev_ptr->is_Rainmaker_device && dev_ptr->is_online && !dev_ptr->is_subscribed)
//{
//chip::DeviceLayer::PlatformMgr().ScheduleWork(_read_device_state, (intptr_t)dev_ptr);
//dev_ptr->is_subscribed = true;
Expand All @@ -535,7 +534,7 @@ void read_dev_info(void)
ESP_LOGI(TAG,"\nnodeid-> %llx\n",dev_ptr->node_id);
dev_ptr = dev_ptr->next;
}

read_node_info(nid_list);

nid_list.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ typedef void *app_driver_handle_t;
* This initializes the button driver associated with the selected board.
*
* @param[in] user_data Custom user data that will be used in button toggle callback.
*
*
* @return Handle on success.
* @return NULL in case of failure.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,24 @@ using namespace chip::app::Clusters;
static const char *TAG = "controller-ctrl";


static void send_command_cb(intptr_t arg)
static void send_command_cb(intptr_t arg)
{
send_cmd_format*ptr = (send_cmd_format *)arg;
// const char *cmd_data[] = { "0x6"/* on-off-cluster*/, "0x2" /* toggle */};

const char* cmd_data_cstr[ptr->cmd_data.size()];
if(ptr->cmd_data)
ESP_LOGI(TAG,"\ncmd_data: %s\n",ptr->cmd_data);

for (size_t i = 0; i < ptr->cmd_data.size(); ++i)
{
cmd_data_cstr[i] = ptr->cmd_data[i].c_str();
ESP_LOGI(TAG,"\ndata: %d : %s\n",i,cmd_data_cstr[i]);
}

if (ptr) {
ESP_LOGI(TAG, "send command to node %llx endpoint %d", ptr->node_id, ptr->endpoint_id);
esp_matter::controller::send_invoke_cluster_command(ptr->node_id, ptr->endpoint_id, ptr->cmd_data.size(), (char **)cmd_data_cstr);
ESP_LOGI(TAG, "send command to node %llx endpoint %d cluster %d command %d", ptr->node_id, ptr->endpoint_id, ptr->cluster_id, ptr->command_id);
esp_matter::controller::send_invoke_cluster_command(ptr->node_id, ptr->endpoint_id, ptr->cluster_id, ptr->command_id, ptr->cmd_data);
}
else
ESP_LOGE(TAG, "send command with null ptr");

ptr->cmd_data.clear();
free(ptr);
delete ptr;
}

void send_command(intptr_t arg)
CHIP_ERROR send_command(intptr_t arg)
{
chip::DeviceLayer::PlatformMgr().ScheduleWork(send_command_cb, arg);
return chip::DeviceLayer::PlatformMgr().ScheduleWork(send_command_cb, arg);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <vector>
#include <string.h>
#include <esp_system.h>
#include <esp_matter.h>
#include <esp_rmaker_work_queue.h>
#include <esp_rmaker_core.h>
#include <esp_rmaker_standard_types.h>
Expand All @@ -12,19 +13,31 @@ typedef struct send_command_format
{
uint64_t node_id;
uint16_t endpoint_id;
std::vector<std::string> cmd_data;
uint32_t cluster_id;
uint32_t command_id;
char* cmd_data;

send_command_format(uint64_t remote_nodeid, uint16_t endpointid, std::vector<std::string> cmd)
send_command_format(uint64_t remote_nodeid, uint16_t endpointid,uint32_t clusterid, uint32_t commandid, char* cmd)
{
this->node_id = remote_nodeid;
this->endpoint_id = endpointid;
for(std::string str: cmd)
this->cluster_id = clusterid;
this->command_id = commandid;
this->cmd_data = NULL;
if(cmd!= NULL)
{
this->cmd_data.push_back(str);
this->cmd_data = new char[strlen(cmd) + 1];
strcpy(this->cmd_data, cmd);
}

}

~send_command_format()
{
delete[] this->cmd_data;
}

}send_cmd_format;


void send_command(intptr_t arg);
CHIP_ERROR send_command(intptr_t arg);
Loading

0 comments on commit 909c7f0

Please sign in to comment.