davisweather

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 16, 2023 License: BSD-2-Clause Imports: 18 Imported by: 0

README

davisweather

Build Status Go Report Card GoDoc GitHub license

Real time consumption of weather data from Davis WeatherLink Live.

Table of Contents

About

davisweather is used to consume from a WeatherLink Live (WLL) unit located on a network. It takes advantage of Davis' live transmission protocol, allowing for updates every 2.5 seconds.

Usage

A managed and unmanaged client is available. The managed client automatically discovers the WLL unit on a local network using mDNS. The unmanaged client is used on networks that block mDNS.

An example client may be found in the example directory.

Managed Client

Here is an example of using the managed client with verbose logging disabled.

func main() {
    ctx := context.Background()
    client := davisweather.Managed(ctx, false)

    for {
        <-client.Notify
        report, err := client.Report()
        if err != nil {
            panic(err)
        }
        log.Println(*report.Temperature)
    }
}
Unmanaged Client

Here is an example of using the unmanaged client with verbose logging enabled.

func main() {
    ctx := context.Background()
    client := davisweather.Unmanaged(ctx, false, "10.0.0.2", 80)

    for {
        <-client.Notify
        report, err := client.Report()
        if err != nil {
            panic(err)
        }
        log.Println(*report.Temperature)
    }
}
Client Shutdown

To shutdown the client, send a Done signal on the context provided to the client.

License

Copyright (c) 2020 Tanner Ryan. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

The ZeroConf package is distributed under an MIT license. Copyright (c) 2016 Stefan Smarzly, Copyright (c) 2014 Oleksandr Lobunets. All rights reserved.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Notify <-chan bool // Notify emits a bool when a new weather report is generated
	// contains filtered or unexported fields
}

Client is the Davis weather client.

func Managed

func Managed(ctx context.Context, verbose bool) *Client

Managed returns a managed Davis weather client. It accepts a context for cancelling the Client. It automatically discovers the WeatherLink Live (WLL) unit on the local network. If multicast DNS is disabled on the network, use the unmanaged client. It returns a new client for consuming weather data. Verbose enables Client logging.

func Unmanaged

func Unmanaged(ctx context.Context, verbose bool, hostname string, port int) (*Client, error)

Unmanaged returns an unmanaged Davis weather client. It accepts a context for cancelling the Client and a hostname (IP or domain) and port of the WeatherLink Live (WLL) unit. It returns a new client for consuming weather data. It returns an error if no hostname is provided. Verbose enables Client logging.

func (*Client) Closed

func (c *Client) Closed()

Closed blocks until the client has been gracefully terminated.

func (*Client) Report

func (c *Client) Report() (*Report, error)

Report returns the latest weather report or an error.

type Report

