mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-24 11:46:34 +00:00
Add jsonl command
This commit is contained in:
parent
f2277d57ff
commit
1d7cdccc5f
@ -23,15 +23,36 @@ void dispatchStatusUpdate()
|
||||
mqttStatusUpdate();
|
||||
}
|
||||
|
||||
void dispatchOutput(int output, bool state)
|
||||
{
|
||||
int pin = 0;
|
||||
|
||||
if(pin >= 0) {
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
ledcWrite(99, state ? 1023 : 0); // ledChannel and value
|
||||
#else
|
||||
analogWrite(pin, state ? 1023 : 0);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
// objectattribute=value
|
||||
void IRAM_ATTR dispatchAttribute(String & strTopic, const char * payload)
|
||||
{
|
||||
if(strTopic.startsWith("p[")) {
|
||||
String strPageId = strTopic.substring(2, strTopic.indexOf("]"));
|
||||
String strTemp = strTopic.substring(strTopic.indexOf("]") + 1, strTopic.length());
|
||||
String strPageId((char *)0);
|
||||
String strTemp((char *)0);
|
||||
|
||||
strPageId = strTopic.substring(2, strTopic.indexOf("]"));
|
||||
strTemp = strTopic.substring(strTopic.indexOf("]") + 1, strTopic.length());
|
||||
|
||||
if(strTemp.startsWith(".b[")) {
|
||||
String strObjId = strTemp.substring(3, strTemp.indexOf("]"));
|
||||
String strAttr = strTemp.substring(strTemp.indexOf("]") + 1, strTemp.length());
|
||||
String strObjId((char *)0);
|
||||
String strAttr((char *)0);
|
||||
|
||||
strObjId = strTemp.substring(3, strTemp.indexOf("]"));
|
||||
strAttr = strTemp.substring(strTemp.indexOf("]") + 1, strTemp.length());
|
||||
// debugPrintln(strPageId + " && " + strObjId + " && " + strAttr);
|
||||
|
||||
int pageid = strPageId.toInt();
|
||||
@ -41,14 +62,24 @@ void IRAM_ATTR dispatchAttribute(String & strTopic, const char * payload)
|
||||
haspProcessAttribute((uint8_t)pageid, (uint8_t)objid, strAttr, payload);
|
||||
} // valid page
|
||||
}
|
||||
} else if(strTopic == "page") {
|
||||
|
||||
} else if(strTopic == F("page")) {
|
||||
dispatchPage(payload);
|
||||
} else if(strTopic == "dim") {
|
||||
|
||||
} else if(strTopic == F("dim") || strTopic == F("brightness")) {
|
||||
dispatchDim(payload);
|
||||
|
||||
} else if(strTopic == F("light")) {
|
||||
dispatchBacklight(payload);
|
||||
|
||||
} else if(strTopic.length() == 7 && strTopic.startsWith(F("output"))) {
|
||||
String strTemp((char *)0);
|
||||
strTemp = strTopic.substring(7, strTopic.length());
|
||||
dispatchOutput(strTemp.toInt(), true);
|
||||
}
|
||||
}
|
||||
|
||||
void IRAM_ATTR dispatchPage(String strPageid)
|
||||
void dispatchPage(String strPageid)
|
||||
{
|
||||
debugPrintln("PAGE: " + strPageid);
|
||||
|
||||
@ -72,13 +103,33 @@ void dispatchDim(String strDimLevel)
|
||||
}
|
||||
}
|
||||
|
||||
void IRAM_ATTR dispatchCommand(String cmnd)
|
||||
void dispatchBacklight(String strPayload)
|
||||
{
|
||||
debugPrintln("LIGHT: " + strPayload);
|
||||
strPayload.toUpperCase();
|
||||
|
||||
if(strPayload == F("ON")) {
|
||||
guiSetBacklight(true);
|
||||
} else if(strPayload == F("OFF")) {
|
||||
guiSetBacklight(false);
|
||||
} else {
|
||||
String strPayload = String(guiGetBacklight());
|
||||
mqttSendState("light", strPayload.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void dispatchCommand(String cmnd)
|
||||
{
|
||||
debugPrintln("CMND: " + cmnd);
|
||||
|
||||
if(cmnd.startsWith(F("page ")) || cmnd.startsWith(F("page="))) {
|
||||
if(cmnd.startsWith(F("page "))) {
|
||||
cmnd = cmnd.substring(5, cmnd.length());
|
||||
dispatchPage(cmnd);
|
||||
String strTopic((char *)0);
|
||||
strTopic.reserve(127);
|
||||
strTopic = F("page");
|
||||
dispatchAttribute(strTopic, cmnd.c_str());
|
||||
|
||||
// dispatchPage(cmnd);
|
||||
} else if(cmnd == F("calibrate")) {
|
||||
guiCalibrate();
|
||||
} else if(cmnd == F("wakeup")) {
|
||||
@ -93,8 +144,15 @@ void IRAM_ATTR dispatchCommand(String cmnd)
|
||||
|
||||
int pos = cmnd.indexOf("=");
|
||||
if(pos > 0) {
|
||||
String strTopic = cmnd.substring(0, pos);
|
||||
String strPayload = cmnd.substring(pos + 1, cmnd.length());
|
||||
String strTopic((char *)0);
|
||||
String strPayload((char *)0);
|
||||
|
||||
strTopic.reserve(127);
|
||||
strPayload.reserve(127);
|
||||
|
||||
strTopic = cmnd.substring(0, pos);
|
||||
strPayload = cmnd.substring(pos + 1, cmnd.length());
|
||||
|
||||
dispatchAttribute(strTopic, strPayload.c_str());
|
||||
} else {
|
||||
dispatchAttribute(cmnd, "");
|
||||
|
@ -13,6 +13,7 @@ void dispatchJsonl(char * strPayload);
|
||||
|
||||
void dispatchPage(String strPageid);
|
||||
void dispatchDim(String strDimLevel);
|
||||
void dispatchBacklight(String strPayload);
|
||||
|
||||
void dispatchIdle(const __FlashStringHelper * state);
|
||||
void dispatchReboot(bool saveConfig);
|
||||
|
@ -121,10 +121,10 @@ void IRAM_ATTR mqttSendNewValue(uint8_t pageid, uint8_t btnid, String txt)
|
||||
mqttSendNewValue(pageid, btnid, "txt", txt);
|
||||
}
|
||||
|
||||
void IRAM_ATTR mqttSendNewEvent(uint8_t pageid, uint8_t btnid, int32_t val)
|
||||
void IRAM_ATTR mqttSendNewEvent(uint8_t pageid, uint8_t btnid, char * value) // int32_t val)
|
||||
{
|
||||
char value[127];
|
||||
itoa(val, value, 10);
|
||||
// char value[127];
|
||||
// itoa(val, value, 10);
|
||||
mqttSendNewValue(pageid, btnid, "event", value);
|
||||
}
|
||||
|
||||
@ -233,11 +233,6 @@ void mqttCallback(char * topic, byte * payload, unsigned int length)
|
||||
strTopic = strTopic.substring(8u, strTopic.length());
|
||||
// debugPrintln(String(F("MQTT Shorter Command Topic : '")) + strTopic + "'");
|
||||
|
||||
if(length == 0) {
|
||||
dispatchCommand(strTopic.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
if(strTopic == F("json")) { // '[...]/device/command/json' -m '["dim=5", "page 1"]' =
|
||||
// nextionSendCmd("dim=50"), nextionSendCmd("page 1")
|
||||
dispatchJson((char *)payload); // Send to nextionParseJson()
|
||||
@ -245,6 +240,8 @@ void mqttCallback(char * topic, byte * payload, unsigned int length)
|
||||
dispatchJsonl((char *)payload);
|
||||
} else if(strTopic == F("setupap")) {
|
||||
haspDisplayAP("HASP-ABC123", "haspadmin");
|
||||
} else if(length == 0) {
|
||||
dispatchCommand(strTopic.c_str());
|
||||
} else { // '[...]/device/command/p[1].b[4].txt' -m '"Lights On"' ==
|
||||
// nextionSetAttr("p[1].b[4].txt", "\"Lights On\"")
|
||||
dispatchAttribute(strTopic, (char *)payload);
|
||||
|
@ -9,11 +9,11 @@ void mqttStop();
|
||||
void mqttReconnect();
|
||||
|
||||
void mqttSendState(const char * subtopic, const char * payload);
|
||||
void mqttSendNewEvent(uint8_t pageid, uint8_t btnid, int32_t val);
|
||||
void mqttSendNewEvent(uint8_t pageid, uint8_t btnid, char * value); // int32_t val)
|
||||
void mqttSendNewValue(uint8_t pageid, uint8_t btnid, int32_t val);
|
||||
void mqttSendNewValue(uint8_t pageid, uint8_t btnid, String txt);
|
||||
void mqttHandlePage(String strPageid);
|
||||
void mqttStatusUpdate (void);
|
||||
void mqttStatusUpdate(void);
|
||||
bool mqttIsConnected(void);
|
||||
|
||||
bool mqttGetConfig(const JsonObject & settings);
|
||||
|
Loading…
x
Reference in New Issue
Block a user