static CommissioningState_t FormJoinNetwork(void) { emberAfDebugPrintln("DEBUG: Form/Join network"); // Form or join depends on the device type // Coordinator: form a network // Router/ZED/SED/MED: find a network EmberStatus status = EMBER_SUCCESS; if (emAfCurrentZigbeeProNetwork->nodeType == EMBER_COORDINATOR) { status = emberAfFindUnusedPanIdAndForm(); } else { status = emberAfStartSearchForJoinableNetwork(); } if (status != EMBER_SUCCESS) { SetNextEvent(SC_EZEV_UNKNOWN); } else { SetNextEvent(SC_EZEV_CHECK_NETWORK); } IncNetworkTries(); // run state machine again after 10 seconds emberEventControlSetDelayQS(StateMachineEvent, SIMPLE_COMMISSIONING_NETWORK_CHECK_RETRY_TIME); return SC_EZ_START; }
void emberAfPluginButtonJoiningButton0EventHandler(void) { emberEventControlSetInactive(buttonEvent0); if (buttonPressDurationMs >= BUTTON_HOLD_DURATION_MS) { emberAfCorePrintln("Leaving network due to button press."); emberLeaveNetwork(); return; } if (emberAfNetworkState() == EMBER_JOINED_NETWORK) { emberAfBroadcastPermitJoin(PERMIT_JOIN_TIMEOUT); } else if (emberAfNetworkState() == EMBER_NO_NETWORK) { #ifdef EMBER_AF_HAS_COORDINATOR_NETWORK emberAfCorePrintln("%p: nwk down: do form", "button0"); emberAfFindUnusedPanIdAndForm(); #else emberAfCorePrintln("%p: nwk down: do join", "button0"); emberAfStartSearchForJoinableNetwork(); #endif } }
void buttonEventHandler(void) { // On a press-and-hold button event, form a network if we don't have one or // permit joining if we do. If we form, we'll automatically permit joining // when we come up. emberEventControlSetInactive(buttonEventControl); if (halButtonState(BUTTON0) == BUTTON_PRESSED) { if (emberNetworkState() == EMBER_NO_NETWORK) { halPlayTune_P(((emberFormAndJoinIsScanning() || emberAfFindUnusedPanIdAndForm() == EMBER_SUCCESS) ? waitTune : sadTune), TRUE); } else { pjoin(); } } else if (halButtonState(BUTTON1) == BUTTON_PRESSED) { emberAfEzmodeServerCommission(emberAfPrimaryEndpoint()); } }