type Report struct {
	DeviceID  string    `json:"deviceID"`  // DeviceID is unique device ID
	Timestamp time.Time `json:"timestamp"` // Timestamp is the time the Report was last modified

	Temperature *float64 `json:"temperature"` // Temperature (°F)
	Humidity    *float64 `json:"humidity"`    // Humidity (%RH)
	Dewpoint    *float64 `json:"dewpoint"`    // Dewpoint (°F)
	Wetbulb     *float64 `json:"wetbulb"`     // Wetbulb (°F)
	HeatIndex   *float64 `json:"heatindex"`   // HeatIndex (°F)
	WindChill   *float64 `json:"windchill"`   // WindChill (°F)
	THWIndex    *float64 `json:"thwIndex"`    // THWIndex is "feels like" (°F)
	THSWIndex   *float64 `json:"thswIndex"`   // THWSIndex is "feels like" including solar (°F)

	WindSpeedLast          *float64 `json:"windSpeedLast"`          // WindSpeedLast is most recent wind speed (mph)
	WindDirLast            *float64 `json:"windDirLast"`            // WindDirLast is most recent wind direction (°)
	WindSpeedAvgLast1Min   *float64 `json:"windSpeedAvg1Min"`       // WindSpeedAvgLast1Min is average wind over last minute (mph)
	WindDirAvgLast1Min     *float64 `json:"windDirAvg1Min"`         // WindDirAvgLast1Min is average wind direction over last minute (°)
	WindSpeedAvgLast2Min   *float64 `json:"windSpeedAvg2Min"`       // WindSpeedAvgLast2Min is average wind over last 2 minutes (mph)
	WindDirAvgLast2Min     *float64 `json:"windDirAvg2Min"`         // WindDirAvgLast2Min is average wind direction over last 2 minutes (°)
	WindSpeedHighLast2Min  *float64 `json:"windGustSpeedLast2Min"`  // WindSpeedHighLast2Min is max gust over last 2 minutes (mph)
	WindDirAtHighLast2Min  *float64 `json:"windGustDirLast2Min"`    // WindDirAtHighLast2Min is max gust direction over last 2 minutes (°)
	WindSpeedAvgLast10Min  *float64 `json:"windSpeedAvg10Min"`      // WindSpeedAvgLast10Min is average wind over last 10 minutes (mph)
	WindDirAvgLast10Min    *float64 `json:"windDirAvg10Min"`        // WindDirAvgLast10Min is average wind dir over last 10 minutes (°)
	WindSpeedHighLast10Min *float64 `json:"windGustSpeedLast10Min"` // WindSpeedHighLast10Min is max gust over last 10 minutes (mph)
	WindDirAtHighLast10Min *float64 `json:"windGustDirLast10Min"`   // WindDirAtHighLast10Min is max gust direction over last 10 minutes (°)

	RainSize              *float64   `json:"rainSize"`              // RainSize is size of rain collector (1: 0.01", 2: 0.2mm)
	RainRateLast          *float64   `json:"rainRateLast"`          // RainRateLast is most recent rain rate (count/hour)
	RainRateHigh          *float64   `json:"rainRateHigh"`          // RainRateHigh is highest rain rate over last minute (count/hour)
	RainLast15Min         *float64   `json:"rainLast15Min"`         // RainLast15Min is rain count in last 15 minutes (count)
	RainRateHighLast15Min *float64   `json:"rainRateHighLast15Min"` // RainRateHighLast15Min is highest rain count rate over last 15 minutes (count/hour)
	RainLast60Min         *float64   `json:"rainLast60Min"`         // RainLast60Min is rain count over last 60 minutes (count)
	RainLast24Hour        *float64   `json:"rainLast24Hour"`        // RainLast24Hour is rain count over last 24 hours (count)
	RainStorm             *float64   `json:"rainStorm"`             // RainStorm is rain since last 24 hour break in rain (count)
	RainStormStartAt      *time.Time `json:"rainStormStart"`        // RainStormStartAt is time of rain storm start

	SolarRad *float64 `json:"solarRad"` // SolarRad is solar radiation (W/m²)
	UVIndex  *float64 `json:"uvIndex"`  // UVIndex is solar UV index

	RXState          string `json:"signal"`  // RXState is ISS receiver status
	TransBatteryFlag string `json:"battery"` // TransBatteryFlag is ISS battery status

	RainfallDaily        *float64   `json:"rainDaily"`          // RainfallDaily is total rain since midnight (count)
	RainfallMonthly      *float64   `json:"rainMonthly"`        // RainfallMonthly is total rain since first of month (count)
	RainfallYear         *float64   `json:"rainYear"`           // RainfallYear is total rain since first of year (count)
	RainStormLast        *float64   `json:"rainStormLast"`      // RainStormLast is rain since last 24 hour break in rain (count)
	RainStormLastStartAt *time.Time `json:"rainStormLastStart"` // RainStormLastStartAt is time of last rain storm start
	RainStormLastEndAt   *time.Time `json:"rainStormLastEnd"`   // rainStormLastEndAt is time of last rain storm end

	BarometerSeaLevel *float64 `json:"barometerSeaLevel"` // BarometerSeaLevel is barometer reading with elevation adjustment (inches)
	BarometerTrend    *float64 `json:"barometerTrend"`    // BarometerTrend is 3 hour barometric trend (inches)
	BarometerAbsolute *float64 `json:"barometerAbsolute"` // BarometerAbsolute is barometer reading at current elevation (inches)

	TemperatureIndoor *float64 `json:"indoorTemperature"` // TemperatureIndoor is indoor temp (°F)
	HumidityIndoor    *float64 `json:"indoorHumidity"`    // HumidityIndoor is indoor humidity (%)
	DewPointIndoor    *float64 `json:"indoorDewpoint"`    // DewPointIndoor is indoor dewpoint (°F)
	HeatIndexIndoor   *float64 `json:"indoorHeatIndex"`   // HeatIndexIndoor is indoor heat index (°F)
	// contains filtered or unexported fields
}

Report is the latest weather report.

func NewReport

func NewReport(verbose bool) (*Report, chan bool)

NewReport returns a new Report state and a notification channel. The channel emits a bool when the Report contents have been modified. Verbose enables Report logging.

func (*Report) Copy

func (r *Report) Copy() (*Report, error)

Copy generates and returns a new deep copy of the Report state. It returns an error if the copy operation fails.

func (*Report) Decode

func (r *Report) Decode(payload []byte) error

Decode updates the Report using a zlib encoded weather report. It returns an error if the provided payload is not valid.

func (*Report) Encode

func (r *Report) Encode() []byte

Encode returns a zlib encoded weather report.

func (*Report) JSON

func (r *Report) JSON() []byte

JSON returns the JSON representation of the Report state and the Report was last updated.

func (*Report) UpdateHTTP

func (r *Report) UpdateHTTP(new *parser.ConditionsHTTP) error

UpdateHTTP atomically updates the Report state using weather conditions retrieved over HTTP. It returns an error if the atomic update action fails.

func (*Report) UpdateJSON

func (r *Report) UpdateJSON(payload []byte) error

UpdateJSON atomically updates the Report state using a provided JSON payload. It returns an error if the JSON does not match the Report structure or if the atomic update action fails.

func (*Report) UpdateUDP

func (r *Report) UpdateUDP(new *parser.ConditionsUDP) error

UpdateUDP atomically updates the Report state using weather conditions received over UDP. It returns an error if the atomic update action fails.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL