In the run, modify the coordinator Pan ID and channel, and the coordinator broadcasts to all device reboots to join the newly created network

Source: Internet
Author: User

See a question from the fly-over forum and record:

A ZigBee network operation, the coordinator through the serial port and the host computer connection, the host computer set the coordinator Pan ID and channel, the coordinator received the configuration information,

The Pan ID and channel broadcasts are first sent to all nodes in the network, and then the coordinator itself restarts to join the new network. Some of the code is as follows:
//pan ID
uint16 Panid = build_uint16 (Msg[locdongle_config_panid_lo_idx],
Msg[locdongle_config_panid_hi_idx]);

//channel
uint8 channelid = Msg[locdongle_config_channelid_idx];
    
//change Pan ID and channel
_nib.nwklogicalchannel = channelid;
_nib.nwkpanid = Panid;

nlme_updatenv (0x01);

//Broadcast to all nodes
if (updateallnetwork (Panid, channelid) = = afstatus_success)
{

// here can be added non-blocking delay, must not add blocking delay, otherwise you cannot execute other programs

Systemresetsoft ();

}

static afstatus_t updateallnetwork (UInt16 panid, uint8 channelid)
{

afaddrtype_t dstaddr;
uint8 datalength = msg_panid_length + msg_channelid_length;
uint8 *msg = Osal_mem_alloc (datalength);

Dstaddr.addrmode = (afaddrmode_t) afaddrbroadcast;
dstAddr.addr.shortAddr = Nwk_broadcast_shortaddr_devall;
dstaddr.endpoint = af_broadcast_endpoint;

msg[0] = lo_uint16 (Panid);
msg[1] = hi_uint16 (Panid);
msg[2] = channelid;

return Af_datarequest (&DSTADDR,
(endpointdesc_t*) &epdesc,
Update_all_network,
Datalength,
msg,
&locdongle_transid,
0,
Af_default_radius);
}
test Result: When commented out Systemresetsoft (), other nodes in the network can accept the broadcast, otherwise the coordinator restarts the formation of a new network, the node cannot receive the broadcast.
Possible cause: The Coordinator has not yet broadcast the data and the facilitator is restarted.

So, I add a delay function, delay a few seconds, but the problem is still, debug is the result. Helpless to ask you, what reason. In addition, to see if you have a better way to achieve, I feel that their way is not natural.


Workaround:

I happen to need to implement this function, has been implemented.
landlord problem analysis is correct, it is because the broadcast frame is not sent out, the coordinator has been restarted, other devices do not receive the restart command.
But the solution is a bit improper, z-stack send data is asynchronous, that is, after the Af_senddata function call is completed and not sent out but to the next layer to continue packaging after the final to send out, so should delay, but not using blocking delay, stay in the current state, Causes the packet to not be sent out.
My solution is after the Af_senddata,using the Osal_start_timerex timer, the timer will generate an event you set after the time you set, then go to the corresponding event and restart the coordinator. The event I set was 500ms!.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

In the run, modify the coordinator Pan ID and channel, and the coordinator broadcasts to all device reboots to join the newly created network

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.