Implementation of ZigBee automatic binding

Source: Internet
Author: User

Recently things more, busy reply, busy to socialize, especially the feelings between students need to drink to deepen, so that there is no time to read the code. So there is no time to read the writing code.

Today the binding experiment has been done again, but it is difficult to think that the binding by the key is manually implemented. So I figured it out in an automatic way. Let's talk about the process of implementing automatic binding.

BTW, put me in the process of the experiment failed to introduce the experience, I hope you have a moment. In the beginning, I added my own event my_event in the initialization, then read the type of the device in the event, if the coordinator is allowed to bind, the binding time is unlimited, if the terminal sends the binding request. But it always fails, and the device is constantly restarting. What is the trouble, do not know what reason.

I would like to have a similar problem with children's shoes can explain to me.

OK, let's get down to the chase. I guess everyone is not bad enough to squirt me.

1, to ensure that the automatic start of equipment. In the original program, the type of the device is set according to different keys, that is, press the different keys, which will be the node according to the specific device to start.

First, block out the key parts in the initialization program. Because this section turns off the auto-start mode.

/*

#if (defined Hal_key) && (Hal_key = = TRUE)

if (halkeyread () = = Hal_key_sw_1)

{

If SW1 is pressed and held when PowerUp, Force Auto-start and nv-restore off and reset

startoptions = 0;

Zb_writeconfiguration (zcd_nv_startup_option, sizeof (uint8), &startoptions);

Zb_systemreset ();

}

#endif//Hal_key

*/

The end part of the initialization function adds the following code:

Startoptions = Zcd_startopt_auto_start;

Zb_writeconfiguration (zcd_nv_startup_option, sizeof (uint8), &startoptions);

Zdoinitdevice (0);

After the device starts automatically, a message is sent to the task that changes the status of the device, which corresponds to the following section in the task handler function:

Case Zdo_state_change:

If the device has started up, notify the application

if (pmsg->status = = Dev_end_device | |

Pmsg->status = = Dev_router | |

Pmsg->status = = Dev_zb_coord)

{

Sapi_startconfirm (zb_success);

}

Break

When the device confirms the status of the change, this time we start to allow the device to bind, or send a binding request.

See Sapi_startconfirm (zb_success) for the specific code, this function.

void Sapi_startconfirm (uint8 status)

{

#if defined (MT_SAPI_CB_FUNC)

/* First check if MT have subscribed for this callback. If So, pass it as

A event to Monitortest and return control to calling function after that * *

if (Sapicb_check (SPI_CB_SAPI_START_CNF))

{

Zb_mtcallbackstartconfirm (status);

}

Else

#endif//mt_sapi_cb_func

{

Zb_startconfirm (status);

}

}

In the last function, let's add our own code.

void Zb_startconfirm (uint8 status)

{

If The device sucessfully started, change state to running

if (status = = Zb_success)

{

Myappstate = App_start;

Uint8 type;

Zb_readconfiguration (Zcd_nv_logical_type, sizeof (uint8), &type);

if (type==zg_devicetype_coordinator)

Zb_allowbind (0xFF);

Else

{

Zb_binddevice (TRUE, toggle_light_cmd_id, NULL);

}

}

Else

{

Try again later with a delay

Osal_start_timer (my_start_evt, Mystartretrydelay);

}

}

The type of the device is read first, and if it is a coordinator, the device is allowed to bind and the binding time is 0xff, which means that the device is allowed to bind at all times.      If it is a different device type, the device binding request is sent. After power on, found that the device can automatically join the network and can be automatically bound, when we again touch the switch device on the light control button, the corresponding light status on the coordinator is sent to flip. Therefore, it is possible to prove that automatic binding is implemented.

Implementation of ZigBee automatic binding

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.