Compare commits

..

2 Commits

Author SHA1 Message Date
eaf2cf211d Update wunderground url
All checks were successful
Build and Publish / release (push) Successful in 2m36s
2025-01-12 19:06:45 -05:00
e8fbacfe6d Proxy updates for AWN
All checks were successful
Build and Publish / release (push) Successful in 2m53s
2025-01-12 17:49:54 -05:00
6 changed files with 43 additions and 8 deletions

View File

@ -4,6 +4,8 @@
- [ ] Add Grafana dashboard
- [ ] Add proxy to upstream support
- [ ] Add new spans
- [ ] Fix wunderground 401
- [ ] Perform proxy calls in goroutines
## Done
- [x] Configuration for app

View File

@ -124,13 +124,21 @@ func (aw *AmbientWeather) handleProviderRequest(
err := aw.awnProvider.ProxyReq(ctx, update)
if err != nil {
zerolog.Ctx(aw.appCtx).Err(err).Msg("failed to proxy to ambient weather")
return
}
zerolog.Ctx(aw.appCtx).Debug().
Str("station", station.Name).
Msg("proxied weather update to awn")
}
if station.ProxyToWunderground {
err := aw.wuProvider.ProxyReq(ctx, update)
if err != nil {
zerolog.Ctx(aw.appCtx).Err(err).Msg("failed to proxy to ambient weather")
return
}
zerolog.Ctx(aw.appCtx).Debug().
Str("station", station.Name).
Msg("proxied weather update to wunderground")
}
}
}

View File

@ -18,6 +18,14 @@ const (
awnURL = "http://ambientweather.net/data/report"
)
// Battery Sensors
const (
BattOutdoorSensor = "OutdoorSensor"
BattIndoorSensor = "IndoorSensor"
BattRainSensor = "RainSensor"
BattCO2Sensor = "CO2Sensor"
)
func (awn *AWNProvider) Name() string {
return providerName
}
@ -66,19 +74,19 @@ func MapAwnUpdate(awnUpdate *AmbientWeatherUpdate) *weather.WeatherUpdate {
TotalRainIn: awnUpdate.TotalRainIn,
Batteries: []weather.BatteryStatus{
{
Component: "OutdoorSensor",
Component: BattOutdoorSensor,
Status: awnUpdate.BattOut,
},
{
Component: "IndoorSensor",
Component: BattIndoorSensor,
Status: awnUpdate.BattIn,
},
{
Component: "RainSensor",
Component: BattRainSensor,
Status: awnUpdate.BattRain,
},
{
Component: "CO2Sensor",
Component: BattCO2Sensor,
Status: awnUpdate.BattCO2,
},
},

View File

@ -79,5 +79,20 @@ func updateToAWNParams(update *weather.WeatherUpdate) *url.Values {
weather.SetURLVal(params, "windgustmph", update.WindGustMPH)
weather.SetURLVal(params, "windspeedmph", update.WindSpeedMPH)
weather.SetURLVal(params, "maxdailygust", update.MaxDailyGust)
// Batteries
for _, status := range update.Batteries {
switch status.Component {
case BattOutdoorSensor:
weather.SetURLVal(params, "battin", status.Status)
case BattIndoorSensor:
weather.SetURLVal(params, "battout", status.Status)
case BattRainSensor:
weather.SetURLVal(params, "battrain", status.Status)
case BattCO2Sensor:
weather.SetURLVal(params, "batt_co2", status.Status)
}
}
return params
}

View File

@ -15,7 +15,7 @@ type WUProvider struct{}
const (
providerName = "weatherunderground"
wuURL = "http://rtupdate.wunderground.com/weatherstation/updateweatherstation.php"
wuURL = "https://rtupdate.wunderground.com/weatherstation/updateweatherstation.php"
)
func (wu *WUProvider) Name() string {

View File

@ -4,7 +4,6 @@ import (
"context"
"errors"
"net/url"
"time"
"github.com/go-resty/resty/v2"
"go.opentelemetry.io/otel/attribute"
@ -39,6 +38,9 @@ func (wu *WUProvider) ProxyReq(ctx context.Context, update *weather.WeatherUpdat
Get(wuURL)
if err != nil {
span.SetStatus(codes.Error, err.Error())
span.SetAttributes(
attribute.String("query", resp.Request.QueryParam.Encode()),
)
span.RecordError(err)
}
@ -52,11 +54,11 @@ func (wu *WUProvider) ProxyReq(ctx context.Context, update *weather.WeatherUpdat
func updateToWuParams(u *weather.WeatherUpdate) *url.Values {
params := &url.Values{}
params.Set("dateutc", time.Now().Format(time.DateTime))
weather.SetURLVal(params, "ID", &u.StationConfig.WundergroundID)
weather.SetURLVal(params, "PASSWORD", &u.StationConfig.WundergroundPassword)
params.Set("action", "updateraw")
params.Set("dateutc", "now")
weather.SetURLVal(params, "UV", u.UV)
weather.SetURLVal(params, "action", ptr.To("updateraw"))
weather.SetURLVal(params, "baromin", u.BaromRelativeIn)
weather.SetURLVal(params, "dailyrainin", u.DailyRainIn)
weather.SetURLVal(params, "dewptf", u.DewPointF)