mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-24 11:46:34 +00:00
Add MQTT_MAX_PACKET_SIZE
This commit is contained in:
parent
18a016ae1a
commit
5a9693ff66
@ -75,7 +75,7 @@ build_flags =
|
||||
-Os ; Code Size Optimization
|
||||
-w ; Suppress warnings
|
||||
-D LV_CONF_INCLUDE_SIMPLE
|
||||
-D SPIFFS_TEMPORAL_FD_CACHE ; speed up opening recent files
|
||||
-D SPIFFS_TEMPORAL_FD_CACHE ; speedup opening recent files
|
||||
-D ARDUINOJSON_DECODE_UNICODE=1 ; for utf-8 symbols
|
||||
-D ARDUINOJSON_ENABLE_PROGMEM=1 ; for PROGMEM arguments
|
||||
-I include ; include lv_conf.h and hasp_conf.h
|
||||
@ -95,6 +95,7 @@ debug_init_break = tbreak setup
|
||||
build_flags =
|
||||
${env.build_flags}
|
||||
; -- TFT_eSPI build options ------------------------
|
||||
-D MQTT_MAX_PACKET_SIZE=2048 ; longer PubSubClient messages
|
||||
-D TFT_ROTATION=${lcd.TFT_ROTATION}
|
||||
-D TFT_WIDTH=${lcd.TFT_WIDTH}
|
||||
-D TFT_HEIGHT=${lcd.TFT_HEIGHT}
|
||||
@ -131,6 +132,7 @@ board_build.partitions = default.csv
|
||||
build_flags =
|
||||
${env.build_flags}
|
||||
; -- TFT_eSPI build options ------------------------
|
||||
-D MQTT_MAX_PACKET_SIZE=2048 ; longer PubSubClient messages
|
||||
-D TFT_ROTATION=${lcd.TFT_ROTATION}
|
||||
-D TFT_WIDTH=${lcd.TFT_WIDTH}
|
||||
-D TFT_HEIGHT=${lcd.TFT_HEIGHT}
|
||||
@ -160,6 +162,7 @@ board_build.partitions = default.csv
|
||||
build_flags =
|
||||
${env.build_flags}
|
||||
; -- TFT_eSPI build options ------------------------
|
||||
-D MQTT_MAX_PACKET_SIZE=2048 ; longer PubSubClient messages
|
||||
-D TFT_ROTATION=${lcd.TFT_ROTATION}
|
||||
-D TFT_WIDTH=${lcd.TFT_WIDTH}
|
||||
-D TFT_HEIGHT=${lcd.TFT_HEIGHT}
|
||||
@ -192,6 +195,7 @@ build_flags =
|
||||
${env.build_flags}
|
||||
-Wl,-Teagle.flash.4m3m.ld
|
||||
; -- TFT_eSPI build options ------------------------
|
||||
-D MQTT_MAX_PACKET_SIZE=512 ; longer PubSubClient messages
|
||||
-D TFT_ROTATION=${lcd.TFT_ROTATION}
|
||||
-D TFT_WIDTH=${lcd.TFT_WIDTH}
|
||||
-D TFT_HEIGHT=${lcd.TFT_HEIGHT}
|
||||
@ -224,6 +228,7 @@ build_flags =
|
||||
${env.build_flags}
|
||||
-Wl,-Teagle.flash.4m3m.ld
|
||||
; -- TFT_eSPI build options ------------------------
|
||||
-D MQTT_MAX_PACKET_SIZE=512 ; longer PubSubClient messages
|
||||
-D TFT_ROTATION=${lcd.TFT_ROTATION}
|
||||
-D TFT_WIDTH=${lcd.TFT_WIDTH}
|
||||
-D TFT_HEIGHT=${lcd.TFT_HEIGHT}
|
||||
|
@ -16,7 +16,7 @@ void dispatchLoop()
|
||||
{}
|
||||
|
||||
// objectattribute=value
|
||||
void IRAM_ATTR dispatchAttribute(String & strTopic, String & strPayload)
|
||||
void IRAM_ATTR dispatchAttribute(String & strTopic, const char * payload)
|
||||
{
|
||||
if(strTopic.startsWith("p[")) {
|
||||
String strPageId = strTopic.substring(2, strTopic.indexOf("]"));
|
||||
@ -30,17 +30,17 @@ void IRAM_ATTR dispatchAttribute(String & strTopic, String & strPayload)
|
||||
int objid = strObjId.toInt();
|
||||
|
||||
if(pageid >= 0 && pageid <= 255 && objid > 0 && objid <= 255) {
|
||||
haspProcessAttribute((uint8_t)pageid, (uint8_t)objid, strAttr, strPayload);
|
||||
haspProcessAttribute((uint8_t)pageid, (uint8_t)objid, strAttr, payload);
|
||||
} // valid page
|
||||
}
|
||||
} else if(strTopic == "page") {
|
||||
dispatchPage(strPayload);
|
||||
dispatchPage(payload);
|
||||
} else if(strTopic == "dim") {
|
||||
dispatchDim(strPayload);
|
||||
dispatchDim(payload);
|
||||
}
|
||||
}
|
||||
|
||||
void IRAM_ATTR dispatchPage(String & strPageid)
|
||||
void IRAM_ATTR dispatchPage(String strPageid)
|
||||
{
|
||||
debugPrintln("PAGE: " + strPageid);
|
||||
|
||||
@ -52,7 +52,7 @@ void IRAM_ATTR dispatchPage(String & strPageid)
|
||||
}
|
||||
}
|
||||
|
||||
void dispatchDim(String & strDimLevel)
|
||||
void dispatchDim(String strDimLevel)
|
||||
{
|
||||
debugPrintln("DIM: " + strDimLevel);
|
||||
|
||||
@ -98,21 +98,21 @@ void IRAM_ATTR dispatchCommand(String cmnd)
|
||||
if(pos > 0) {
|
||||
String strTopic = cmnd.substring(0, pos);
|
||||
String strPayload = cmnd.substring(pos + 1, cmnd.length());
|
||||
debugPrintln("CMND: '" + strTopic + "'='" + strPayload + "'");
|
||||
dispatchAttribute(strTopic, strPayload);
|
||||
// debugPrintln("CMND: '" + strTopic + "'='" + strPayload + "'");
|
||||
dispatchAttribute(strTopic, strPayload.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void dispatchJson(String & strPayload)
|
||||
void dispatchJson(char * payload)
|
||||
{ // Parse an incoming JSON array into individual commands
|
||||
if(strPayload.endsWith(",]")) {
|
||||
// Trailing null array elements are an artifact of older Home Assistant automations
|
||||
// and need to be removed before parsing by ArduinoJSON 6+
|
||||
strPayload.remove(strPayload.length() - 2, 2);
|
||||
strPayload.concat("]");
|
||||
}
|
||||
DynamicJsonDocument haspCommands(2048 + 512);
|
||||
DeserializationError jsonError = deserializeJson(haspCommands, strPayload);
|
||||
/* if(strPayload.endsWith(",]")) {
|
||||
// Trailing null array elements are an artifact of older Home Assistant automations
|
||||
// and need to be removed before parsing by ArduinoJSON 6+
|
||||
strPayload.remove(strPayload.length() - 2, 2);
|
||||
strPayload.concat("]");
|
||||
}*/
|
||||
DynamicJsonDocument haspCommands(MQTT_MAX_PACKET_SIZE + 512);
|
||||
DeserializationError jsonError = deserializeJson(haspCommands, payload);
|
||||
if(jsonError) { // Couldn't parse incoming JSON command
|
||||
errorPrintln(String(F("JSON: %sFailed to parse incoming JSON command with error: ")) +
|
||||
String(jsonError.c_str()));
|
||||
|
@ -6,12 +6,12 @@
|
||||
void dispatchSetup(void);
|
||||
void dispatchLoop(void);
|
||||
|
||||
void dispatchAttribute(String & strTopic, String & strPayload);
|
||||
void dispatchAttribute(String & strTopic, const char * strPayload);
|
||||
void dispatchCommand(String cmnd);
|
||||
void dispatchJson(String & strPayload);
|
||||
void dispatchJson(char * strPayload);
|
||||
|
||||
void dispatchPage(String & strPageid);
|
||||
void dispatchDim(String & strDimLevel);
|
||||
void dispatchPage(String strPageid);
|
||||
void dispatchDim(String strDimLevel);
|
||||
|
||||
void dispatchIdle(const __FlashStringHelper * state);
|
||||
void dispatchReboot(bool saveConfig);
|
||||
|
@ -185,9 +185,8 @@ void mqttStatusUpdate()
|
||||
// Receive incoming messages
|
||||
void mqttCallback(char * topic, byte * payload, unsigned int length)
|
||||
{ // Handle incoming commands from MQTT
|
||||
payload[length] = '\0';
|
||||
String strTopic = topic;
|
||||
String strPayload = (char *)payload;
|
||||
payload[length] = '\0';
|
||||
String strTopic = topic;
|
||||
|
||||
// strTopic: homeassistant/haswitchplate/devicename/command/p[1].b[4].txt
|
||||
// strPayload: "Lights On"
|
||||
@ -208,7 +207,7 @@ void mqttCallback(char * topic, byte * payload, unsigned int length)
|
||||
// '[...]/device/command/p[1].b[4].txt' -m '' = nextionGetAttr("p[1].b[4].txt")
|
||||
// '[...]/device/command/p[1].b[4].txt' -m '"Lights On"' = nextionSetAttr("p[1].b[4].txt", "\"Lights On\"")
|
||||
|
||||
debugPrintln(String(F("MQTT IN: '")) + strTopic + "' : '" + strPayload + "'");
|
||||
debugPrintln(String(F("MQTT IN: '")) + strTopic + "' : '" + (char *)payload + "'");
|
||||
|
||||
if(strTopic.startsWith(mqttNodeTopic)) {
|
||||
strTopic = strTopic.substring(mqttNodeTopic.length(), strTopic.length());
|
||||
@ -220,7 +219,7 @@ void mqttCallback(char * topic, byte * payload, unsigned int length)
|
||||
// debugPrintln(String(F("MQTT Short Topic : '")) + strTopic + "'");
|
||||
|
||||
if(strTopic == F("command")) {
|
||||
dispatchCommand(strPayload);
|
||||
dispatchCommand((char *)payload);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -229,18 +228,18 @@ void mqttCallback(char * topic, byte * payload, unsigned int length)
|
||||
// debugPrintln(String(F("MQTT Shorter Command Topic : '")) + strTopic + "'");
|
||||
|
||||
if(strTopic == F("page")) { // '[...]/device/command/page' -m '1' == nextionSendCmd("page 1")
|
||||
dispatchPage(strPayload);
|
||||
dispatchPage((char *)payload);
|
||||
} else if(strTopic == F("dim")) { // '[...]/device/command/page' -m '1' == nextionSendCmd("page 1")
|
||||
dispatchDim(strPayload);
|
||||
dispatchDim((char *)payload);
|
||||
} else if(strTopic == F("json")) { // '[...]/device/command/json' -m '["dim=5", "page 1"]' =
|
||||
// nextionSendCmd("dim=50"), nextionSendCmd("page 1")
|
||||
dispatchJson(strPayload); // Send to nextionParseJson()
|
||||
dispatchJson((char *)payload); // Send to nextionParseJson()
|
||||
} else if(strTopic == F("statusupdate")) { // '[...]/device/command/statusupdate' == mqttStatusUpdate()
|
||||
// mqttStatusUpdate(); // return status JSON via MQTT
|
||||
} else if(strTopic == F("espupdate")) { // '[...]/device/command/espupdate' -m
|
||||
// 'http://192.168.0.10/local/HASwitchPlate.ino.d1_mini.bin' ==
|
||||
// espStartOta("http://192.168.0.10/local/HASwitchPlate.ino.d1_mini.bin")
|
||||
if(strPayload == "") {
|
||||
if(length == 0) {
|
||||
// espStartOta(espFirmwareUrl);
|
||||
} else {
|
||||
// espStartOta(strPayload);
|
||||
@ -254,11 +253,13 @@ void mqttCallback(char * topic, byte * payload, unsigned int length)
|
||||
// haspProcessAttribute(strTopic, "");
|
||||
} else { // '[...]/device/command/p[1].b[4].txt' -m '"Lights On"' ==
|
||||
// nextionSetAttr("p[1].b[4].txt", "\"Lights On\"")
|
||||
dispatchAttribute(strTopic, strPayload);
|
||||
dispatchAttribute(strTopic, (char *)payload);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
String strPayload = (char *)payload;
|
||||
|
||||
if(strTopic == mqttLightBrightCommandTopic) { // change the brightness from the light topic
|
||||
int panelDim = map(strPayload.toInt(), 0, 255, 0, 100);
|
||||
// nextionSetAttr("dim", String(panelDim));
|
||||
|
Loading…
x
Reference in New Issue
Block a user