Help us shape the future of Go! Take the 2026 Go Developer Survey

goweather

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2019 License: MIT Imports: 6 Imported by: 0

README

GoWeather

A way to read data from a USB weatherstation based on the FineOffset WH1080 or compatible device.

This is meant to be used as a way to read data from the device and return something that can be used for other applications

Usage

Use this to get data from a weather station, you need to make sure that you allow read access to the WH1080 device via USB by adding the following udev rule

# cat /etc/udev/rules.d/99-wh1080.rules 
SUBSYSTEM=="usb", ATTRS{idVendor}=="1941", ATTRS{idProduct}=="8021", MODE="0666"

Example program

package main

import (
	"fmt"
	"log"
	"encoding/json"
	weather "github.com/shreddedbacon/goweather"
)

func main() {
	wh1080, err := weather.New() //open the usb connection and hold it here
	if err != nil {
		log.Fatalln(err)
	}	
	serialBufferMain := wh1080.Read(0x00, 0x100)
	mainData := wh1080.ReturnMainData(serialBufferMain)
	serialBufferCurrent := wh1080.Read(mainData.State.CurrentPos, 0x20)
	currentData := wh1080.ReturnCurrentData(serialBufferCurrent, mainData.State.CurrentPos)
	fullData := &weather.FullData{
		CurrentData: *currentData,
		WH1080Data:  *mainData,
	}
	jsonData, _ := json.Marshal(fullData)
	fmt.Println(string(jsonData))
}

Output

