Merge pull request #7935 from s-hadinger/pmem_2

Moving more strings to PROGMEM
This commit is contained in:
Theo Arends 2020-03-17 08:44:39 +01:00 committed by GitHub
commit f060954f54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 88 additions and 66 deletions

View File

@ -77,6 +77,14 @@ void ResponseCmndIdxNumber(int value)
Response_P(S_JSON_COMMAND_INDEX_NVALUE, XdrvMailbox.command, XdrvMailbox.index, value); Response_P(S_JSON_COMMAND_INDEX_NVALUE, XdrvMailbox.command, XdrvMailbox.index, value);
} }
void ResponseCmndChar_P(const char* value)
{
size_t buf_size = strlen_P(value);
char buf[buf_size + 1];
strcpy_P(buf, value);
Response_P(S_JSON_COMMAND_SVALUE, XdrvMailbox.command, buf);
}
void ResponseCmndChar(const char* value) void ResponseCmndChar(const char* value)
{ {
Response_P(S_JSON_COMMAND_SVALUE, XdrvMailbox.command, value); Response_P(S_JSON_COMMAND_SVALUE, XdrvMailbox.command, value);
@ -602,7 +610,7 @@ void CmndRestart(void)
EspRestart(); EspRestart();
break; break;
default: default:
ResponseCmndChar(D_JSON_ONE_TO_RESTART); ResponseCmndChar_P(PSTR(D_JSON_ONE_TO_RESTART));
} }
} }
@ -1059,7 +1067,7 @@ void CmndTemplate(void)
if (JsonTemplate(XdrvMailbox.data)) { // Free 336 bytes StaticJsonBuffer stack space by moving code to function if (JsonTemplate(XdrvMailbox.data)) { // Free 336 bytes StaticJsonBuffer stack space by moving code to function
if (USER_MODULE == Settings.module) { restart_flag = 2; } if (USER_MODULE == Settings.module) { restart_flag = 2; }
} else { } else {
ResponseCmndChar(D_JSON_INVALID_JSON); ResponseCmndChar_P(PSTR(D_JSON_INVALID_JSON));
error = true; error = true;
} }
} }

View File

