<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Implementation of Zigbee cli function calls in Shell</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/89059/implementation-of-zigbee-cli-function-calls-in-shell</link><description>Hello Support, 
 For my Zigbee Coordinator development I use nrf Connect SDK 1.9.1 (for now), and VS, I like using Kconfig GUI as much as possible. 
 I&amp;#39;m trying to find some reference or documentation that shows the BDB START (as example) shell commands</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 23 Jun 2022 11:31:08 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/89059/implementation-of-zigbee-cli-function-calls-in-shell" /><item><title>RE: Implementation of Zigbee cli function calls in Shell</title><link>https://devzone.nordicsemi.com/thread/373918?ContentTypeID=1</link><pubDate>Thu, 23 Jun 2022 11:31:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:38ca4341-6a73-4daa-b7b3-f76a4554b5aa</guid><dc:creator>Sigurd Hellesvik</dc:creator><description>&lt;p&gt;Hi Jørgen&lt;/p&gt;
&lt;p&gt;See the last comment of Marte:&lt;/p&gt;
[quote user="Marte.M"]I will be out of office for a few weeks, so if you have any more issues or questions regarding this case please create a new ticket and link to this one. Thank you![/quote]
&lt;p&gt;Regards,&lt;br /&gt;Sigurd Hellesvik&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Implementation of Zigbee cli function calls in Shell</title><link>https://devzone.nordicsemi.com/thread/373084?ContentTypeID=1</link><pubDate>Fri, 17 Jun 2022 15:29:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f667630e-1797-4940-a811-e96ec2f8fc8d</guid><dc:creator>JorgenM</dc:creator><description>&lt;p&gt;Thanks Marte,&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;Wow, it looks to be quite complicated to add function calls but your directions and explanation will help a lot, thanks!&lt;br /&gt;One can probably do an educated guess to find the shell commands and associated function calls but wanted to make sure I didn&amp;#39;t miss something.&lt;br /&gt;Thanks for the &amp;quot;bdb_c stop&amp;quot; example how to add a command. I will give this a try.&lt;/p&gt;
&lt;p&gt;Just a general question: &lt;br /&gt;Am I doing something very different from others how to implement a coordinator (using shell and cli)&amp;nbsp; or is this what everyone is spending time on coding?&lt;br /&gt;Seem like many of the &amp;quot;hooks&amp;quot; are missing to really utilize the Zigbee stack capabilities without a lot of custom coding?&lt;/p&gt;
&lt;p&gt;If there is a easier/better way feel free to suggest it.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;Have a great time off &amp;amp; Glad Midsummer,&lt;br /&gt;&lt;br /&gt;Jorgen&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Implementation of Zigbee cli function calls in Shell</title><link>https://devzone.nordicsemi.com/thread/373072?ContentTypeID=1</link><pubDate>Fri, 17 Jun 2022 14:25:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2052be73-e5b2-4d37-be5b-e05179b018f5</guid><dc:creator>Marte Myrvold</dc:creator><description>&lt;p&gt;Hi Jorgen,&lt;/p&gt;
&lt;p&gt;I will be out of office for a few weeks, so if you have any more issues or questions regarding this case please create a new ticket and link to this one. Thank you!&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Marte&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Implementation of Zigbee cli function calls in Shell</title><link>https://devzone.nordicsemi.com/thread/372941?ContentTypeID=1</link><pubDate>Fri, 17 Jun 2022 07:57:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d16bdbb3-966e-481f-b840-1a6db4991128</guid><dc:creator>Marte Myrvold</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;Jorgen,&lt;/p&gt;
[quote user=""]I&amp;#39;m trying to find some reference or documentation that shows the BDB START (as example) shell commands and what it actually calls.[/quote]
&lt;p&gt;As you say, the documentation does not explicitly state what this command does or calls, so you must look in the Zigbee shell library code.&amp;nbsp;The bdb commands are in&amp;nbsp;zigbee_cli_cmd_bdb.c, and &amp;quot;bdb start&amp;quot; calls the function cmd_zb_start(), as you can see&amp;nbsp;here:&amp;nbsp;&lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/v1.9.1/subsys/zigbee/cli/zigbee_cli_cmd_bdb.c#L285"&gt;https://github.com/nrfconnect/sdk-nrf/blob/v1.9.1/subsys/zigbee/cli/zigbee_cli_cmd_bdb.c#L285&lt;/a&gt;. This function first check if the Zigbee stack is started or not, and if not it will set the channel and role of the device, and then start the Zigbee stack. If the stack is started the command will repoen the network (start commissioning) by calling&amp;nbsp;bdb_start_top_level_commissioning().&amp;nbsp;&lt;/p&gt;
[quote user=""]So when people (Marte suggestion in other ticket) say &amp;quot;use the function call&amp;quot;&amp;nbsp;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/zboss/3.11.1.0/group__zboss__bdb__comm__start.html#gaff7aef66e3cd632ce7c144fc3faa1a27"&gt;zb_bdb_close_network()&lt;/a&gt;&amp;nbsp;as example, what is the actual bdb command?&lt;br /&gt;It does not show in Nordic Coordinator example using 1.9.1 SDK in shell bdb commands.&lt;br /&gt;Looks like I have to add this function?[/quote]
&lt;p&gt;You are correct. There is no shell command for stopping the network, so you must implement it yourself, by either adding the command as a subcommand in zigbee_cli_cmd_bdb.c or create a new file and create the command there. The latter is probably the cleanest option since you should avoid making changes to the library files. Lucky for you I decided to do just that:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#include &amp;lt;string.h&amp;gt;
#include &amp;lt;shell/shell.h&amp;gt;
#include &amp;lt;zboss_api.h&amp;gt;
#include &amp;lt;zigbee/zigbee_error_handler.h&amp;gt;
#include &amp;lt;zb_nrf_platform.h&amp;gt;
#include &amp;quot;zigbee_cli.h&amp;quot;
#include &amp;quot;zigbee_cli_utils.h&amp;quot;


