EZSP32 idf4.4

This commit is contained in:
Stephan Hadinger 2021-11-05 23:21:09 +01:00
parent a3568b1ece
commit 2da2e37abc
6 changed files with 19 additions and 20 deletions

View File

@ -853,8 +853,8 @@
#define IR_RCV_WHILE_SENDING 0 // Turns on receiver while sending messages, i.e. receive your own. This is unreliable and can cause IR timing issues
// -- 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 // Enable serial communication with Zigbee CC2530/CC2652 flashed with ZNP or EFR32 flashed with EZSP (+49k code, +3k mem)
#define USE_ZIGBEE_ZNP // Enable ZNP protocol, needed for CC2530/CC2652 based devices
// #define USE_ZIGBEE_EZSP // 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_EEPROM // Use the EEPROM from the Sonoff ZBBridge to save Zigbee configuration and data

View File

@ -95,6 +95,8 @@ protected:
uint8_t _reserved; // power state if the type supports it
};
Z_Data z_data_unk; // dummy object to mark that data is unknown
Z_Data_Type Z_Data::CharToDataType(char c) {
if (c) {
if (c == '_') {
@ -676,7 +678,7 @@ const M & Z_Data_Set::find(uint8_t ep) const {
// Output: if reference is null, instantiate object and add it at the end of the list
template <class M>
M & Z_Data_Set::addIfNull(M & cur, uint8_t ep) {
if (nullptr == &cur) {
if (&z_data_unk == &cur) {
LList_elt<M> * elt = new LList_elt<M>();
elt->val()._endpoint = ep;
this->addToLast((LList_elt<Z_Data>*)elt);
@ -697,7 +699,7 @@ const Z_Data & Z_Data_Set::find(Z_Data_Type type, uint8_t ep) const {
}
}
}
return *(Z_Data*)nullptr;
return z_data_unk; // mark as unknown
}
/*********************************************************************************************\

View File

@ -796,7 +796,7 @@ String Z_Devices::dumpCoordinator(void) const {
String Z_Devices::dumpDevice(uint32_t dump_mode, const Z_Device & device) const {
JsonGeneratorArray json_arr;
if (&device == nullptr) {
if (&device == &device_unk) {
if (dump_mode < 2) {
// dump light mode for all devices
for (const auto & device2 : _devices) {

View File

@ -152,21 +152,22 @@ void ZigbeeHueGroups(String * lights) {
}
void ZigbeeSendHue(uint16_t shortaddr, uint16_t cluster, uint8_t cmd, const SBuffer & s) {
ZCLMessage zcl(&s ? s.len() : 0);
ZCLMessage zcl(s.len());
zcl.shortaddr = shortaddr;
zcl.cluster = cluster;
zcl.cmd = cmd;
zcl.clusterSpecific = true;
zcl.needResponse = true;
zcl.direct = false; // discover route
if (&s) { zcl.buf.replace(s); }
zcl.buf.replace(s);
zigbeeZCLSendCmd(zcl);
}
// Send commands
// Power On/Off
void ZigbeeHuePower(uint16_t shortaddr, bool power) {
ZigbeeSendHue(shortaddr, 0x0006, power ? 1 : 0, *(SBuffer*)nullptr);
SBuffer s(0);
ZigbeeSendHue(shortaddr, 0x0006, power ? 1 : 0, s);
zigbee_devices.getShortAddr(shortaddr).setPower(power, 0);
}

View File

@ -281,7 +281,6 @@ void ZigbeeInputLoop(void) {
// Initialize internal structures
void ZigbeeInitSerial(void)
{
// AddLog(LOG_LEVEL_INFO, PSTR("ZigbeeInit Mem1 = %d"), ESP_getFreeHeap());
zigbee.active = false;
if (PinUsed(GPIO_ZIGBEE_RX) && PinUsed(GPIO_ZIGBEE_TX)) {
AddLog(LOG_LEVEL_DEBUG_MORE, PSTR(D_LOG_ZIGBEE "GPIOs Rx:%d Tx:%d"), Pin(GPIO_ZIGBEE_RX), Pin(GPIO_ZIGBEE_TX));
@ -293,9 +292,7 @@ void ZigbeeInitSerial(void)
uint32_t aligned_buffer = ((uint32_t)TasmotaGlobal.serial_in_buffer + 3) & ~3;
zigbee_buffer = new PreAllocatedSBuffer(sizeof(TasmotaGlobal.serial_in_buffer) - 3, (char*) aligned_buffer);
} else {
// AddLog(LOG_LEVEL_INFO, PSTR("ZigbeeInit Mem2 = %d"), ESP_getFreeHeap());
zigbee_buffer = new SBuffer(ZIGBEE_BUFFER_SIZE);
// AddLog(LOG_LEVEL_INFO, PSTR("ZigbeeInit Mem3 = %d"), ESP_getFreeHeap());
}
if (PinUsed(GPIO_ZIGBEE_RST)) {
@ -312,7 +309,6 @@ void ZigbeeInitSerial(void)
zigbee.state_machine = true; // start the state machine
ZigbeeSerial->flush();
}
// AddLog(LOG_LEVEL_INFO, PSTR("ZigbeeInit Mem9 = %d"), ESP_getFreeHeap());
}
#ifdef USE_ZIGBEE_ZNP

View File

@ -1224,7 +1224,7 @@ void CmndZbOccupancy(void) {
zigbee_devices.dirty();
} else {
const Z_Data_PIR & pir_found = (const Z_Data_PIR&) device.data.find(Z_Data_Type::Z_PIR);
if (&pir_found != nullptr) {
if (&pir_found != &z_data_unk) {
occupancy_time = pir_found.getTimeoutSeconds();
}
}
@ -1549,7 +1549,7 @@ void CmndZbStatus(void) {
dump = zigbee_devices.dumpDevice(XdrvMailbox.index, device);
} else {
if (XdrvMailbox.index >= 2) { ResponseCmndChar_P(PSTR(D_ZIGBEE_UNKNOWN_DEVICE)); return; }
dump = zigbee_devices.dumpDevice(XdrvMailbox.index, *(Z_Device*)nullptr);
dump = zigbee_devices.dumpDevice(XdrvMailbox.index, device_unk);
}
}
@ -1994,7 +1994,7 @@ void ZigbeeShow(bool json)
// Sensors
const Z_Data_Thermo & thermo = device.data.find<Z_Data_Thermo>();
if (&thermo != nullptr) {
if (&thermo != &z_data_unk) {
bool validTemp = thermo.validTemperature();
bool validTempTarget = thermo.validTempTarget();
bool validThSetpoint = thermo.validThSetpoint();
@ -2029,12 +2029,12 @@ void ZigbeeShow(bool json)
// Light, switches and plugs
const Z_Data_OnOff & onoff = device.data.find<Z_Data_OnOff>();
bool onoff_display = (&onoff != nullptr) ? onoff.validPower() : false;
bool onoff_display = (&onoff != &z_data_unk) ? onoff.validPower() : false;
const Z_Data_Light & light = device.data.find<Z_Data_Light>();
bool light_display = (&light != nullptr) ? light.validDimmer() : false;
bool light_display = (&light != &z_data_unk) ? light.validDimmer() : false;
const Z_Data_Plug & plug = device.data.find<Z_Data_Plug>();
bool plug_voltage = (&plug != nullptr) ? plug.validMainsVoltage() : false;
bool plug_power = (&plug != nullptr) ? plug.validMainsPower() : false;
bool plug_voltage = (&plug != &z_data_unk) ? plug.validMainsVoltage() : false;
bool plug_power = (&plug != &z_data_unk) ? plug.validMainsPower() : false;
if (onoff_display || light_display || plug_voltage || plug_power) {
int8_t channels = device.getLightChannels();
if (channels < 0) { channels = 5; } // if number of channel is unknown, display all known attributes
@ -2042,7 +2042,7 @@ void ZigbeeShow(bool json)
if (onoff_display) {
WSContentSend_P(PSTR(" %s"), onoff.getPower() ? PSTR(D_ON) : PSTR(D_OFF));
}
if (&light != nullptr) {
if (&light != &z_data_unk) {
if (light.validDimmer() && (channels >= 1)) {
WSContentSend_P(PSTR(" &#128261; %d%%"), changeUIntScale(light.getDimmer(),0,254,0,100));
}