mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-27 12:46:34 +00:00
Zigbee use of ZbRestore for backup
This commit is contained in:
parent
95362af6e4
commit
817ac3a01f
@ -204,7 +204,7 @@ const char * hydrateSingleString(const SBuffer & buf, uint32_t *d) {
|
|||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void hydrateSingleDevice(const SBuffer & buf_d, uint32_t version) {
|
void hydrateSingleDevice(const SBuffer & buf_d, uint32_t version = 2) {
|
||||||
uint32_t d = 1; // index in device buffer
|
uint32_t d = 1; // index in device buffer
|
||||||
uint16_t shortaddr = buf_d.get16(d); d += 2;
|
uint16_t shortaddr = buf_d.get16(d); d += 2;
|
||||||
uint64_t longaddr = buf_d.get64(d); d += 8;
|
uint64_t longaddr = buf_d.get64(d); d += 8;
|
||||||
@ -424,4 +424,16 @@ void eraseZigbeeDevices(void) {
|
|||||||
#endif // ESP32
|
#endif // ESP32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void restoreDumpAllDevices(void) {
|
||||||
|
for (const auto & device : zigbee_devices.getDevices()) {
|
||||||
|
const SBuffer buf = hibernateDevicev2(device);
|
||||||
|
if (buf.len() > 0) {
|
||||||
|
char hex_char[buf.len()*2+2];
|
||||||
|
Response_P(PSTR("{\"" D_PRFX_ZB D_CMND_ZIGBEE_RESTORE "\":\"ZbRestore %s\"}"),
|
||||||
|
ToHex_P(buf.buf(0), buf.len(), hex_char, sizeof(hex_char)));
|
||||||
|
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_STAT, PSTR(D_PRFX_ZB D_CMND_ZIGBEE_DATA));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endif // USE_ZIGBEE
|
#endif // USE_ZIGBEE
|
||||||
|
@ -1676,8 +1676,6 @@ int32_t EZ_IncomingMessage(int32_t res, const class SBuffer &buf) {
|
|||||||
case ZDO_Parent_annce_rsp:
|
case ZDO_Parent_annce_rsp:
|
||||||
return EZ_ParentAnnceRsp(res, zdo_buf, true);
|
return EZ_ParentAnnceRsp(res, zdo_buf, true);
|
||||||
default:
|
default:
|
||||||
// TODO move later to LOG_LEVEL_DEBUG
|
|
||||||
AddLog_P(LOG_LEVEL_INFO, PSTR("ZIG: Internal ZDO message 0x%04X sent from 0x%04X %s"), clusterid, srcaddr, wasbroadcast ? PSTR("(broadcast)") : "");
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -1282,6 +1282,12 @@ void CmndZbSave(void) {
|
|||||||
// ZbRestore {"Device":"0x5ADF","Name":"Petite_Lampe","IEEEAddr":"0x90FD9FFFFE03B051","ModelId":"TRADFRI bulb E27 WS opal 980lm","Manufacturer":"IKEA of Sweden","Endpoints":["0x01","0xF2"]}
|
// ZbRestore {"Device":"0x5ADF","Name":"Petite_Lampe","IEEEAddr":"0x90FD9FFFFE03B051","ModelId":"TRADFRI bulb E27 WS opal 980lm","Manufacturer":"IKEA of Sweden","Endpoints":["0x01","0xF2"]}
|
||||||
void CmndZbRestore(void) {
|
void CmndZbRestore(void) {
|
||||||
if (zigbee.init_phase) { ResponseCmndChar_P(PSTR(D_ZIGBEE_NOT_STARTED)); return; }
|
if (zigbee.init_phase) { ResponseCmndChar_P(PSTR(D_ZIGBEE_NOT_STARTED)); return; }
|
||||||
|
RemoveSpace(XdrvMailbox.data);
|
||||||
|
|
||||||
|
if (strlen(XdrvMailbox.data) == 0) {
|
||||||
|
// if empty, log values for all devices
|
||||||
|
restoreDumpAllDevices();
|
||||||
|
} else if (XdrvMailbox.data[0] == '{') { // try JSON
|
||||||
JsonParser parser(XdrvMailbox.data);
|
JsonParser parser(XdrvMailbox.data);
|
||||||
JsonParserToken root = parser.getRoot();
|
JsonParserToken root = parser.getRoot();
|
||||||
|
|
||||||
@ -1317,6 +1323,17 @@ void CmndZbRestore(void) {
|
|||||||
ResponseCmndChar_P(PSTR("Missing parameters"));
|
ResponseCmndChar_P(PSTR("Missing parameters"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
} else { // try hex
|
||||||
|
SBuffer buf = SBuffer::SBufferFromHex(XdrvMailbox.data, strlen(XdrvMailbox.data));
|
||||||
|
// do a sanity check, the first byte must equal the length of the buffer
|
||||||
|
if (buf.get8(0) == buf.len()) {
|
||||||
|
// good, we can hydrate
|
||||||
|
hydrateSingleDevice(buf);
|
||||||
|
} else {
|
||||||
|
ResponseCmndChar_P(PSTR("Restore failed"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
ResponseCmndDone();
|
ResponseCmndDone();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1857,11 +1874,12 @@ bool Xdrv23(uint8_t function)
|
|||||||
case FUNC_COMMAND:
|
case FUNC_COMMAND:
|
||||||
result = DecodeCommand(kZbCommands, ZigbeeCommand);
|
result = DecodeCommand(kZbCommands, ZigbeeCommand);
|
||||||
break;
|
break;
|
||||||
#ifdef USE_ZIGBEE_EZSP
|
|
||||||
case FUNC_SAVE_BEFORE_RESTART:
|
case FUNC_SAVE_BEFORE_RESTART:
|
||||||
|
#ifdef USE_ZIGBEE_EZSP
|
||||||
hibernateAllData();
|
hibernateAllData();
|
||||||
break;
|
|
||||||
#endif // USE_ZIGBEE_EZSP
|
#endif // USE_ZIGBEE_EZSP
|
||||||
|
restoreDumpAllDevices();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user