chirpstack-network-server
chirpstack-network-server copied to clipboard
Wrong test in func UpdateGatewayState to see if gateway coordinates should be updated
- [X] The issue is present in master and 3.16.2, I do not know if master is the latest release
- [X] I have searched the issues of this repository and believe that this is not a duplicate.
What happened?
When a gateway has an altitude of 0m, its other coordinates are not updated, even if they are not zeroes. It looks logical from the code: in chirpstack-network-server/internal/storage/gateway.go around line 366
// UpdateGatewayState updates the location of the gateway and last seen ts.
func UpdateGatewayState(ctx context.Context, db sqlx.Execer, id lorawan.EUI64, lat, lon, alt float64) error {
var loc *GPSPoint
var altt *float64
if lat != 0 && lon != 0 && alt != 0 {
loc = &GPSPoint{
Latitude: lat,
Longitude: lon,
}
altt = &alt
}
now := time.Now()
// * only update first_seen_at when the current value is NULL
// * only update the location when the given value is not NULL
// * only update the altitude when the given value is not NULL
What did you expect?
I expect that an altitude of 0m does not prevent a gateway gps coordinates to be updated. So I expect to have OR and not AND in the test:
if lat != 0 || lon != 0 || alt != 0 {
since I would expect that only the default coordinates (0,0,0) will cause coordinates not to be updated [poor ships cruising the Gulf of Guinea by the way ...] And as altitude is coded as an integer (if I read correctly the packet_forwarder protocol) it might even be the case for a gateway 40cm above sea level (a buoy for instance).
Steps to reproduce this issue
Steps:
- Make a gateway publish stats like that: {"stat":{"time":"2022-06-13 12:46:27 GMT","lati":48.5777965,"long":7.7497201,"alti":0,"rxnb":0,"rxok":0,"rxfw":0,"ackr":0,"dwnb":3,"txnb":0}}
- gateway latitude and longitude won't be updated.
Your Environment
| Component | Version |
|---|---|
| Application Server | v3.15.0 |
| Network Server | v3.13.0 |
| Gateway Bridge | v3.11.0 |
| Chirpstack API | |
| Geolocation | Not installed |
| Concentratord | Not installed |