weatherlink

package module
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2020 License: MIT Imports: 16 Imported by: 0

README

GoDoc Go Report Card

This package provides a Go library for the Davis WeatherLink v2 API.

Installation

go get github.com/alexhowarth/go-weatherlink

Usage

// configure
config := weatherlink.Config{
        Key:    "mykey",
        Secret: "mysecret",
}

// build a client
wl := config.NewClient()

// all weather stations associated with your key
st, err := wl.AllStations()
if err != nil {
        // handle error
}

// current conditions for a station
cu, err := wl.Current(123)
if err != nil {
        // handle error
}

// historic for a station
start := time.Now().Add(-time.Hour * 2)
end := time.Now()

h, err := wl.Historic(123, start, end)
if err != nil {
        // handle error
}

for _, v := range h.Sensors {
        for _, d := range v.Data {
                fmt.Printf("Time: %v Temp: %v\n", time.Unix(d.Ts, 0), d.TempOut)
	}
}

Command line tool

This package contains the command line tool weatherlink-cli. To install and use it:

$ go install weatherlink-cli
$ weatherlink-cli --help

To extract certain data from the output, you might use jq:

$ weatherlink-cli historic --key mykey --secret mysecret --station 2970 --start="2020-07-08T00:00:00Z" --end="2020-07-08T01:00:00Z"| jq -r '.sensors[].data[] | "timestamp: \(.ts) temp_out: \(.temp_out) bar: \(.bar)"'

timestamp: 1594167300 temp_out: 76.8 bar: 30.018
timestamp: 1594167600 temp_out: 76.8 bar: 30.014

TODO

The following are not currently implemented:

  • Nodes
  • SensorActivity

This is work in progress. Let me know if something breaks or if your sensor type is not supported.

API

Documentation for the API can be found at https://weatherlink.github.io/v2-api/

Documentation

Overview

Package weatherlink provides a client to the Davis Weatherlink weather station API

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Client *http.Client
	Config *Config
}

Client contains the http client and config. It is used to make requests to the API endpoints

func (*Client) AllSensors

func (w *Client) AllSensors() (sr SensorsResponse, err error)

AllSensors gets all sensors attached to all weather stations associated with your API Key

func (*Client) AllSensorsGeneric added in v1.0.4

func (w *Client) AllSensorsGeneric() (sr interface{}, err error)

AllSensors gets all sensors attached to all weather stations associated with your API Key The result is an interface{} for generic use

func (*Client) AllStations

func (w *Client) AllStations() (sr StationsResponse, err error)

AllStations gets all weather stations associated with your API Key

func (*Client) AllStationsGeneric added in v1.0.4

func (w *Client) AllStationsGeneric() (sr interface{}, err error)

AllStationsGeneric gets all weather stations associated with your API Key The result is an interface{} for generic use

func (*Client) Current

func (w *Client) Current(station int) (cr CurrentResponse, err error)

Current gets current conditions data for one station

func (*Client) CurrentGeneric added in v1.0.4

func (w *Client) CurrentGeneric(station int) (cr interface{}, err error)

CurrentGeneric gets current conditions data for one station The result is an interface{} for generic use

func (*Client) Historic

func (w *Client) Historic(station int, start time.Time, end time.Time) (hr HistoricResponse, err error)

Historic gets historic data for one station ID within a given timerange

func (*Client) HistoricGeneric added in v1.0.4

func (w *Client) HistoricGeneric(station int, start time.Time, end time.Time) (hr interface{}, err error)

HistoricGeneric gets historic data for one station ID within a given timerange The result is an interface{} for generic use

func (*Client) MakeSignatureParams

func (w *Client) MakeSignatureParams() SignatureParams

MakeSignatureParams creates SignatureParams with the common signature parameters

func (*Client) SensorCatalog

func (w *Client) SensorCatalog(path string) (err error)

SensorCatalog saves a catalogue of all types of sensors to file

func (*Client) Sensors

func (w *Client) Sensors(sensors []int) (sr SensorsResponse, err error)

Sensors gets sensors for one or more sensor IDs provided

func (*Client) SensorsGeneric added in v1.0.4

func (w *Client) SensorsGeneric(sensors []int) (sr interface{}, err error)

Sensors gets sensors for one or more sensor IDs provided The result is an interface{} for generic use

func (*Client) Stations

func (w *Client) Stations(stations []int) (sr StationsResponse, err error)

Stations gets weather stations for one or more station IDs provided

func (*Client) StationsGeneric added in v1.0.4

func (w *Client) StationsGeneric(stations []int) (sr interface{}, err error)

StationsGeneric gets weather stations for one or more station IDs provided The result is an interface{} for generic use

type Config

type Config struct {
	Client *http.Client
	Key    string
	Secret string
}

Config contains the fields to construct a Client. Client is optional.

func (*Config) NewClient

func (c *Config) NewClient() *Client

NewClient returns a WeatherLink client for interacting with the API

type CurrentResponse

