mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-24 11:46:34 +00:00
Do not quote numbers in response json
This commit is contained in:
parent
666cbbf804
commit
1b64ec7747
@ -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)
|
||||
|
@ -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 ===== */
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user