采集失败处理

This commit is contained in:
2025-10-08 17:52:30 +08:00
parent b611f132f1
commit 8a2e889048

View File

@@ -4,6 +4,7 @@ import (
"encoding/base64"
"encoding/json"
"io"
"math"
"net/http"
"time"
@@ -256,6 +257,12 @@ func (c *ChirpStackListener) handleUpEvent(event *UpEvent) {
for i, deviceID := range deviceIDs {
rawSensorValue := values[i] // 这是设备上报的原始值
// 检查设备上报的值是否为 NaN (Not a Number),如果是则跳过
if math.IsNaN(float64(rawSensorValue)) {
c.logger.Warnf("设备 (ID: %d) 上报了一个无效的 NaN 值,已跳过当前值的记录。", deviceID)
continue
}
// 5.1 获取设备及其模板
dev, err := c.deviceRepo.FindByID(deviceID)
if err != nil {