type CurrentResponse struct {
	StationID int `json:"station_id"`
	Sensors   []struct {
		Lsid              int `json:"lsid"`
		SensorType        int `json:"sensor_type"`
		DataStructureType int `json:"data_structure_type"`
		Data              []struct {
			Ts                int64       `json:"ts"`
			BarTrend          float64     `json:"bar_trend"`
			Bar               float64     `json:"bar"`
			TempIn            float64     `json:"temp_in"`
			HumIn             float64     `json:"hum_in"`
			TempOut           float64     `json:"temp_out"`
			WindSpeed         float64     `json:"wind_speed"`
			WindSpeed10MinAvg float64     `json:"wind_speed_10_min_avg"`
			WindDir           float64     `json:"wind_dir"`
			TempExtra1        interface{} `json:"temp_extra_1"`
			TempExtra2        interface{} `json:"temp_extra_2"`
			TempExtra3        interface{} `json:"temp_extra_3"`
			TempExtra4        interface{} `json:"temp_extra_4"`
			TempExtra5        interface{} `json:"temp_extra_5"`
			TempExtra6        interface{} `json:"temp_extra_6"`
			TempExtra7        interface{} `json:"temp_extra_7"`
			TempSoil1         interface{} `json:"temp_soil_1"`
			TempSoil2         interface{} `json:"temp_soil_2"`
			TempSoil3         interface{} `json:"temp_soil_3"`
			TempSoil4         interface{} `json:"temp_soil_4"`
			TempLeaf1         interface{} `json:"temp_leaf_1"`
			TempLeaf2         interface{} `json:"temp_leaf_2"`
			TempLeaf3         interface{} `json:"temp_leaf_3"`
			TempLeaf4         interface{} `json:"temp_leaf_4"`
			HumOut            float64     `json:"hum_out"`
			HumExtra1         interface{} `json:"hum_extra_1"`
			HumExtra2         interface{} `json:"hum_extra_2"`
			HumExtra3         interface{} `json:"hum_extra_3"`
			HumExtra4         interface{} `json:"hum_extra_4"`
			HumExtra5         interface{} `json:"hum_extra_5"`
			HumExtra6         interface{} `json:"hum_extra_6"`
			HumExtra7         interface{} `json:"hum_extra_7"`
			RainRateClicks    float64     `json:"rain_rate_clicks"`
			RainRateIn        float64     `json:"rain_rate_in"`
			RainRateMm        float64     `json:"rain_rate_mm"`
			Uv                interface{} `json:"uv"`
			SolarRad          interface{} `json:"solar_rad"`
			RainStormClicks   float64     `json:"rain_storm_clicks"`
			RainStormIn       float64     `json:"rain_storm_in"`
			RainStormMm       float64     `json:"rain_storm_mm"`
			RainDayClicks     float64     `json:"rain_day_clicks"`
			RainDayIn         float64     `json:"rain_day_in"`
			RainDayMm         float64     `json:"rain_day_mm"`
			RainMonthClicks   float64     `json:"rain_month_clicks"`
			RainMonthIn       float64     `json:"rain_month_in"`
			RainMonthMm       float64     `json:"rain_month_mm"`
			RainYearClicks    float64     `json:"rain_year_clicks"`
			RainYearIn        float64     `json:"rain_year_in"`
			RainYearMm        float64     `json:"rain_year_mm"`
			EtDay             float64     `json:"et_day"`
			EtMonth           float64     `json:"et_month"`
			EtYear            float64     `json:"et_year"`
			MoistSoil1        interface{} `json:"moist_soil_1"`
			MoistSoil2        interface{} `json:"moist_soil_2"`
			MoistSoil3        interface{} `json:"moist_soil_3"`
			MoistSoil4        interface{} `json:"moist_soil_4"`
			WetLeaf1          interface{} `json:"wet_leaf_1"`
			WetLeaf2          interface{} `json:"wet_leaf_2"`
			WetLeaf3          interface{} `json:"wet_leaf_3"`
			WetLeaf4          interface{} `json:"wet_leaf_4"`
		} `json:"data"`
	} `json:"sensors"`
	GeneratedAt int `json:"generated_at"`
}

CurrentResponse represents data from the /current endpoint

type HistoricResponse

