From 9524701aee12ed1c17c49bf2de3a9cb4ebfbf416 Mon Sep 17 00:00:00 2001 From: baocm Date: Thu, 29 Jan 2026 11:37:29 +0800 Subject: [PATCH] =?UTF-8?q?1.=20mqtt=E5=8F=91=E5=B8=83=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E5=A4=84=E7=90=86=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mqttdds/Publisher.cxx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mqttdds/Publisher.cxx b/mqttdds/Publisher.cxx index 0e3b872..3102452 100644 --- a/mqttdds/Publisher.cxx +++ b/mqttdds/Publisher.cxx @@ -355,7 +355,12 @@ void PublisherApp::run(std::shared_ptr dev) { if (dev->is_connected()) { - std::string payload = "{\"value\": " + std::to_string(info.Value()) + "}"; + float weight_value = info.Value(); + if (std::isinf(weight_value) || std::isnan(weight_value)) + { + weight_value = 0.0; + } + std::string payload = "{\"value\": " + std::to_string(weight_value) + "}"; auto mqtt_msg = mqtt::make_message("pound/" + std::string(mqtt_topic_id) + "/scale/weight", payload); mqtt_msg->set_qos(0); mqtt_msg->set_retained(true);