@ -258,10 +258,10 @@ void IrRemoteCmndResponse(uint32_t error)
{ {
switch (error) { switch (error) {
case IE_INVALID_RAWDATA: case IE_INVALID_RAWDATA:
ResponseCmndChar(D_JSON_INVALID_RAWDATA); ResponseCmndChar_P(PSTR(D_JSON_INVALID_RAWDATA));
break; break;
case IE_INVALID_JSON: case IE_INVALID_JSON:
ResponseCmndChar(D_JSON_INVALID_JSON); ResponseCmndChar_P(PSTR(D_JSON_INVALID_JSON));
break; break;
case IE_SYNTAX_IRSEND: case IE_SYNTAX_IRSEND:
Response_P(PSTR("{\"" D_CMND_IRSEND "\":\"" D_JSON_NO " " D_JSON_IR_PROTOCOL ", " D_JSON_IR_BITS " " D_JSON_OR " " D_JSON_IR_DATA "\"}")); Response_P(PSTR("{\"" D_CMND_IRSEND "\":\"" D_JSON_NO " " D_JSON_IR_PROTOCOL ", " D_JSON_IR_BITS " " D_JSON_OR " " D_JSON_IR_DATA "\"}"));

View File

@ -605,10 +605,10 @@ void IrRemoteCmndResponse(uint32_t error)
{ {
switch (error) { switch (error) {
case IE_INVALID_RAWDATA: case IE_INVALID_RAWDATA:
ResponseCmndChar(D_JSON_INVALID_RAWDATA); ResponseCmndChar_P(PSTR(D_JSON_INVALID_RAWDATA));
break; break;
case IE_INVALID_JSON: case IE_INVALID_JSON:
ResponseCmndChar(D_JSON_INVALID_JSON); ResponseCmndChar_P(PSTR(D_JSON_INVALID_JSON));
break; break;
case IE_SYNTAX_IRSEND: case IE_SYNTAX_IRSEND:
Response_P(PSTR("{\"" D_CMND_IRSEND "\":\"" D_JSON_NO " " D_JSON_IR_BITS " " D_JSON_OR " " D_JSON_IR_DATA "\"}")); Response_P(PSTR("{\"" D_CMND_IRSEND "\":\"" D_JSON_NO " " D_JSON_IR_BITS " " D_JSON_OR " " D_JSON_IR_DATA "\"}"));

View File

@ -461,7 +461,7 @@ uint32_t findEchoGeneration(void) {
gen = 1; // if no user-agent, also revert to gen v1 gen = 1; // if no user-agent, also revert to gen v1
} }
AddLog_P2(LOG_LEVEL_DEBUG_MORE, D_LOG_HTTP D_HUE " User-Agent: %s, gen=%d", user_agent.c_str(), gen); // Header collection is set in xdrv_01_webserver.ino, in StartWebserver() AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR(D_LOG_HTTP D_HUE " User-Agent: %s, gen=%d"), user_agent.c_str(), gen); // Header collection is set in xdrv_01_webserver.ino, in StartWebserver()
return gen; return gen;
} }
@ -705,8 +705,8 @@ void HueLights(String *path)
uint32_t device_id; // the raw device_id used by Hue emulation uint32_t device_id; // the raw device_id used by Hue emulation
uint8_t maxhue = (devices_present > MAX_HUE_DEVICES) ? MAX_HUE_DEVICES : devices_present; uint8_t maxhue = (devices_present > MAX_HUE_DEVICES) ? MAX_HUE_DEVICES : devices_present;
path->remove(0,path->indexOf("/lights")); // Remove until /lights path->remove(0,path->indexOf(F("/lights"))); // Remove until /lights
if (path->endsWith("/lights")) { // Got /lights if (path->endsWith(F("/lights"))) { // Got /lights
response = "{"; response = "{";
bool appending = false; bool appending = false;
CheckHue(&response, appending); CheckHue(&response, appending);
@ -718,9 +718,9 @@ void HueLights(String *path)
#endif #endif
response += "}"; response += "}";
} }
else if (path->endsWith("/state")) { // Got ID/state else if (path->endsWith(F("/state"))) { // Got ID/state
path->remove(0,8); // Remove /lights/ path->remove(0,8); // Remove /lights/
path->remove(path->indexOf("/state")); // Remove /state path->remove(path->indexOf(F("/state"))); // Remove /state
device_id = atoi(path->c_str()); device_id = atoi(path->c_str());
device = DecodeLightId(device_id); device = DecodeLightId(device_id);
#ifdef USE_ZIGBEE #ifdef USE_ZIGBEE
@ -741,8 +741,8 @@ void HueLights(String *path)
} }
} }
else if(path->indexOf("/lights/") >= 0) { // Got /lights/ID else if(path->indexOf(F("/lights/")) >= 0) { // Got /lights/ID
AddLog_P2(LOG_LEVEL_DEBUG_MORE, "/lights path=%s", path->c_str()); AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR("/lights path=%s"), path->c_str());
path->remove(0,8); // Remove /lights/ path->remove(0,8); // Remove /lights/
device_id = atoi(path->c_str()); device_id = atoi(path->c_str());
device = DecodeLightId(device_id); device = DecodeLightId(device_id);

View File

@ -305,6 +305,15 @@ ZBM(ZBS_PERMITJOINREQ_CLOSE, Z_SREQ | Z_ZDO, ZDO_MGMT_PERMIT_JOIN_REQ, 0x02 /* A
ZBM(ZBR_PERMITJOINREQ, Z_SRSP | Z_ZDO, ZDO_MGMT_PERMIT_JOIN_REQ, Z_SUCCESS) // 653600 ZBM(ZBR_PERMITJOINREQ, Z_SRSP | Z_ZDO, ZDO_MGMT_PERMIT_JOIN_REQ, Z_SUCCESS) // 653600
ZBM(ZBR_PERMITJOIN_AREQ_RSP, Z_AREQ | Z_ZDO, ZDO_MGMT_PERMIT_JOIN_RSP, 0x00, 0x00 /* srcAddr*/, Z_SUCCESS ) // 45B6000000 ZBM(ZBR_PERMITJOIN_AREQ_RSP, Z_AREQ | Z_ZDO, ZDO_MGMT_PERMIT_JOIN_RSP, 0x00, 0x00 /* srcAddr*/, Z_SUCCESS ) // 45B6000000
const char kCheckingDeviceConfiguration[] PROGMEM = D_LOG_ZIGBEE "checking device configuration";
const char kConfigured[] PROGMEM = "Configured, starting coordinator";
const char kStarted[] PROGMEM = "Started";
const char kZigbeeStarted[] PROGMEM = D_LOG_ZIGBEE "Zigbee started";
const char kResetting[] PROGMEM = "Resetting configuration";
const char kZNP12[] PROGMEM = "Only ZNP 1.2 is currently supported";
const char kAbort[] PROGMEM = "Abort";
const char kZigbeeAbort[] PROGMEM = D_LOG_ZIGBEE "Abort";
static const Zigbee_Instruction zb_prog[] PROGMEM = { static const Zigbee_Instruction zb_prog[] PROGMEM = {
ZI_LABEL(0) ZI_LABEL(0)
ZI_NOOP() ZI_NOOP()
@ -319,7 +328,7 @@ static const Zigbee_Instruction zb_prog[] PROGMEM = {
ZI_SEND(ZBS_RESET) // reboot cc2530 just in case we rebooted ESP8266 but not cc2530 ZI_SEND(ZBS_RESET) // reboot cc2530 just in case we rebooted ESP8266 but not cc2530
ZI_WAIT_RECV_FUNC(5000, ZBR_RESET, &Z_Reboot) // timeout 5s ZI_WAIT_RECV_FUNC(5000, ZBR_RESET, &Z_Reboot) // timeout 5s
ZI_WAIT(100) ZI_WAIT(100)
ZI_LOG(LOG_LEVEL_DEBUG, D_LOG_ZIGBEE "checking device configuration") ZI_LOG(LOG_LEVEL_DEBUG, kCheckingDeviceConfiguration)
ZI_SEND(ZBS_ZNPHC) // check value of ZNP Has Configured ZI_SEND(ZBS_ZNPHC) // check value of ZNP Has Configured
ZI_WAIT_RECV(2000, ZBR_ZNPHC) ZI_WAIT_RECV(2000, ZBR_ZNPHC)
ZI_SEND(ZBS_VERSION) // check ZNP software version ZI_SEND(ZBS_VERSION) // check ZNP software version
@ -338,7 +347,7 @@ static const Zigbee_Instruction zb_prog[] PROGMEM = {
// all is good, we can start // all is good, we can start
ZI_LABEL(ZIGBEE_LABEL_START) // START ZNP App ZI_LABEL(ZIGBEE_LABEL_START) // START ZNP App
ZI_MQTT_STATE(ZIGBEE_STATUS_STARTING, "Configured, starting coordinator") ZI_MQTT_STATE(ZIGBEE_STATUS_STARTING, kConfigured)
ZI_ON_ERROR_GOTO(ZIGBEE_LABEL_ABORT) ZI_ON_ERROR_GOTO(ZIGBEE_LABEL_ABORT)
// Z_ZDO:startupFromApp // Z_ZDO:startupFromApp
//ZI_LOG(LOG_LEVEL_INFO, D_LOG_ZIGBEE "starting zigbee coordinator") //ZI_LOG(LOG_LEVEL_INFO, D_LOG_ZIGBEE "starting zigbee coordinator")
@ -367,8 +376,8 @@ ZI_SEND(ZBS_STARTUPFROMAPP) // start coordinator
ZI_WAIT_UNTIL(1000, ZBR_PERMITJOIN_AREQ_RSP) ZI_WAIT_UNTIL(1000, ZBR_PERMITJOIN_AREQ_RSP)
ZI_LABEL(ZIGBEE_LABEL_READY) ZI_LABEL(ZIGBEE_LABEL_READY)
ZI_MQTT_STATE(ZIGBEE_STATUS_OK, "Started") ZI_MQTT_STATE(ZIGBEE_STATUS_OK, kStarted)
ZI_LOG(LOG_LEVEL_INFO, D_LOG_ZIGBEE "Zigbee started") ZI_LOG(LOG_LEVEL_INFO, kZigbeeStarted)
ZI_CALL(&Z_State_Ready, 1) // Now accept incoming messages ZI_CALL(&Z_State_Ready, 1) // Now accept incoming messages
ZI_CALL(&Z_Load_Devices, 0) ZI_CALL(&Z_Load_Devices, 0)
ZI_CALL(&Z_Query_Bulbs, 0) ZI_CALL(&Z_Query_Bulbs, 0)
@ -377,7 +386,7 @@ ZI_SEND(ZBS_STARTUPFROMAPP) // start coordinator
ZI_GOTO(ZIGBEE_LABEL_READY) ZI_GOTO(ZIGBEE_LABEL_READY)
ZI_LABEL(50) // reformat device ZI_LABEL(50) // reformat device
ZI_MQTT_STATE(ZIGBEE_STATUS_RESET_CONF, "Reseting configuration") ZI_MQTT_STATE(ZIGBEE_STATUS_RESET_CONF, kResetting)
//ZI_LOG(LOG_LEVEL_INFO, D_LOG_ZIGBEE "zigbee bad configuration of device, doing a factory reset") //ZI_LOG(LOG_LEVEL_INFO, D_LOG_ZIGBEE "zigbee bad configuration of device, doing a factory reset")
ZI_ON_ERROR_GOTO(ZIGBEE_LABEL_ABORT) ZI_ON_ERROR_GOTO(ZIGBEE_LABEL_ABORT)
ZI_SEND(ZBS_FACTRES) // factory reset ZI_SEND(ZBS_FACTRES) // factory reset
@ -410,12 +419,12 @@ ZI_SEND(ZBS_STARTUPFROMAPP) // start coordinator
ZI_GOTO(ZIGBEE_LABEL_START) ZI_GOTO(ZIGBEE_LABEL_START)
ZI_LABEL(ZIGBEE_LABEL_UNSUPPORTED_VERSION) ZI_LABEL(ZIGBEE_LABEL_UNSUPPORTED_VERSION)
ZI_MQTT_STATE(ZIGBEE_STATUS_UNSUPPORTED_VERSION, "Only ZNP 1.2 is currently supported") ZI_MQTT_STATE(ZIGBEE_STATUS_UNSUPPORTED_VERSION, kZNP12)
ZI_GOTO(ZIGBEE_LABEL_ABORT) ZI_GOTO(ZIGBEE_LABEL_ABORT)
ZI_LABEL(ZIGBEE_LABEL_ABORT) // Label 99: abort ZI_LABEL(ZIGBEE_LABEL_ABORT) // Label 99: abort
ZI_MQTT_STATE(ZIGBEE_STATUS_ABORT, "Abort") ZI_MQTT_STATE(ZIGBEE_STATUS_ABORT, kAbort)
ZI_LOG(LOG_LEVEL_ERROR, D_LOG_ZIGBEE "Abort") ZI_LOG(LOG_LEVEL_ERROR, kZigbeeAbort)
ZI_STOP(ZIGBEE_LABEL_ABORT) ZI_STOP(ZIGBEE_LABEL_ABORT)
}; };
@ -573,10 +582,15 @@ void ZigbeeStateMachine_Run(void) {
AddLog_P(cur_d8, (char*) cur_ptr1); AddLog_P(cur_d8, (char*) cur_ptr1);
break; break;
case ZGB_INSTR_MQTT_STATE: case ZGB_INSTR_MQTT_STATE:
{
const char *f_msg = (const char*) cur_ptr1;
char buf[strlen_P(f_msg) + 1];
strcpy_P(buf, f_msg);
Response_P(PSTR("{\"" D_JSON_ZIGBEE_STATE "\":{\"Status\":%d,\"Message\":\"%s\"}}"), Response_P(PSTR("{\"" D_JSON_ZIGBEE_STATE "\":{\"Status\":%d,\"Message\":\"%s\"}}"),
cur_d8, (char*) cur_ptr1); cur_d8, buf);
MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_JSON_ZIGBEE_STATE)); MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_JSON_ZIGBEE_STATE));
XdrvRulesProcess(); XdrvRulesProcess();
}
break; break;
case ZGB_INSTR_SEND: case ZGB_INSTR_SEND:
ZigbeeZNPSend((uint8_t*) cur_ptr1, cur_d8 /* len */); ZigbeeZNPSend((uint8_t*) cur_ptr1, cur_d8 /* len */);

