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) { emberEventControlSetInactive(buttonEventControl); if (halButtonState(BUTTON0) == BUTTON_PRESSED) { EmberNetworkStatus state = emberNetworkState(); if (state == EMBER_JOINED_NETWORK) { emberAfFillExternalBuffer((ZCL_CLUSTER_SPECIFIC_COMMAND | ZCL_FRAME_CONTROL_CLIENT_TO_SERVER), ZCL_ON_OFF_CLUSTER_ID, (on ? ZCL_OFF_COMMAND_ID : ZCL_ON_COMMAND_ID), ""); emberAfGetCommandApsFrame()->profileId = emberAfPrimaryProfileId(); emberAfGetCommandApsFrame()->sourceEndpoint = emberAfPrimaryEndpoint(); emberAfGetCommandApsFrame()->destinationEndpoint = EMBER_BROADCAST_ENDPOINT; if (emberAfSendCommandUnicastToBindings() == EMBER_SUCCESS) { on = !on; } else { halPlayTune_P(sadTune, TRUE); } } else if (state == EMBER_NO_NETWORK) { halPlayTune_P((emberAfStartSearchForJoinableNetwork() == EMBER_SUCCESS ? waitTune : sadTune), TRUE); } else { if (REPAIR_LIMIT_MS < elapsedTimeInt16u(buttonPressTime, halCommonGetInt16uMillisecondTick())) { halPlayTune_P(sadTune, TRUE); } else { if (state == EMBER_JOINED_NETWORK_NO_PARENT && !emberStackIsPerformingRejoin()) { halPlayTune_P((emberFindAndRejoinNetwork(TRUE, 0) == EMBER_SUCCESS ? waitTune : sadTune), TRUE); } emberEventControlSetDelayMS(buttonEventControl, REPAIR_DELAY_MS); } } } else if (halButtonState(BUTTON1) == BUTTON_PRESSED) { emberAfEzmodeClientCommission(emberAfPrimaryEndpoint(), EMBER_AF_EZMODE_COMMISSIONING_CLIENT_TO_SERVER, clusterIds, COUNTOF(clusterIds)); } }
void buttonEventHandler(void) { emberEventControlSetInactive(buttonEventControl); if (halButtonState(BUTTON0) == BUTTON_PRESSED) { EmberNetworkStatus state = emberNetworkState(); if (state == EMBER_JOINED_NETWORK) { emberAfEzmodeClientCommission(emberAfPrimaryEndpoint(), EMBER_AF_EZMODE_COMMISSIONING_SERVER_TO_CLIENT, clusterIds, COUNTOF(clusterIds)); } else if (state == EMBER_NO_NETWORK) { halPlayTune_P(((emberFormAndJoinIsScanning() || (emberAfStartSearchForJoinableNetwork() == EMBER_SUCCESS)) ? waitTune : sadTune), TRUE); } } else if (halButtonState(BUTTON1) == BUTTON_PRESSED) { emberAfEzmodeServerCommission(emberAfPrimaryEndpoint()); } }