/**@brief Stop bdb top level commissioning process.
 *
 * @code
 * &amp;gt; bdb_c stop
 * Commissioning stopped
 * Done
 * @endcode
 * 
 * @pre Only after @ref start &amp;quot;bdb start&amp;quot;.
 * 
 * Will stop cinnussioning by broadcasting a Mgmt_Permit_Joining_req with PermitDuration of 0.
 * See Base Device Behaviour specification for details.
 */

static int cmd_zb_stop(const struct shell *shell, size_t argc, char **argv)
{
	ARG_UNUSED(argc);
	ARG_UNUSED(argv);

	zb_bool_t ret = ZB_TRUE;

    if ((!zigbee_is_stack_started())) {
        zb_cli_print_error(shell, &amp;quot;Stack is not started&amp;quot;,
					   ZB_FALSE);
		return -ENOEXEC;
    }

    ret = zb_bdb_close_network(NULL);
    if (ret != RET_OK)
    {
		zb_cli_print_error(shell, &amp;quot;Can not stop commissioning&amp;quot;, ZB_FALSE);
	}
}


SHELL_STATIC_SUBCMD_SET_CREATE(sub_bdb_c,
	SHELL_CMD_ARG(stop, NULL, &amp;quot;Stop commissionning&amp;quot;, cmd_zb_stop, 1, 0),
	SHELL_SUBCMD_SET_END /* Array terminated. */
);

