From 1798007f9d10470d045380b220df1813b479c12f Mon Sep 17 00:00:00 2001 From: John Date: Sat, 26 Feb 2022 08:56:22 +0100 Subject: [PATCH] add mqttjson=short option --- src/ebusd/mqtthandler.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/ebusd/mqtthandler.cpp b/src/ebusd/mqtthandler.cpp index 48211b77..f24c130d 100755 --- a/src/ebusd/mqtthandler.cpp +++ b/src/ebusd/mqtthandler.cpp @@ -72,7 +72,8 @@ static const struct argp_option g_mqtt_argp_options[] = { {"mqttqos", O_PQOS, "QOS", 0, "Set the QoS value for all topics (0-2) [0]", 0 }, {"mqttint", O_INTF, "FILE", 0, "Read MQTT integration settings from FILE (no default)", 0 }, {"mqttvar", O_IVAR, "NAME=VALUE[,...]", 0, "Add variable(s) to the read MQTT integration settings", 0 }, - {"mqttjson", O_JSON, nullptr, 0, "Publish in JSON format instead of strings", 0 }, + {"mqttjson", O_JSON, "short", OPTION_ARG_OPTIONAL, + "Publish in JSON format instead of strings, optionally in short (value directly below field key)", 0 }, {"mqttverbose", O_VERB, nullptr, 0, "Publish all available attributes", 0 }, #if (LIBMOSQUITTO_VERSION_NUMBER >= 1003001) {"mqttlog", O_LOGL, nullptr, 0, "Log library events", 0 }, @@ -244,12 +245,15 @@ static error_t mqtt_parse_opt(int key, char *arg, struct argp_state *state) { g_integrationVars = arg; break; - case O_JSON: // --mqttjson + case O_JSON: // --mqttjson[=short] g_publishFormat |= OF_JSON|OF_NAMES; + if (arg && strcmp("short", arg) == 0) { + g_publishFormat = (g_publishFormat & ~(OF_NAMES|OF_UNITS|OF_COMMENTS|OF_ALL_ATTRS)) | OF_SHORT; + } break; case O_VERB: // --mqttverbose - g_publishFormat |= OF_NAMES|OF_UNITS|OF_COMMENTS|OF_ALL_ATTRS; + g_publishFormat = (g_publishFormat & ~OF_SHORT) | OF_NAMES|OF_UNITS|OF_COMMENTS|OF_ALL_ATTRS; break; #if (LIBMOSQUITTO_VERSION_NUMBER >= 1003001)