{
	"current_data": {
		"indoor_humidity": 41,
		"indoor_temp": 21.5,
		"status_RCO": false,
		"wind_dir": 315,
		"cursor": 51312,
		"status_LOC": false,
		"ave_wind_speed": 0,
		"outdoor_humidity": 94,
		"gust_wind_speed": 0,
		"delay": 1,
		"abs_pressure": 972.9,
		"time": 0,
		"rain_total": 1887.3,
		"outdoor_temp": 4.4,
		"time_str": "2019-06-27T11:14:18Z"
	},
	"main_data": {
		"display_option": {
			"show_rain_month": false,
			"date_alarm_time": false,
			"show_outdoor_temp": true,
			"date_month-day-year": false,
			"show_rain_hour": true,
			"show_rain_day": false,
			"time_scale_24_hour": false,
			"show_outdoor_chill": false,
			"show_rain_total": false,
			"wind_speed_gust": false,
			"pressure_relative": true,
			"show_rain_week": false,
			"date_show_year": true,
			"show_outdoor_dew": false,
			"time_12": false,
			"date_show_day_name": false
		},
		"alarm": {
			"absolute_pressure_high": 1040,
			"outdoor_temp_low": -10,
			"gust_wind_speed_ms": 36,
			"average_wind_speed_ms": 18,
			"wind_direction": 0,
			"outdoor_humidity_high": 70,
			"windchill_low": 0,
			"absolute_pressure_low": 960,
			"outdoor_humidity_low": 45,
			"relative_pressure_high": 1040,
			"indoor_temp_high": 20,
			"rain_daily": 50,
			"gust_wind_speed_bft": 0,
			"average_wind_speed_bft": 0,
			"dewpoint_low": -10,
			"indoor_temp_low": 0,
			"windchill_high": 20,
			"indoor_humidity_high": 65,
			"indoor_humidity_low": 35,
			"relative_pressure_low": 960,
			"dewpoint_high": 10,
			"rain_hourly": 1,
			"time": [12, 0],
			"outdoor_temp_high": 30
		},
		"state": {
			"no_of_readings": 3192,
			"current_pos": 51312,
			"absolute_pressure": 972.9,
			"time_zone": 0,
			"read_Period": 5,
			"relative_pressure": 1025.5,
			"current_date_time": [19, 6, 27, 21, 12]
		},
		"minmax": {
			"min_wind_chill": -7,
			"min_indoor_humidity": 11,
			"min_outdoor_temp_date": [18, 7, 21, 6, 23],
			"min_abs_pressure": 933.6,
			"max_dew_point_date": [18, 1, 19, 16, 54],
			"max_indoor_temp": 36.4,
			"max_outdoor_humidity": 99,
			"min_dew_point": -11.8,
			"max_rain_total": 585.3,
			"min_outdoor_temp": -7,
			"max_rain_month_nibble": 0,
			"max_rain_weekly": 64.5,
			"max_rain_daily": 35.1,
			"max_abs_pressure_date": [10, 1, 1, 12, 0],
			"min_rel_pressure_date": [16, 9, 30, 5, 15],
			"max_wind_chill": 44.400000000000006,
			"max_rain_daily_date": [15, 1, 11, 13, 38],
			"min_outdoor_humidity": 10,
			"min_outdoor_humidity_date": [10, 1, 1, 12, 0],
			"min_rel_pressure": 991.7,
			"max_rain_monthly": 99.9,
			"min_indoor_temp": 40,
			"max_abs_pressure": 1018.3,
			"max_rel_pressure": 1042.6,
			"max_rain_monthly_date": [17, 11, 14, 10, 19],
			"max_wind_chill_date": [39, 1, 14, 13, 51],
			"max_rain_hourly_date": [15, 1, 24, 13, 1],
			"max_rain_hourly": 848.3,
			"max_outdoor_temp": 44.400000000000006,
			"max_rel_pressure_date": [15, 10, 8, 8, 48],
			"max_rain_total_nibble": 0,
			"max_outdoor_humidity_date": [15, 11, 26, 6, 33],
			"max_indoor_temp_date": [15, 3, 11, 16, 53],
			"max_outdoor_temp_date": [19, 1, 14, 13, 51],
			"max_ave_wind_speed_date": [18, 6, 2, 21, 1],
			"max_rain_weekly_date": [10, 1, 6, 20, 46],
			"max_indoor_humidity_date": [17, 3, 21, 10, 53],
			"max_gust_wind_speed": 54.4,
			"max_rain_total_date": [15, 12, 26, 10, 20],
			"min_dew_point_date": [90, 1, 1, 12, 0],
			"max_dew_point": 37,
			"min_abs_pressure_date": [16, 9, 30, 5, 15],
			"max_average_wind_speed": 43.5,
			"max_gust_wind_speed_date": [17, 1, 20, 18, 30],
			"min_indoor_temp_date": [15, 1, 24, 10, 19],
			"min_wind_chill_date": [18, 7, 21, 6, 23],
			"max_indoor_humidity": 92,
			"min_indoor_humidity_date": [14, 12, 16, 16, 42]
		},
		"alarm_enable": {
			"outdoor_temp_low": false,
			"wind_average": false,
			"wind_direction": false,
			"outdoor_humidity_high": false,
			"abs_pressure_low": false,
			"outdoor_humidity_low": false,
			"indoor_temp_high": false,
			"rel_pressure_high": false,
			"rain_daily": false,
			"abs_pressure_high": false,
			"wind_chill_low": false,
			"wind_chill_high": false,
			"dew_point_low": false,
			"dew_point_high": false,
			"indoor_temp_low": false,
			"wind_gust": false,
			"indoor_humidity_high": false,
			"indoor_humidity_low": false,
			"rain_hourly": false,
			"time": false,
			"outdoor_temp_high": false,
			"rel_pressure_low": false
		},
		"unit_setting": {
			"windspeed_knot": false,
			"windspeed_bft": false,
			"outdoor_Temp_F": false,
			"rain_inch": false,
			"pressure_inHg": false,
			"pressure_mmHg": false,
			"indoor_Temp_F": false,
			"pressure_hPa": true,
			"windspeed_ms": false,
			"windspeed_kmh": true,
			"windspeed_mh": false
		}
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BitIsSset

func BitIsSset(b int, bit uint) bool

check bit is set / true/false

func BytesToShort

func BytesToShort(byte_high byte, byte_low byte) float64

turn bytes to signed short

func Float2DecimalString

func Float2DecimalString(f float64) string

print float to string

func FromBCD

func FromBCD(bcd []byte) []int

turn bytes to ints

func UintToString

func UintToString(i uint) string

turn uint to string

Types

type Alarm

type Alarm struct {
	AbsolutePressureHigh float64 `json:"absolute_pressure_high"`
	OutdoorTempLow       float64 `json:"outdoor_temp_low"`
	GustWindSpeedMs      float64 `json:"gust_wind_speed_ms"`
	AverageWindSpeedMs   float64 `json:"average_wind_speed_ms"`
	WindDirection        float64 `json:"wind_direction"`
	OutdoorHumidityHigh  int     `json:"outdoor_humidity_high"`
	WindchillLow         float64 `json:"windchill_low"`
	AbsolutePressureLow  float64 `json:"absolute_pressure_low"`
	OutdoorHumidityLow   int     `json:"outdoor_humidity_low"`
	RelativePressureHigh float64 `json:"relative_pressure_high"`
	IndoorTempHigh       float64 `json:"indoor_temp_high"`
	RainDaily            float64 `json:"rain_daily"`
	GustWindSpeedBft     int     `json:"gust_wind_speed_bft"`
	AverageWindSpeedBft  int     `json:"average_wind_speed_bft"`
	DewpointLow          float64 `json:"dewpoint_low"`
	IndoorTempLow        float64 `json:"indoor_temp_low"`
	WindchillHigh        float64 `json:"windchill_high"`
	IndoorHumidityHigh   int     `json:"indoor_humidity_high"`
	IndoorHumidityLow    int     `json:"indoor_humidity_low"`
	RelativePressureLow  float64 `json:"relative_pressure_low"`
	DewpointHigh         float64 `json:"dewpoint_high"`
	RainHourly           float64 `json:"rain_hourly"`
	Time                 []int   `json:"time"`
	OutdoorTempHigh      float64 `json:"outdoor_temp_high"`
}

type AlarmEnable

type AlarmEnable struct {
	OutdoorTempLow      bool `json:"outdoor_temp_low"`
	WindAverage         bool `json:"wind_average"`
	WindDirection       bool `json:"wind_direction"`
	OutdoorHumidityHigh bool `json:"outdoor_humidity_high"`
	AbsPressureLow      bool `json:"abs_pressure_low"`
	OutdoorHumidityLow  bool `json:"outdoor_humidity_low"`
	IndoorTempHigh      bool `json:"indoor_temp_high"`
	RelPressureHigh     bool `json:"rel_pressure_high"`
	RainDaily           bool `json:"rain_daily"`
	AbsPressureHigh     bool `json:"abs_pressure_high"`
	WindChillLow        bool `json:"wind_chill_low"`
	WindChillHigh       bool `json:"wind_chill_high"`
	DewPointLow         bool `json:"dew_point_low"`
	DewPointHigh        bool `json:"dew_point_high"`
	IndoorTempLow       bool `json:"indoor_temp_low"`
	WindGust            bool `json:"wind_gust"`
	IndoorHumidityHigh  bool `json:"indoor_humidity_high"`
	IndoorHumidityLow   bool `json:"indoor_humidity_low"`
	RainHourly          bool `json:"rain_hourly"`
	Time                bool `json:"time"`
	OutdoorTempHigh     bool `json:"outdoor_temp_high"`
	RelPressureLow      bool `json:"rel_pressure_low"`
}

type Client added in v0.1.0

type Client interface {
	Read(int, int) []byte
	ReturnMainData([]byte) *WH1080Data
	ReturnCurrentData([]byte, int) *CurrentData
	CollectData() *FullData
}

Client struct

func New added in v0.1.0

func New() (Client, error)

type CurrentData

type CurrentData struct {
	IndoorHumidity  int     `json:"indoor_humidity"`
	IndoorTemp      float64 `json:"indoor_temp"`
	StatusRCO       bool    `json:"status_RCO"`
	WindDir         float64 `json:"wind_dir"`
	Cursor          int     `json:"cursor"`
	StatusLOC       bool    `json:"status_LOC"`
	AveWindSpeed    float64 `json:"ave_wind_speed"`
	OutdoorHumidity int     `json:"outdoor_humidity"`
	GustWindSpeed   float64 `json:"gust_wind_speed"`
	Delay           int     `json:"delay"`
	AbsPressure     float64 `json:"abs_pressure"`
	Time            float64 `json:"time"`
	RainTotal       float64 `json:"rain_total"`
	OutdoorTemp     float64 `json:"outdoor_temp"`
	TimeStr         string  `json:"time_str"`
	ApparentTemp    float64 `json:"apparent_temp"`
}

type DisplayOption

type DisplayOption struct {
	ShowRainMonth    bool `json:"show_rain_month"`
	DateAlarmTime    bool `json:"date_alarm_time"`
	ShowOutdoorTemp  bool `json:"show_outdoor_temp"`
	DateMonthDayYear bool `json:"date_month-day-year"`
	ShowRainHour     bool `json:"show_rain_hour"`
	ShowRainDay      bool `json:"show_rain_day"`
	TimeScale24Hour  bool `json:"time_scale_24_hour"`
	ShowOutdoorChill bool `json:"show_outdoor_chill"`
	ShowRainTotal    bool `json:"show_rain_total"`
	WindSpeedGust    bool `json:"wind_speed_gust"`
	PressureRelative bool `json:"pressure_relative"`
	ShowRainWeek     bool `json:"show_rain_week"`
	DateShowYear     bool `json:"date_show_year"`
	ShowOutdoorDew   bool `json:"show_outdoor_dew"`
	Time12           bool `json:"time_12"`
	DateShowDayName  bool `json:"date_show_day_name"`
}

type FullData

type FullData struct {
	CurrentData CurrentData `json:"current_data"`
	WH1080Data  WH1080Data  `json:"main_data"`
}

type Interface added in v0.1.0

type Interface struct {
	WH1080 *hid.Device
}

Interface struct

func (*Interface) CollectData added in v0.1.0

func (gow *Interface) CollectData() *FullData

func (*Interface) Read added in v0.1.0

func (gow *Interface) Read(address int, offset int) []byte

func (*Interface) ReturnCurrentData added in v0.1.1

func (gow *Interface) ReturnCurrentData(data []byte, cursor int) *CurrentData

Return CurrentData

func (*Interface) ReturnMainData added in v0.1.0

func (gow *Interface) ReturnMainData(data []byte) *WH1080Data

return maindata

type Minmax

type Minmax struct {
	MinWindChill           float64 `json:"min_wind_chill"`
	MinIndoorHumidity      int     `json:"min_indoor_humidity"`
	MinOutdoorTempDate     []int   `json:"min_outdoor_temp_date"`
	MinAbsPressure         float64 `json:"min_abs_pressure"`
	MaxDewPointDate        []int   `json:"max_dew_point_date"`
	MaxIndoorTemp          float64 `json:"max_indoor_temp"`
	MaxOutdoorHumidity     int     `json:"max_outdoor_humidity"`
	MinDewPoint            float64 `json:"min_dew_point"`
	MaxRainTotal           float64 `json:"max_rain_total"`
	MinOutdoorTemp         float64 `json:"min_outdoor_temp"`
	MaxRainMonthNibble     int     `json:"max_rain_month_nibble"`
	MaxRainWeekly          float64 `json:"max_rain_weekly"`
	MaxRainDaily           float64 `json:"max_rain_daily"`
	MaxAbsPressureDate     []int   `json:"max_abs_pressure_date"`
	MinRelPressureDate     []int   `json:"min_rel_pressure_date"`
	MaxWindChill           float64 `json:"max_wind_chill"`
	MaxRainDailyDate       []int   `json:"max_rain_daily_date"`
	MinOutdoorHumidity     int     `json:"min_outdoor_humidity"`
	MinOutdoorHumidityDate []int   `json:"min_outdoor_humidity_date"`
	MinRelPressure         float64 `json:"min_rel_pressure"`
	MaxRainMonthly         float64 `json:"max_rain_monthly"`
	MinIndoorTemp          float64 `json:"min_indoor_temp"`
	MaxAbsPressure         float64 `json:"max_abs_pressure"`
	MaxRelPressure         float64 `json:"max_rel_pressure"`
	MaxRainMonthlyDate     []int   `json:"max_rain_monthly_date"`
	MaxWindChillDate       []int   `json:"max_wind_chill_date"`
	MaxRainHourlyDate      []int   `json:"max_rain_hourly_date"`
	MaxRainHourly          float64 `json:"max_rain_hourly"`
	MaxOutdoorTemp         float64 `json:"max_outdoor_temp"`
	MaxRelPressureDate     []int   `json:"max_rel_pressure_date"`
	MaxRainTotalNibble     int     `json:"max_rain_total_nibble"`
	MaxOutdoorHumidityDate []int   `json:"max_outdoor_humidity_date"`
	MaxIndoorTempDate      []int   `json:"max_indoor_temp_date"`
	MaxOutdoorTempDate     []int   `json:"max_outdoor_temp_date"`
	MaxAveWindSpeedDate    []int   `json:"max_ave_wind_speed_date"`
	MaxRainWeeklyDate      []int   `json:"max_rain_weekly_date"`
	MaxIndoorHumidityDate  []int   `json:"max_indoor_humidity_date"`
	MaxGustWindSpeed       float64 `json:"max_gust_wind_speed"`
	MaxRainTotalDate       []int   `json:"max_rain_total_date"`
	MinDewPointDate        []int   `json:"min_dew_point_date"`
	MaxDewPoint            float64 `json:"max_dew_point"`
	MinAbsPressureDate     []int   `json:"min_abs_pressure_date"`
	MaxAverageWindSpeed    float64 `json:"max_average_wind_speed"`
	MaxGustWindSpeedDate   []int   `json:"max_gust_wind_speed_date"`
	MinIndoorTempDate      []int   `json:"min_indoor_temp_date"`
	MinWindChillDate       []int   `json:"min_wind_chill_date"`
	MaxIndoorHumidity      int     `json:"max_indoor_humidity"`
	MinIndoorHumidityDate  []int   `json:"min_indoor_humidity_date"`
}

type State

type State struct {
	NoOfReadings     int     `json:"no_of_readings"`
	CurrentPos       int     `json:"current_pos"`
	AbsolutePressure float64 `json:"absolute_pressure"`
	TimeZone         int     `json:"time_zone"`
	ReadPeriod       int     `json:"read_Period"`
	RelativePressure float64 `json:"relative_pressure"`
	CurrentDateTime  []int   `json:"current_date_time"`
}

type UnitSetting

type UnitSetting struct {
	WindspeedKnot bool `json:"windspeed_knot"`
	WindspeedBft  bool `json:"windspeed_bft"`
	OutdoorTempF  bool `json:"outdoor_Temp_F"`
	RainInch      bool `json:"rain_inch"`
	PressureInHg  bool `json:"pressure_inHg"`
	PressureMmHg  bool `json:"pressure_mmHg"`
	IndoorTempF   bool `json:"indoor_Temp_F"`
	PressureHPa   bool `json:"pressure_hPa"`
	WindspeedMs   bool `json:"windspeed_ms"`
	WindspeedKmh  bool `json:"windspeed_kmh"`
	WindspeedMh   bool `json:"windspeed_mh"`
}

type WH1080Data

type WH1080Data struct {
	DisplayOption DisplayOption `json:"display_option"`
	Alarm         Alarm         `json:"alarm"`
	State         State         `json:"state"`
	Minmax        Minmax        `json:"minmax"`
	AlarmEnable   AlarmEnable   `json:"alarm_enable"`
	UnitSetting   UnitSetting   `json:"unit_setting"`
}

Jump to

Keyboard shortcuts

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