Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Zigbee initial support for EmberZNet protocol #8709

Merged
merged 2 commits into from
Jun 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tasmota/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### 8.3.1.5 20200616

- Add ESP32 ethernet commands ``EthType 0/1``, ``EthAddress 0..31`` and ``EthClockMode 0..3``
- Add Zigbee initial support for EmberZNet protocol (raw send/receive only)

### 8.3.1.4 20200615

Expand Down
4 changes: 4 additions & 0 deletions tasmota/i18n.h
Original file line number Diff line number Diff line change
Expand Up @@ -505,10 +505,14 @@
#define D_CMND_ZIGBEE_RESET "Reset"
#define D_JSON_ZIGBEE_CC2530 "CC2530"
#define D_CMND_ZIGBEEZNPRECEIVE "ZNPReceive" // only for debug
#define D_CMND_ZIGBEE_EZSP_RECEIVE "EZSPReceive" // only for debug
#define D_CMND_ZIGBEEZNPSEND "ZNPSend"
#define D_CMND_ZIGBEE_EZSP_SEND "EZSPSend"
#define D_JSON_ZIGBEE_STATE "ZbState"
#define D_JSON_ZIGBEEZNPRECEIVED "ZbZNPReceived"
#define D_JSON_ZIGBEE_EZSP_RECEIVED "ZbEZSPReceived"
#define D_JSON_ZIGBEEZNPSENT "ZbZNPSent"
#define D_JSON_ZIGBEE_EZSP_SENT "ZbEZSPSent"
#define D_JSON_ZIGBEEZCL_RECEIVED "ZbZCLReceived"
#define D_JSON_ZIGBEEZCL_RAW_RECEIVED "ZbZCLRawReceived"
#define D_JSON_ZIGBEE_DEVICE "Device"
Expand Down
3 changes: 3 additions & 0 deletions tasmota/my_user_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,9 @@

// -- Zigbee interface ----------------------------
//#define USE_ZIGBEE // Enable serial communication with Zigbee CC2530 flashed with ZNP (+49k code, +3k mem)
#define USE_ZIGBEE_ZNP // Enable ZNP protocol, needed for CC2530 based devices
// #define USE_ZIGBEE_EZSP // [EXPERIMENTAL - DO NOT USE] Enable EZSP protocol, needed for EFR32 EmberZNet based devices, like Sonoff Zigbee bridge
// Note: USE_ZIGBEE_ZNP and USE_ZIGBEE_EZSP are mutually incompatible, you must select exactly one
#define USE_ZIGBEE_PANID 0x1A63 // arbitrary PAN ID for Zigbee network, must be unique in the home
// if PANID == 0xFFFF, then the device will act as a Zigbee router, the parameters below are ignored
// if PANID == 0xFFFE, then the device will act as a Zigbee end-device (non-router), the parameters below are ignored
Expand Down
9 changes: 9 additions & 0 deletions tasmota/xdrv_23_zigbee_0_constants.ino
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,21 @@

#ifdef USE_ZIGBEE

#if defined(USE_ZIGBEE_ZNP) && defined(USE_ZIGBEE_EZSP)
#error "#define USE_ZIGBEE_ZNP and #define USE_ZIGBEE_EZSP are mutually incompatible"
#endif
#if !defined(USE_ZIGBEE_ZNP) && !defined(USE_ZIGBEE_EZSP)
#error "You must select one of: #define USE_ZIGBEE_ZNP or #define USE_ZIGBEE_EZSP"
#endif

#define OCCUPANCY "Occupancy" // global define for Aqara

typedef uint64_t Z_IEEEAddress;
typedef uint16_t Z_ShortAddress;

const uint16_t BAD_SHORTADDR = 0xFFFE;

