1. mqtt发布增加异常处理。

main
baocm 8 months ago
parent c142bad42d
commit 9524701aee

@ -355,7 +355,12 @@ void PublisherApp::run(std::shared_ptr<mqtt::async_client> 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);

Loading…
Cancel
Save