diff --git a/src/hasp/hasp_dispatch.cpp b/src/hasp/hasp_dispatch.cpp index eedb531c..a58a46f2 100644 --- a/src/hasp/hasp_dispatch.cpp +++ b/src/hasp/hasp_dispatch.cpp @@ -265,19 +265,28 @@ void dispatch_output_group_state(uint8_t groupid, uint16_t state) dispatch_state_msg(F("output"), payload); } -void IRAM_ATTR dispatch_send_obj_attribute_str(uint8_t pageid, uint8_t btnid, const char * attribute, const char * data) +void dispatch_send_obj_attribute_str(uint8_t pageid, uint8_t btnid, const char * attribute, const char * data) { if(!attribute || !data) return; char topic[12]; char payload[32 + strlen(data) + strlen(attribute)]; - // snprintf_P(payload, sizeof(payload), PSTR("{\"page\":%u,\"id\":%u,\"%s\":\"%s\"}"), pageid, btnid, attribute, - // data); dispatch_state_msg(F("json"), payload); snprintf_P(topic, sizeof(payload), PSTR("p%ub%u"), pageid, btnid); snprintf_P(payload, sizeof(payload), PSTR("{\"%s\":\"%s\"}"), attribute, data); mqtt_send_state_str(topic, payload); } +void dispatch_send_obj_attribute_int(uint8_t pageid, uint8_t btnid, const char * attribute, int32_t val) +{ + if(!attribute) return; + + char topic[12]; + char payload[64 + strlen(attribute)]; + snprintf_P(topic, sizeof(payload), PSTR("p%ub%u"), pageid, btnid); + snprintf_P(payload, sizeof(payload), PSTR("{\"%s\":%d}"), attribute, val); + mqtt_send_state_str(topic, payload); +} + #if HASP_USE_CONFIG > 0 // Get or Set a part of the config.json file static void dispatch_config(const char * topic, const char * payload) diff --git a/src/hasp/hasp_dispatch.h b/src/hasp/hasp_dispatch.h index 9f6ff358..d5a40cba 100644 --- a/src/hasp/hasp_dispatch.h +++ b/src/hasp/hasp_dispatch.h @@ -54,8 +54,8 @@ void dispatch_object_value_changed(lv_obj_t * obj, int16_t state); void dispatch_normalized_group_value(uint8_t groupid, uint16_t value, lv_obj_t * obj); -void IRAM_ATTR dispatch_send_obj_attribute_str(uint8_t pageid, uint8_t btnid, const char * attribute, - const char * data); +void dispatch_send_obj_attribute_str(uint8_t pageid, uint8_t btnid, const char * attribute, const char * data); +void dispatch_send_obj_attribute_int(uint8_t pageid, uint8_t btnid, const char * attribute, int32_t val); /* ===== Getter and Setter Functions ===== */ diff --git a/src/hasp/hasp_object.cpp b/src/hasp/hasp_object.cpp index 97026007..ca9ebb4f 100644 --- a/src/hasp/hasp_object.cpp +++ b/src/hasp/hasp_object.cpp @@ -220,9 +220,12 @@ void hasp_send_obj_attribute_str(lv_obj_t * obj, const char * attribute, const c void hasp_send_obj_attribute_int(lv_obj_t * obj, const char * attribute, int32_t val) { - char data[64]; - itoa(val, data, 10); - hasp_send_obj_attribute_str(obj, attribute, data); + uint8_t pageid; + uint8_t objid; + + if(hasp_find_id_from_obj(obj, &pageid, &objid)) { + dispatch_send_obj_attribute_int(pageid, objid, attribute, val); + } } void hasp_send_obj_attribute_color(lv_obj_t * obj, const char * attribute, lv_color_t color) diff --git a/src/svc/hasp_mqtt.cpp b/src/svc/hasp_mqtt.cpp index 19c668c0..537e61ad 100644 --- a/src/svc/hasp_mqtt.cpp +++ b/src/svc/hasp_mqtt.cpp @@ -91,7 +91,10 @@ PubSubClient mqttClient(mqttNetworkClient); static bool mqttPublish(const char * topic, const char * payload, size_t len, bool retain = false) { if(mqttIsConnected()) { - if(mqttClient.publish(topic, (uint8_t *)payload, len, retain)) { + if(mqttClient.beginPublish(topic, len, retain)) { + mqttClient.write((uint8_t *)payload, len); + mqttClient.endPublish(); + Log.notice(TAG_MQTT_PUB, F("%s => %s"), topic, payload); return true; } else {