mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-24 11:46:34 +00:00
Add custom fan animation example
This commit is contained in:
parent
4dac1ae447
commit
3772db01fa
@ -340,6 +340,14 @@ void dispatch_topic_payload(const char* topic, const char* payload, bool update,
|
||||
}
|
||||
#endif
|
||||
|
||||
#if HASP_USE_CUSTOM > 0
|
||||
if(topic == strstr_P(topic, PSTR(MQTT_TOPIC_CUSTOM "/"))) { // startsWith custom
|
||||
topic += 7u;
|
||||
custom_topic_payload(topic, (char*)payload, source);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
dispatch_command(topic, (char*)payload, update, source); // dispatch as is
|
||||
}
|
||||
|
||||
@ -615,7 +623,7 @@ void dispatch_parse_jsonl(std::istream& stream)
|
||||
{
|
||||
uint8_t savedPage = haspPages.get();
|
||||
uint16_t line = 1;
|
||||
DynamicJsonDocument jsonl(MQTT_MAX_PACKET_SIZE / 2 + 128);
|
||||
DynamicJsonDocument jsonl(MQTT_MAX_PACKET_SIZE / 2 + 128);
|
||||
DeserializationError jsonError = deserializeJson(jsonl, stream);
|
||||
|
||||
#ifdef ARDUINO
|
||||
|
@ -72,6 +72,10 @@ bool mqttSetConfig(const JsonObject& settings);
|
||||
#define MQTT_TOPIC_SENSORS "sensors"
|
||||
#endif
|
||||
|
||||
#ifndef MQTT_TOPIC_CUSTOM
|
||||
#define MQTT_TOPIC_CUSTOM "custom"
|
||||
#endif
|
||||
|
||||
#define MQTT_TOPIC_LWT "LWT"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -264,6 +264,14 @@ static void onConnect(void* context)
|
||||
topic = mqttNodeTopic + "config/#";
|
||||
mqtt_subscribe(mqtt_client, topic.c_str());
|
||||
|
||||
#if HASP_USE_CUSTOM > 0
|
||||
topic = mqttGroupTopic + MQTT_TOPIC_CUSTOM "/#";
|
||||
mqtt_subscribe(mqtt_client, topic.c_str());
|
||||
|
||||
topic = mqttNodeTopic + MQTT_TOPIC_CUSTOM "/#";
|
||||
mqtt_subscribe(mqtt_client, topic.c_str());
|
||||
#endif
|
||||
|
||||
#ifdef HASP_USE_BROADCAST
|
||||
topic = MQTT_PREFIX "/" MQTT_TOPIC_BROADCAST "/" MQTT_TOPIC_COMMAND "/#";
|
||||
mqtt_subscribe(mqtt_client, topic.c_str());
|
||||
|
@ -119,7 +119,7 @@ int mqtt_send_object_state(uint8_t pageid, uint8_t btnid, const char* payload)
|
||||
|
||||
int mqtt_send_state(const char* subtopic, const char* payload)
|
||||
{
|
||||
char tmp_topic[strlen(mqttNodeTopic) + 20];
|
||||
char tmp_topic[strlen(mqttNodeTopic) + strlen(subtopic) + 16];
|
||||
snprintf_P(tmp_topic, sizeof(tmp_topic), PSTR("%s" MQTT_TOPIC_STATE "/%s"), mqttNodeTopic, subtopic);
|
||||
return mqttPublish(tmp_topic, payload, false);
|
||||
}
|
||||
@ -300,6 +300,13 @@ void mqttStart()
|
||||
snprintf_P(topic, sizeof(topic), PSTR("%s" MQTT_TOPIC_CONFIG "/#"), mqttNodeTopic);
|
||||
mqttSubscribeTo(topic);
|
||||
|
||||
#if HASP_USE_CUSTOM > 0
|
||||
snprintf_P(topic, sizeof(topic), PSTR("%s" MQTT_TOPIC_CUSTOM "/#"), mqttGroupTopic);
|
||||
mqttSubscribeTo(topic);
|
||||
snprintf_P(topic, sizeof(topic), PSTR("%s" MQTT_TOPIC_CUSTOM "/#"), mqttNodeTopic);
|
||||
mqttSubscribeTo(topic);
|
||||
#endif
|
||||
|
||||
#ifdef HASP_USE_BROADCAST
|
||||
snprintf_P(topic, sizeof(topic), PSTR(MQTT_PREFIX "/" MQTT_TOPIC_BROADCAST "/" MQTT_TOPIC_COMMAND "/#"));
|
||||
mqttSubscribeTo(topic);
|
||||
|
Loading…
x
Reference in New Issue
Block a user