#ifdef USE_ZIGBEE_ZNP
enum ZnpCommandType {
Z_POLL = 0x00,
Z_SREQ = 0x20,
Expand All @@ -45,6 +53,7 @@ enum ZnpSubsystem {
Z_DEBUG = 0x08,
Z_APP = 0x09
};
#endif // USE_ZIGBEE_ZNP

// Commands in the SYS subsystem
enum SysCommand {
Expand Down
28 changes: 28 additions & 0 deletions tasmota/xdrv_23_zigbee_7_statemachine.ino
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ SBuffer *zigbee_buffer = nullptr;

#define USE_ZIGBEE_CHANNEL_MASK (1 << (USE_ZIGBEE_CHANNEL))

#ifdef USE_ZIGBEE_ZNP

// ZBS_* Zigbee Send
// ZBR_* Zigbee Recv
ZBM(ZBS_RESET, Z_AREQ | Z_SYS, SYS_RESET, 0x00 ) // 410001 SYS_RESET_REQ Hardware reset
Expand Down Expand Up @@ -611,6 +613,30 @@ static const Zigbee_Instruction zb_prog[] PROGMEM = {
ZI_STOP(ZIGBEE_LABEL_ABORT)
};

#endif // USE_ZIGBEE_ZNP

#ifdef USE_ZIGBEE_EZSP

// Update the relevant commands with Settings
void Z_UpdateConfig(uint8_t zb_channel, uint16_t zb_pan_id, uint64_t zb_ext_panid, uint64_t zb_precfgkey_l, uint64_t zb_precfgkey_h) {
}


static const Zigbee_Instruction zb_prog[] PROGMEM = {
ZI_LABEL(0)
ZI_NOOP()
ZI_ON_ERROR_GOTO(ZIGBEE_LABEL_ABORT)
ZI_ON_TIMEOUT_GOTO(ZIGBEE_LABEL_ABORT)
// ZI_ON_RECV_UNEXPECTED(&Z_Recv_Default)
// ZI_WAIT(10500) // wait for 10 seconds for Tasmota to stabilize

ZI_LABEL(ZIGBEE_LABEL_MAIN_LOOP)
ZI_WAIT_FOREVER()
ZI_GOTO(ZIGBEE_LABEL_READY)
};

#endif // USE_ZIGBEE_EZSP

uint8_t ZigbeeGetInstructionSize(uint8_t instr) { // in Zigbee_Instruction lines (words)
if (instr >= ZGB_INSTR_12_BYTES) {
return 3;
Expand Down Expand Up @@ -770,7 +796,9 @@ void ZigbeeStateMachine_Run(void) {
}
break;
case ZGB_INSTR_SEND:
#ifdef USE_ZIGBEE_ZNP
ZigbeeZNPSend((uint8_t*) cur_ptr1, cur_d8 /* len */);
#endif // USE_ZIGBEE_ZNP
break;
case ZGB_INSTR_WAIT_UNTIL:
zigbee.recv_until = true; // and reuse ZGB_INSTR_WAIT_RECV
Expand Down
31 changes: 31 additions & 0 deletions tasmota/xdrv_23_zigbee_8_parsers.ino
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ int32_t Z_MgmtBindRsp(int32_t res, const class SBuffer &buf) {
return -1;
}

#ifdef USE_ZIGBEE_ZNP
/*********************************************************************************************\
* Send specific ZNP messages
\*********************************************************************************************/
Expand Down Expand Up @@ -589,6 +590,32 @@ void Z_SendAFInfoRequest(uint16_t shortaddr) {
ZigbeeZNPSend(AFInfoReq, sizeof(AFInfoReq));
}

#endif // USE_ZIGBEE_ZNP

#ifdef USE_ZIGBEE_EZSP
/*********************************************************************************************\
* Send specific EZS¨ messages
\*********************************************************************************************/

//
// Send ZDO_IEEE_ADDR_REQ request to get IEEE long address
//
void Z_SendIEEEAddrReq(uint16_t shortaddr) {
}

//
// Send ACTIVE_EP_REQ to collect active endpoints for this address
//
void Z_SendActiveEpReq(uint16_t shortaddr) {
}

//
// Send AF Info Request
//
void Z_SendAFInfoRequest(uint16_t shortaddr) {
}

#endif // USE_ZIGBEE_EZSP

/*********************************************************************************************\
* Callbacks
Expand Down Expand Up @@ -718,6 +745,8 @@ typedef struct Z_Dispatcher {
ZB_RecvMsgFunc func;
} Z_Dispatcher;

#ifdef USE_ZIGBEE_ZNP

// Ffilters based on ZNP frames
ZBM(AREQ_AF_DATA_CONFIRM, Z_AREQ | Z_AF, AF_DATA_CONFIRM) // 4480
ZBM(AREQ_AF_INCOMING_MESSAGE, Z_AREQ | Z_AF, AF_INCOMING_MSG) // 4481
Expand Down Expand Up @@ -767,6 +796,8 @@ int32_t Z_Recv_Default(int32_t res, const class SBuffer &buf) {
}
}

#endif // USE_ZIGBEE_ZNP

/*********************************************************************************************\
* Functions called by State Machine
\*********************************************************************************************/
Expand Down
Loading