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