View File

@ -94,9 +94,9 @@ int32_t Z_Reboot(int32_t res, class SBuffer &buf) {
GetTextIndexed(reason_str, sizeof(reason_str), reason, Z_RebootReason); GetTextIndexed(reason_str, sizeof(reason_str), reason, Z_RebootReason);
Response_P(PSTR("{\"" D_JSON_ZIGBEE_STATE "\":{" Response_P(PSTR("{\"" D_JSON_ZIGBEE_STATE "\":{"
"\"Status\":%d,\"Message\":\"%s\",\"RestartReason\":\"%s\"" "\"Status\":%d,\"Message\":\"CC2530 booted\",\"RestartReason\":\"%s\""
",\"MajorRel\":%d,\"MinorRel\":%d}}"), ",\"MajorRel\":%d,\"MinorRel\":%d}}"),
ZIGBEE_STATUS_BOOT, "CC2530 booted", reason_str, ZIGBEE_STATUS_BOOT, reason_str,
major_rel, minor_rel); major_rel, minor_rel);
MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_JSON_ZIGBEE_STATE)); MqttPublishPrefixTopic_P(RESULT_OR_TELE, PSTR(D_JSON_ZIGBEE_STATE));

View File

@ -271,10 +271,10 @@ void CmndZbReset(void) {
ZigbeeZNPSend(ZIGBEE_FACTORY_RESET, sizeof(ZIGBEE_FACTORY_RESET)); ZigbeeZNPSend(ZIGBEE_FACTORY_RESET, sizeof(ZIGBEE_FACTORY_RESET));
eraseZigbeeDevices(); eraseZigbeeDevices();
restart_flag = 2; restart_flag = 2;
ResponseCmndChar(D_JSON_ZIGBEE_CC2530 " " D_JSON_RESET_AND_RESTARTING); ResponseCmndChar_P(PSTR(D_JSON_ZIGBEE_CC2530 " " D_JSON_RESET_AND_RESTARTING));
break; break;
default: default:
ResponseCmndChar(D_JSON_ONE_TO_RESET); ResponseCmndChar_P(PSTR(D_JSON_ONE_TO_RESET));
} }
} }
} }
@ -425,10 +425,10 @@ void CmndZbSend(void) {
// ZigbeeSend { "devicse":"0x1234", "endpoint":"0x03", "send":{"Power":1} } // ZigbeeSend { "devicse":"0x1234", "endpoint":"0x03", "send":{"Power":1} }
// ZigbeeSend { "device":"0x1234", "endpoint":"0x03", "send":{"Color":"1,2"} } // ZigbeeSend { "device":"0x1234", "endpoint":"0x03", "send":{"Color":"1,2"} }
// ZigbeeSend { "device":"0x1234", "endpoint":"0x03", "send":{"Color":"0x1122,0xFFEE"} } // ZigbeeSend { "device":"0x1234", "endpoint":"0x03", "send":{"Color":"0x1122,0xFFEE"} }
if (zigbee.init_phase) { ResponseCmndChar(D_ZIGBEE_NOT_STARTED); return; } if (zigbee.init_phase) { ResponseCmndChar_P(PSTR(D_ZIGBEE_NOT_STARTED)); return; }
DynamicJsonBuffer jsonBuf; DynamicJsonBuffer jsonBuf;
JsonObject &json = jsonBuf.parseObject(XdrvMailbox.data); JsonObject &json = jsonBuf.parseObject(XdrvMailbox.data);
if (!json.success()) { ResponseCmndChar(D_JSON_INVALID_JSON); return; } if (!json.success()) { ResponseCmndChar_P(PSTR(D_JSON_INVALID_JSON)); return; }
// params // params
static char delim[] = ", "; // delimiters for parameters static char delim[] = ", "; // delimiters for parameters
@ -449,9 +449,9 @@ void CmndZbSend(void) {
const JsonVariant &val_device = getCaseInsensitive(json, PSTR("Device")); const JsonVariant &val_device = getCaseInsensitive(json, PSTR("Device"));
if (nullptr != &val_device) { if (nullptr != &val_device) {
device = zigbee_devices.parseDeviceParam(val_device.as<char*>()); device = zigbee_devices.parseDeviceParam(val_device.as<char*>());
if (0xFFFF == device) { ResponseCmndChar("Invalid parameter"); return; } if (0xFFFF == device) { ResponseCmndChar_P(PSTR("Invalid parameter")); return; }
} }
if ((nullptr == &val_device) || (0x0000 == device)) { ResponseCmndChar("Unknown device"); return; } if ((nullptr == &val_device) || (0x0000 == device)) { ResponseCmndChar_P(PSTR("Unknown device")); return; }
} }
const JsonVariant &val_endpoint = getCaseInsensitive(json, PSTR("Endpoint")); const JsonVariant &val_endpoint = getCaseInsensitive(json, PSTR("Endpoint"));
@ -541,7 +541,7 @@ void CmndZbSend(void) {
if ('_' == *data) { clusterSpecific = false; } if ('_' == *data) { clusterSpecific = false; }
data++; data++;
} else { } else {
ResponseCmndChar("Wrong delimiter for payload"); ResponseCmndChar_P(PSTR("Wrong delimiter for payload"));
return; return;
} }
// parse cmd number // parse cmd number
@ -571,10 +571,10 @@ void CmndZbBind(void) {
// ZbBind { "device":"0x1234", "endpoint":1, "cluster":6 } // ZbBind { "device":"0x1234", "endpoint":1, "cluster":6 }
// local endpoint is always 1, IEEE addresses are calculated // local endpoint is always 1, IEEE addresses are calculated
if (zigbee.init_phase) { ResponseCmndChar(D_ZIGBEE_NOT_STARTED); return; } if (zigbee.init_phase) { ResponseCmndChar_P(PSTR(D_ZIGBEE_NOT_STARTED)); return; }
DynamicJsonBuffer jsonBuf; DynamicJsonBuffer jsonBuf;
JsonObject &json = jsonBuf.parseObject(XdrvMailbox.data); JsonObject &json = jsonBuf.parseObject(XdrvMailbox.data);
if (!json.success()) { ResponseCmndChar(D_JSON_INVALID_JSON); return; } if (!json.success()) { ResponseCmndChar_P(PSTR(D_JSON_INVALID_JSON)); return; }
// params // params
// static char delim[] = ", "; // delimiters for parameters // static char delim[] = ", "; // delimiters for parameters
@ -592,12 +592,12 @@ void CmndZbBind(void) {
const JsonVariant &val_device = getCaseInsensitive(json, PSTR("Device")); const JsonVariant &val_device = getCaseInsensitive(json, PSTR("Device"));
if (nullptr != &val_device) { if (nullptr != &val_device) {
srcDevice = zigbee_devices.parseDeviceParam(val_device.as<char*>()); srcDevice = zigbee_devices.parseDeviceParam(val_device.as<char*>());
if (0xFFFF == srcDevice) { ResponseCmndChar("Invalid parameter"); return; } if (0xFFFF == srcDevice) { ResponseCmndChar_P(PSTR("Invalid parameter")); return; }
} }
if ((nullptr == &val_device) || (0x0000 == srcDevice)) { ResponseCmndChar("Unknown source device"); return; } if ((nullptr == &val_device) || (0x0000 == srcDevice)) { ResponseCmndChar_P(PSTR("Unknown source device")); return; }
// check if IEEE address is known // check if IEEE address is known
uint64_t srcLongAddr = zigbee_devices.getDeviceLongAddr(srcDevice); uint64_t srcLongAddr = zigbee_devices.getDeviceLongAddr(srcDevice);
if (0 == srcLongAddr) { ResponseCmndChar("Unknown source IEEE address"); return; } if (0 == srcLongAddr) { ResponseCmndChar_P(PSTR("Unknown source IEEE address")); return; }
// look for source endpoint // look for source endpoint
const JsonVariant &val_endpoint = getCaseInsensitive(json, PSTR("Endpoint")); const JsonVariant &val_endpoint = getCaseInsensitive(json, PSTR("Endpoint"));
if (nullptr != &val_endpoint) { endpoint = strToUInt(val_endpoint); } if (nullptr != &val_endpoint) { endpoint = strToUInt(val_endpoint); }
@ -612,13 +612,13 @@ void CmndZbBind(void) {
const JsonVariant &dst_device = getCaseInsensitive(json, PSTR("ToDevice")); const JsonVariant &dst_device = getCaseInsensitive(json, PSTR("ToDevice"));
if (nullptr != &dst_device) { if (nullptr != &dst_device) {
dstDevice = zigbee_devices.parseDeviceParam(dst_device.as<char*>()); dstDevice = zigbee_devices.parseDeviceParam(dst_device.as<char*>());
if (0xFFFF == dstDevice) { ResponseCmndChar("Invalid parameter"); return; } if (0xFFFF == dstDevice) { ResponseCmndChar_P(PSTR("Invalid parameter")); return; }
if (0x0000 == dstDevice) { if (0x0000 == dstDevice) {
dstLongAddr = localIEEEAddr; dstLongAddr = localIEEEAddr;
} else { } else {
dstLongAddr = zigbee_devices.getDeviceLongAddr(dstDevice); dstLongAddr = zigbee_devices.getDeviceLongAddr(dstDevice);
} }
if (0 == dstLongAddr) { ResponseCmndChar("Unknown dest IEEE address"); return; } if (0 == dstLongAddr) { ResponseCmndChar_P(PSTR("Unknown dest IEEE address")); return; }
const JsonVariant &val_toendpoint = getCaseInsensitive(json, PSTR("ToEndpoint")); const JsonVariant &val_toendpoint = getCaseInsensitive(json, PSTR("ToEndpoint"));
if (nullptr != &val_toendpoint) { toendpoint = strToUInt(val_endpoint); } else { toendpoint = endpoint; } if (nullptr != &val_toendpoint) { toendpoint = strToUInt(val_endpoint); } else { toendpoint = endpoint; }
@ -629,8 +629,8 @@ void CmndZbBind(void) {
if (nullptr != &to_group) { toGroup = strToUInt(to_group); } if (nullptr != &to_group) { toGroup = strToUInt(to_group); }
// make sure we don't have conflicting parameters // make sure we don't have conflicting parameters
if (toGroup && dstLongAddr) { ResponseCmndChar("Cannot have both \"ToDevice\" and \"ToGroup\""); return; } if (toGroup && dstLongAddr) { ResponseCmndChar_P(PSTR("Cannot have both \"ToDevice\" and \"ToGroup\"")); return; }
if (!toGroup && !dstLongAddr) { ResponseCmndChar("Missing \"ToDevice\" or \"ToGroup\""); return; } if (!toGroup && !dstLongAddr) { ResponseCmndChar_P(PSTR("Missing \"ToDevice\" or \"ToGroup\"")); return; }
SBuffer buf(34); SBuffer buf(34);
buf.add8(Z_SREQ | Z_ZDO); buf.add8(Z_SREQ | Z_ZDO);
@ -659,10 +659,10 @@ void CmndZbProbe(void) {
} }
void CmndZbProbeOrPing(boolean probe) { void CmndZbProbeOrPing(boolean probe) {
if (zigbee.init_phase) { ResponseCmndChar(D_ZIGBEE_NOT_STARTED); return; } if (zigbee.init_phase) { ResponseCmndChar_P(PSTR(D_ZIGBEE_NOT_STARTED)); return; }
uint16_t shortaddr = zigbee_devices.parseDeviceParam(XdrvMailbox.data); uint16_t shortaddr = zigbee_devices.parseDeviceParam(XdrvMailbox.data);
if (0x0000 == shortaddr) { ResponseCmndChar("Unknown device"); return; } if (0x0000 == shortaddr) { ResponseCmndChar_P(PSTR("Unknown device")); return; }
if (0xFFFF == shortaddr) { ResponseCmndChar("Invalid parameter"); return; } if (0xFFFF == shortaddr) { ResponseCmndChar_P(PSTR("Invalid parameter")); return; }
// everything is good, we can send the command // everything is good, we can send the command
Z_SendIEEEAddrReq(shortaddr); Z_SendIEEEAddrReq(shortaddr);
@ -686,7 +686,7 @@ void CmndZbName(void) {
// //
// Where <device_id> can be: short_addr, long_addr, device_index, friendly_name // Where <device_id> can be: short_addr, long_addr, device_index, friendly_name
if (zigbee.init_phase) { ResponseCmndChar(D_ZIGBEE_NOT_STARTED); return; } if (zigbee.init_phase) { ResponseCmndChar_P(PSTR(D_ZIGBEE_NOT_STARTED)); return; }
// check if parameters contain a comma ',' // check if parameters contain a comma ','
char *p; char *p;
@ -694,8 +694,8 @@ void CmndZbName(void) {
// parse first part, <device_id> // parse first part, <device_id>
uint16_t shortaddr = zigbee_devices.parseDeviceParam(XdrvMailbox.data, true); // in case of short_addr, it must be already registered uint16_t shortaddr = zigbee_devices.parseDeviceParam(XdrvMailbox.data, true); // in case of short_addr, it must be already registered
if (0x0000 == shortaddr) { ResponseCmndChar("Unknown device"); return; } if (0x0000 == shortaddr) { ResponseCmndChar_P(PSTR("Unknown device")); return; }
if (0xFFFF == shortaddr) { ResponseCmndChar("Invalid parameter"); return; } if (0xFFFF == shortaddr) { ResponseCmndChar_P(PSTR("Invalid parameter")); return; }
if (p == nullptr) { if (p == nullptr) {
const char * friendlyName = zigbee_devices.getFriendlyName(shortaddr); const char * friendlyName = zigbee_devices.getFriendlyName(shortaddr);
@ -715,7 +715,7 @@ void CmndZbModelId(void) {
// //
// Where <device_id> can be: short_addr, long_addr, device_index, friendly_name // Where <device_id> can be: short_addr, long_addr, device_index, friendly_name
if (zigbee.init_phase) { ResponseCmndChar(D_ZIGBEE_NOT_STARTED); return; } if (zigbee.init_phase) { ResponseCmndChar_P(PSTR(D_ZIGBEE_NOT_STARTED)); return; }
// check if parameters contain a comma ',' // check if parameters contain a comma ','
char *p; char *p;
@ -723,8 +723,8 @@ void CmndZbModelId(void) {
// parse first part, <device_id> // parse first part, <device_id>
uint16_t shortaddr = zigbee_devices.parseDeviceParam(XdrvMailbox.data, true); // in case of short_addr, it must be already registered uint16_t shortaddr = zigbee_devices.parseDeviceParam(XdrvMailbox.data, true); // in case of short_addr, it must be already registered
if (0x0000 == shortaddr) { ResponseCmndChar("Unknown device"); return; } if (0x0000 == shortaddr) { ResponseCmndChar_P(PSTR("Unknown device")); return; }
if (0xFFFF == shortaddr) { ResponseCmndChar("Invalid parameter"); return; } if (0xFFFF == shortaddr) { ResponseCmndChar_P(PSTR("Invalid parameter")); return; }
if (p == nullptr) { if (p == nullptr) {
const char * modelId = zigbee_devices.getModelId(shortaddr); const char * modelId = zigbee_devices.getModelId(shortaddr);
@ -743,7 +743,7 @@ void CmndZbLight(void) {
// //
// Where <device_id> can be: short_addr, long_addr, device_index, friendly_name // Where <device_id> can be: short_addr, long_addr, device_index, friendly_name
if (zigbee.init_phase) { ResponseCmndChar(D_ZIGBEE_NOT_STARTED); return; } if (zigbee.init_phase) { ResponseCmndChar_P(PSTR(D_ZIGBEE_NOT_STARTED)); return; }
// check if parameters contain a comma ',' // check if parameters contain a comma ','
char *p; char *p;
@ -751,8 +751,8 @@ void CmndZbLight(void) {
// parse first part, <device_id> // parse first part, <device_id>
uint16_t shortaddr = zigbee_devices.parseDeviceParam(XdrvMailbox.data, true); // in case of short_addr, it must be already registered uint16_t shortaddr = zigbee_devices.parseDeviceParam(XdrvMailbox.data, true); // in case of short_addr, it must be already registered
if (0x0000 == shortaddr) { ResponseCmndChar("Unknown device"); return; } if (0x0000 == shortaddr) { ResponseCmndChar_P(PSTR("Unknown device")); return; }
if (0xFFFF == shortaddr) { ResponseCmndChar("Invalid parameter"); return; } if (0xFFFF == shortaddr) { ResponseCmndChar_P(PSTR("Invalid parameter")); return; }
if (p) { if (p) {
int8_t bulbtype = strtol(p, nullptr, 10); int8_t bulbtype = strtol(p, nullptr, 10);
@ -768,22 +768,22 @@ void CmndZbLight(void) {
// Remove an old Zigbee device from the list of known devices, use ZigbeeStatus to know all registered devices // Remove an old Zigbee device from the list of known devices, use ZigbeeStatus to know all registered devices
void CmndZbForget(void) { void CmndZbForget(void) {
if (zigbee.init_phase) { ResponseCmndChar(D_ZIGBEE_NOT_STARTED); return; } if (zigbee.init_phase) { ResponseCmndChar_P(PSTR(D_ZIGBEE_NOT_STARTED)); return; }
uint16_t shortaddr = zigbee_devices.parseDeviceParam(XdrvMailbox.data); uint16_t shortaddr = zigbee_devices.parseDeviceParam(XdrvMailbox.data);
if (0x0000 == shortaddr) { ResponseCmndChar("Unknown device"); return; } if (0x0000 == shortaddr) { ResponseCmndChar_P(PSTR("Unknown device")); return; }
if (0xFFFF == shortaddr) { ResponseCmndChar("Invalid parameter"); return; } if (0xFFFF == shortaddr) { ResponseCmndChar_P(PSTR("Invalid parameter")); return; }
// everything is good, we can send the command // everything is good, we can send the command
if (zigbee_devices.removeDevice(shortaddr)) { if (zigbee_devices.removeDevice(shortaddr)) {
ResponseCmndDone(); ResponseCmndDone();
} else { } else {
ResponseCmndChar("Unknown device"); ResponseCmndChar_P(PSTR("Unknown device"));
} }
} }
// Save Zigbee information to flash // Save Zigbee information to flash
void CmndZbSave(void) { void CmndZbSave(void) {
if (zigbee.init_phase) { ResponseCmndChar(D_ZIGBEE_NOT_STARTED); return; } if (zigbee.init_phase) { ResponseCmndChar_P(PSTR(D_ZIGBEE_NOT_STARTED)); return; }
saveZigbeeDevices(); saveZigbeeDevices();
@ -795,10 +795,10 @@ void CmndZbRead(void) {
// ZigbeeRead {"Device":"0xF289","Cluster":0,"Endpoint":3,"Attr":5} // ZigbeeRead {"Device":"0xF289","Cluster":0,"Endpoint":3,"Attr":5}
// ZigbeeRead {"Device":"0xF289","Cluster":"0x0000","Endpoint":"0x0003","Attr":"0x0005"} // ZigbeeRead {"Device":"0xF289","Cluster":"0x0000","Endpoint":"0x0003","Attr":"0x0005"}
// ZigbeeRead {"Device":"0xF289","Cluster":0,"Endpoint":3,"Attr":[5,6,7,4]} // ZigbeeRead {"Device":"0xF289","Cluster":0,"Endpoint":3,"Attr":[5,6,7,4]}
if (zigbee.init_phase) { ResponseCmndChar(D_ZIGBEE_NOT_STARTED); return; } if (zigbee.init_phase) { ResponseCmndChar_P(PSTR(D_ZIGBEE_NOT_STARTED)); return; }
DynamicJsonBuffer jsonBuf; DynamicJsonBuffer jsonBuf;
JsonObject &json = jsonBuf.parseObject(XdrvMailbox.data); JsonObject &json = jsonBuf.parseObject(XdrvMailbox.data);
if (!json.success()) { ResponseCmndChar(D_JSON_INVALID_JSON); return; } if (!json.success()) { ResponseCmndChar_P(PSTR(D_JSON_INVALID_JSON)); return; }
// params // params
uint16_t device = 0xFFFF; // 0xFFFF is braodcast, so considered valid uint16_t device = 0xFFFF; // 0xFFFF is braodcast, so considered valid
@ -814,9 +814,9 @@ void CmndZbRead(void) {
const JsonVariant &val_device = getCaseInsensitive(json, PSTR("Device")); const JsonVariant &val_device = getCaseInsensitive(json, PSTR("Device"));
if (nullptr != &val_device) { if (nullptr != &val_device) {
device = zigbee_devices.parseDeviceParam(val_device.as<char*>()); device = zigbee_devices.parseDeviceParam(val_device.as<char*>());
if (0xFFFF == device) { ResponseCmndChar("Invalid parameter"); return; } if (0xFFFF == device) { ResponseCmndChar_P(PSTR("Invalid parameter")); return; }
} }
if ((nullptr == &val_device) || (0x0000 == device)) { ResponseCmndChar("Unknown device"); return; } if ((nullptr == &val_device) || (0x0000 == device)) { ResponseCmndChar_P(PSTR("Unknown device")); return; }
} }
const JsonVariant &val_cluster = getCaseInsensitive(json, PSTR("Cluster")); const JsonVariant &val_cluster = getCaseInsensitive(json, PSTR("Cluster"));
@ -858,7 +858,7 @@ void CmndZbRead(void) {
ZigbeeZCLSend_Raw(device, groupaddr, cluster, endpoint, ZCL_READ_ATTRIBUTES, false, attrs, attrs_len, true /* we do want a response */, zigbee_devices.getNextSeqNumber(device)); ZigbeeZCLSend_Raw(device, groupaddr, cluster, endpoint, ZCL_READ_ATTRIBUTES, false, attrs, attrs_len, true /* we do want a response */, zigbee_devices.getNextSeqNumber(device));
ResponseCmndDone(); ResponseCmndDone();
} else { } else {
ResponseCmndChar("Missing parameters"); ResponseCmndChar_P(PSTR("Missing parameters"));
} }
if (attrs) { delete[] attrs; } if (attrs) { delete[] attrs; }
@ -866,7 +866,7 @@ void CmndZbRead(void) {
// Allow or Deny pairing of new Zigbee devices // Allow or Deny pairing of new Zigbee devices
void CmndZbPermitJoin(void) { void CmndZbPermitJoin(void) {
if (zigbee.init_phase) { ResponseCmndChar(D_ZIGBEE_NOT_STARTED); return; } if (zigbee.init_phase) { ResponseCmndChar_P(PSTR(D_ZIGBEE_NOT_STARTED)); return; }
uint32_t payload = XdrvMailbox.payload; uint32_t payload = XdrvMailbox.payload;
uint16_t dstAddr = 0xFFFC; // default addr uint16_t dstAddr = 0xFFFC; // default addr
uint8_t duration = 60; // default 60s uint8_t duration = 60; // default 60s
@ -892,11 +892,11 @@ void CmndZbPermitJoin(void) {
void CmndZbStatus(void) { void CmndZbStatus(void) {
if (ZigbeeSerial) { if (ZigbeeSerial) {
if (zigbee.init_phase) { ResponseCmndChar(D_ZIGBEE_NOT_STARTED); return; } if (zigbee.init_phase) { ResponseCmndChar_P(PSTR(D_ZIGBEE_NOT_STARTED)); return; }
uint16_t shortaddr = zigbee_devices.parseDeviceParam(XdrvMailbox.data); uint16_t shortaddr = zigbee_devices.parseDeviceParam(XdrvMailbox.data);
if (0xFFFF == shortaddr) { ResponseCmndChar("Invalid parameter"); return; } if (0xFFFF == shortaddr) { ResponseCmndChar_P(PSTR("Invalid parameter")); return; }
if (XdrvMailbox.payload > 0) { if (XdrvMailbox.payload > 0) {
if (0x0000 == shortaddr) { ResponseCmndChar("Unknown device"); return; } if (0x0000 == shortaddr) { ResponseCmndChar_P(PSTR("Unknown device")); return; }
} }
String dump = zigbee_devices.dump(XdrvMailbox.index, shortaddr); String dump = zigbee_devices.dump(XdrvMailbox.index, shortaddr);