fix: handle string, uint, and uint64 types in toFloat64#352
Merged
Conversation
Bridges may send SNR/RSSI values as strings instead of numbers, causing toFloat64 to silently return (0, false) and drop the data. Add string case using strconv.ParseFloat with TrimSpace, plus uint and uint64 cases for completeness. Update tests accordingly. Fixes #350
a30a890 to
8d52b39
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #350 —
toFloat64()silently drops SNR/RSSI values when bridges send strings instead of numbers.Problem
Some MQTT bridges serialize numeric fields (SNR, RSSI, battery_mv, etc.) as JSON strings like
"-7.5"instead of numbers. The existingtoFloat64()switch only handledfloat64,float32,int,int64, andjson.Number, so string values fell through to the default case returning(0, false)— silently dropping the data.Changes
cmd/ingestor/main.go: Addedstring,uint, anduint64cases totoFloat64()string: usesstrconv.ParseFloat(strings.TrimSpace(n), 64)to handle whitespace-padded numeric stringsuint/uint64: straightforward numeric conversionstrconvimportcmd/ingestor/main_test.go: UpdatedTestToFloat64with new cases:"3.14"), string with spaces (" -7.5 "), string integer ("42")"hello"), empty stringuint(10),uint64(999)Testing
All ingestor tests pass (
go test ./...).