SHELL_CMD_REGISTER(bdb_c, &amp;amp;sub_bdb_c, &amp;quot;Base device behaviour manipulation.&amp;quot;, NULL);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Please note that since this is a new set of commands you cannot use &amp;quot;bdb&amp;nbsp;&lt;em&gt;command&lt;/em&gt;&amp;quot;, since the bdb set of commands are already registered in&amp;nbsp;zigbee_cli_cmd_bdb.c. I called it bdb_c for bdb custom, so you will have to call &amp;quot;bdb_c stop&amp;quot;, but you can rename it to something else by changing&amp;nbsp;sub_bdb_c and&amp;nbsp;bdb_c in&amp;nbsp;SHELL_STATIC_SUBCMD_SET_CREATE and&amp;nbsp;SHELL_CMD_REGISTER. I put this code in a file called&amp;nbsp;zigbee_cli_cmd_bdb_stop.c under&amp;nbsp;network_coordinator/src, and added it to CMakeLists.txt like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;target_sources(app PRIVATE
  src/main.c;
  src/zigbee_cli_cmd_bdb_stop.c
)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;You can also add more subcommands by adding them to&amp;nbsp;SHELL_STATIC_SUBCMD_SET_CREATE. For this, you can look at how it is done in the Zigbee shell library files.&lt;/p&gt;
[quote user=""]Where does &amp;quot;mgmt_lqi&amp;quot; exist?[/quote]
&lt;p&gt;The command zdo mgmt_lqi calls the function&amp;nbsp;cmd_zb_mgmt_lqi() in&amp;nbsp;zigbee_cli_cmd_zdo.c:&amp;nbsp;&lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/v1.9.1/subsys/zigbee/cli/zigbee_cli_cmd_zdo.c#L2193"&gt;https://github.com/nrfconnect/sdk-nrf/blob/v1.9.1/subsys/zigbee/cli/zigbee_cli_cmd_zdo.c#L2193&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The implementation of the commands can be difficult to find, since for example the only place you will find exactly &amp;quot;zdo mgmt_lqi&amp;quot; is in the comment right above the function&amp;nbsp;cmd_zb_mgmt_lqi(). This is because you have both root commands and subcommands. In this case, zdo is the root command, and it is a shell command in and of itself. In addition to this, you have a list of subcommands under zdo, such as active_ep, bind, mgmt_lqi etc. So you&amp;nbsp;might not find the commands by searching for &amp;lt;&lt;em&gt;root command&lt;/em&gt;&amp;gt; &amp;lt;&lt;em&gt;sub_command&lt;/em&gt;&amp;gt; or even&amp;nbsp;&amp;lt;&lt;em&gt;root command&lt;/em&gt;&amp;gt;_&amp;lt;&lt;em&gt;sub_command&lt;/em&gt;&amp;gt;, since the commands are not registered as such. The command &amp;quot;zdo mgmt_lqi&amp;quot; is not registered as &amp;quot;&lt;span&gt;zdo mgmt_lqi&amp;quot; or even &amp;quot;zdo_mgmt_lqi&amp;quot;, but as this:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;SHELL_STATIC_SUBCMD_SET_CREATE(sub_zdo,
    ...
    SHELL_CMD_ARG(mgmt_lqi, NULL, MGMT_LQI_HELP, cmd_zb_mgmt_lqi, 2, 1),
    SHELL_SUBCMD_SET_END);
    
SHELL_CMD_REGISTER(zdo, &amp;amp;sub_zdo, &amp;quot;ZDO manipulation.&amp;quot;, NULL);&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;And even the function that is called when you issue the command is not named zdo_mgmt_lqi, but&amp;nbsp;cmd_zb_mgmt_lqi().&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;The&amp;nbsp;Zigbee shell files are located in&amp;nbsp;&lt;a href="https://github.com/nrfconnect/sdk-nrf/tree/v1.9.1/subsys/zigbee/cli"&gt;nrf/subsys/zigbee/cli/&lt;/a&gt;&amp;nbsp;in nRF Connect SDK v1.9.1 and earlier, and from v2.0.0 they are under&amp;nbsp;&lt;a href="https://github.com/nrfconnect/sdk-nrf/tree/v2.0.0/subsys/zigbee/lib/zigbee_shell"&gt;nrf/subsys/zigbee/lib/zigbee_shell&lt;/a&gt;. You should be able to find which file most of the commands are in just by looking at the file names, e.g. bdb commands are in&amp;nbsp;&lt;a title="zigbee_cli_cmd_bdb.c" href="https://github.com/nrfconnect/sdk-nrf/blob/v1.9.1/subsys/zigbee/cli/zigbee_cli_cmd_bdb.c"&gt;zigbee_cli_cmd_bdb.c&lt;/a&gt;/zigbee_shell_cmd_bdb.c, zdo commands in&amp;nbsp;&lt;a title="zigbee_cli_cmd_zdo.c" href="https://github.com/nrfconnect/sdk-nrf/blob/v1.9.1/subsys/zigbee/cli/zigbee_cli_cmd_zdo.c"&gt;zigbee_cli_cmd_zdo.c&lt;/a&gt;/zigbee_shell_cmd_zdo.c and so forth.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I hope this clears up some of the confusion with the Zigbee shell commands!&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Best regards,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Marte&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>