Docs

You are here:
Network operation

Joining and leaving the network.

Once the RCM radio module is configured, what we want to do is to allow it to connect to a network, or establish a new network in case of a coordinator device. To do that we simply call rcm::Connection::startNetworking method. The returned value will tell us, whether we have joined (or established) the network successfully or not.

Complementary, in order to disconnect from the network, we can call rcm::Connection::stopNetworking method.

We can always call the rcm::Connection::getNetworkState method to determine the actual networking state.

The following example illustrates how to establish the network:

#include "rcmpp.h"
int rcmpp_networking_example(const char* portName)
{
int result = 0;
try {
// construct the connection object
rcm::Connection rcm(portName);
// set UID
rcm.setUID(0x0123456789abcdef);
// configure networking
rcm.configureNode(RCM_DEVICE_TYPE_COORDINATOR, 0x1122334455667788, RCM_ADDRESSING_SCHEME_STATIC, 0);
// start networking
if (rcm.startNetworking()) {
// some delay
OS_Sleep(5000);
// check network state
if (RCM_NETWORK_JOINED == rcm.getNetworkState()) {
// leave the network
rcm.stopNetworking();
}
}
}
catch(rcm::exception &e) {
result = 100;
}
catch(std::exception &e) {
result = 101;
}
catch (...) {
result = 102;
}
return result;
}

Addressing network nodes.

The remote nodes can be addressed using 64-bit unique ID (UID) or 16-bit short network address. Sometimes it is feasible to convert one address to another, which generally requires communication with the node using one address and asking it for the other, unless such information is already cached in the RCM stack. To perform such action two functions are provided: rcm::Connection::getUIDFromNwkShortAddress and rcm::Connection::getNwkShortAddressFromUID.

The following example illustrates such usage:

#include "rcmpp.h"
int rcmpp_address_resolution_example(const char* portName)
{
int result = 0;
unsigned short nwkAddr;
unsigned long long uid;
try {
// construct the connection object
rcm::Connection rcm(portName);
// set UID
rcm.setUID(0x0123456789abcdee);
// configure networking
rcm.configureNode(RCM_DEVICE_TYPE_ROUTER, 0x1122334455667788, RCM_ADDRESSING_SCHEME_STATIC, 1);
// start networking
if (rcm.startNetworking()) {
// convert the UID to network address
rcm.getNwkShortAddressFromUID(0x0123456789abcdef, nwkAddr);
// convert the network address to UID
rcm.getUIDFromNwkShortAddress(0, uid);
// leave the network
rcm.stopNetworking();
}
} catch(rcm::exception &e) {
result = 100;
}
catch(std::exception &e) {
result = 101;
}
catch (...) {
result = 102;
}
return result;
}
Go to Top