void setup() {
Serial.begin(115200);
znp_serial.begin(115200);
Serial.println("\nstart_coordinator(0)");
if (zigbee_network.start_coordinator(0) == 0) {
Serial.println("OK");
}
else {
Serial.println("NG");
}
}
char serial_cmd;
void loop() {
if (Serial.available()) {
serial_cmd = Serial.read();
switch(serial_cmd) {
case '0': {
Serial.println("\nstart_coordinator(1)");
if (zigbee_network.start_coordinator(1) == 0) {
Serial.println("OK");
}
else {
Serial.println("NG");
}
}
break;
case '1': {
Serial.println("set_permit_joining_req");
zigbee_network.set_permit_joining_req(ALL_ROUTER_AND_COORDINATOR, 60, 1);
}
break;
case '3': {
Serial.println("TOOGLE Switch Req !\n");
/*
* Frame Control, Transaction Sequence Number, Value control
* Value control -> 0x00: off, 0x01: on, 0x02: toogle
*/
if (control_switch_address) {
uint8_t st_buffer[3] = { /* Frame control */ 0x01,
/* Transaction Sequence Number */0x00, /* control_switch_cmd_seq++ */
/* Value Control */ 0x02}; /* Value Control [ 0x00:OFF , 0x01:ON , 0x02:TOOGLE ] */
st_buffer[1] = control_switch_cmd_seq++;
af_data_request_t st_af_data_request;
st_af_data_request.cluster_id = ZCL_CLUSTER_ID_PI_GENERIC_TUNNEL;
st_af_data_request.dst_address = control_switch_address;
st_af_data_request.dst_endpoint = 0x01;
st_af_data_request.src_endpoint = 0x01;
st_af_data_request.trans_id = 0x00;
st_af_data_request.options = 0x10;
st_af_data_request.radius = 0x0F;
st_af_data_request.len = sizeof(st_buffer);
st_af_data_request.data = st_buffer;
zigbee_network.send_af_data_req(st_af_data_request);
}
else {
Serial.println("Please join Switch !\n");
}
}
break;