type HistoricResponse struct {
	Sensors []struct {
		Lsid int `json:"lsid"`
		Data []struct {
			Ts               int64   `json:"ts"`
			ArchInt          int     `json:"arch_int"`
			RevType          int     `json:"rev_type"`
			TempOut          float64 `json:"temp_out"`
			TempOutHi        float64 `json:"temp_out_hi"`
			TempOutLo        float64 `json:"temp_out_lo"`
			TempIn           float64 `json:"temp_in"`
			HumIn            float64 `json:"hum_in"`
			HumOut           float64 `json:"hum_out"`
			RainfallIn       float64 `json:"rainfall_in"`
			RainfallClicks   float64 `json:"rainfall_clicks"`
			RainfallMm       float64 `json:"rainfall_mm"`
			RainRateHiIn     float64 `json:"rain_rate_hi_in"`
			RainRateHiClicks float64 `json:"rain_rate_hi_clicks"`
			RainRateHiMm     float64 `json:"rain_rate_hi_mm"`
			Et               float64 `json:"et"`
			Bar              float64 `json:"bar"`
			WindNumSamples   float64 `json:"wind_num_samples"`
			WindSpeedAvg     float64 `json:"wind_speed_avg"`
			WindSpeedHi      float64 `json:"wind_speed_hi"`
			WindDirOfHi      float64 `json:"wind_dir_of_hi"`
			WindDirOfPrevail float64 `json:"wind_dir_of_prevail"`
			ForecastRule     float64 `json:"forecast_rule"`
			AbsPress         float64 `json:"abs_press"`
			BarNoaa          float64 `json:"bar_noaa"`
			DewPointOut      float64 `json:"dew_point_out"`
			DewPointIn       float64 `json:"dew_point_in"`
			Emc              float64 `json:"emc"`
			HeatIndexOut     float64 `json:"heat_index_out"`
			HeatIndexIn      float64 `json:"heat_index_in"`
			WindChill        float64 `json:"wind_chill"`
			WindRun          float64 `json:"wind_run"`
			DegDaysHeat      float64 `json:"deg_days_heat"`
			DegDaysCool      float64 `json:"deg_days_cool"`
			ThwIndex         float64 `json:"thw_index"`
			WetBulb          float64 `json:"wet_bulb"`
		} `json:"data"`
		SensorType        int `json:"sensor_type"`
		DataStructureType int `json:"data_structure_type"`
	} `json:"sensors"`
	GeneratedAt int `json:"generated_at"`
	StationID   int `json:"station_id"`
}

HistoricResponse represents historic data for one station ID within a given timerange

type SensorsResponse

type SensorsResponse struct {
	Sensors []struct {
		Lsid              int         `json:"lsid"`
		SensorType        int         `json:"sensor_type"`
		Category          string      `json:"category"`
		Manufacturer      string      `json:"manufacturer"`
		ProductName       string      `json:"product_name"`
		ProductNumber     string      `json:"product_number"`
		RainCollectorType int         `json:"rain_collector_type"`
		Active            bool        `json:"active"`
		CreatedDate       int         `json:"created_date"`
		ModifiedDate      int         `json:"modified_date"`
		StationID         int         `json:"station_id"`
		StationName       string      `json:"station_name"`
		ParentDeviceType  string      `json:"parent_device_type"`
		ParentDeviceName  string      `json:"parent_device_name"`
		ParentDeviceID    int         `json:"parent_device_id"`
		ParentDeviceIDHex string      `json:"parent_device_id_hex"`
		PortNumber        int         `json:"port_number"`
		Latitude          float64     `json:"latitude"`
		Longitude         float64     `json:"longitude"`
		Elevation         float64     `json:"elevation"`
		TxID              interface{} `json:"tx_id"`
	} `json:"sensors"`
	GeneratedAt int `json:"generated_at"`
}

SensorsResponse represents data from the /sensors endpoint

type SignatureParams

type SignatureParams map[string]string

func (SignatureParams) Add

func (s SignatureParams) Add(key string, value string)

Add a kv parameter to the signature

func (SignatureParams) Signature added in v1.0.1

func (s SignatureParams) Signature(secret string) string

Signature encodes and returns the HMAC hexadecimal string

func (SignatureParams) String added in v1.0.1

func (s SignatureParams) String() string

String is the unencoded signature

type StationsResponse

type StationsResponse struct {
	Stations []struct {
		StationID           int     `json:"station_id"`
		StationName         string  `json:"station_name"`
		GatewayID           int     `json:"gateway_id"`
		GatewayIDHex        string  `json:"gateway_id_hex"`
		ProductNumber       string  `json:"product_number"`
		Username            string  `json:"username"`
		UserEmail           string  `json:"user_email"`
		CompanyName         string  `json:"company_name"`
		Active              bool    `json:"active"`
		Private             bool    `json:"private"`
		RecordingInterval   int     `json:"recording_interval"`
		FirmwareVersion     string  `json:"firmware_version"`
		Meid                string  `json:"meid"`
		RegisteredDate      int     `json:"registered_date"`
		SubscriptionEndDate int     `json:"subscription_end_date"`
		TimeZone            string  `json:"time_zone"`
		City                string  `json:"city"`
		Region              string  `json:"region"`
		Country             string  `json:"country"`
		Latitude            float64 `json:"latitude"`
		Longitude           float64 `json:"longitude"`
		Elevation           float64 `json:"elevation"`
	} `json:"stations"`
	GeneratedAt int `json:"generated_at"`
}

StationsResponse represents data from the /stations endpoint

Directories

Path Synopsis
examples
cmd

Jump to

Keyboard shortcuts

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