diff --git a/internal/app/webhook/chirp_stack.go b/internal/app/webhook/chirp_stack.go index 2463ffc..2f46263 100644 --- a/internal/app/webhook/chirp_stack.go +++ b/internal/app/webhook/chirp_stack.go @@ -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 {