func (demo ClearBladeInfo) publishMessage() {

	weather, err := owm.NewCurrent("F", "en")

	if err != nil {

		os.Exit(1)
	}

	weather.CurrentByName("Austin, TX")

	bytes, err1 := json.Marshal(weather)
	checkError(err1)

	topic := "Austin Weather"

	fmt.Printf("Publish: %s, Msg: %s\n", topic, weather)

	err = demo.UserClient.Publish(topic, bytes, gosdk.QOS_AtMostOnce)
	checkError(err)

	demo.ReceivedMessage, err = demo.UserClient.Subscribe("test", gosdk.QOS_AtMostOnce)
	//fmt.Println(demo.ReceivedMessage)
	checkError(err)
}
Example #2
0
// getCurrent gets the current weather for the provided
// location in the units provided.
func getCurrent(l, u, lang string) *owm.CurrentWeatherData {
	w, err := owm.NewCurrent(u, lang)
	if err != nil {
		log.Fatalln(err)
	}
	w.CurrentByName(l)
	return w
}
// getCurrent gets the current weather for the provided location in
// the units provided.
func getCurrent(l, u, lang string) *owm.CurrentWeatherData {
	w, err := owm.NewCurrent(u, lang) // Create the instance with the given unit
	if err != nil {
		log.Fatal(err)
	}
	w.CurrentByName(l) // Get the actual data for the given location
	return w
}
Example #4
0
func GetWeather(place string) (*openweathermap.CurrentWeatherData, error) {
	w, err := openweathermap.NewCurrent("F", "en")
	if err != nil {
		return nil, fmt.Errorf("Could not get weather: %s", err)
	}

	err = w.CurrentByName(place)
	if err != nil {
		return nil, fmt.Errorf("Weather fetch fail:", err)
	}
	return w, nil
}
func outside(srv *Service) sensorData {
	w, err := owm.NewCurrent("C", "EN")
	if err != nil {
		glog.Infoln(err)
	}
	w.CurrentByID(srv.OWMcityID)
	s := sensorData{
		temperature: w.Main.Temp,
		humidity:    float64(w.Main.Humidity),
	}
	return s
}
Example #6
0
func getWeather(location string) (result string) {
	w, err := owm.NewCurrent("C", "en")
	if err != nil {
		log.Print("getWeather() => newCurrent() error:\n", err)
		return "error"
	}

	w.CurrentByName(location)
	result += fmt.Sprintf("***Weather for %s (%s)***\n\n", w.Name, w.Sys.Country)
	result += fmt.Sprintf("```Temperature: %.1f°C\n", w.Main.Temp)
	result += fmt.Sprintf("Humidity: %d%%\n", w.Main.Humidity)
	for _, item := range w.Weather {
		result += fmt.Sprintf("%s: %s\n", item.Main, item.Description)
	}
	result += fmt.Sprintf("Wind speed: %.1fm/s\n", w.Wind.Speed)
	result += fmt.Sprintf("Clouds: %d%%```", w.Clouds.All)
	return
}
Example #7
0
func main() {
	jWeather := utils.JWeather{}

	f, err := os.Create(os.Getenv("GOPATH") + "/output/openweather.json")

	if err != nil {
		log.Fatalln(err)
		os.Exit(1)
	}

	defer f.Close()

	current, err := owm.NewCurrent("C", "sv")
	if err != nil {
		log.Fatalln(err)
	}

	forecast, err := owm.NewForecast("C", "sv")

	if err != nil {
		log.Fatalln(err)
	}

	err = forecast.DailyByID(2673730, 5)

	if err != nil {
		log.Fatalln(err)
	} else {
		for _, weather := range forecast.List {
			jWeather.JForecastWeatherList = append(jWeather.JForecastWeatherList, utils.JForecastWeather{
				TempDay:     weather.Temp.Day,
				TempMin:     weather.Temp.Min,
				TempMax:     weather.Temp.Max,
				TempNight:   weather.Temp.Night,
				Pressure:    weather.Pressure,
				Humidity:    weather.Humidity,
				Weather:     weather.Weather[0].Main,
				Description: weather.Weather[0].Description,
				ID:          weather.Weather[0].ID,
			})
		}
	}

	err = current.CurrentByID(2673730)
	if err != nil {
		log.Fatalln(err)
	} else {
		jWeather.JCurrentWeather = utils.JCurrentWeather{
			Sunrise:     &utils.Timestamp{Time: time.Unix(int64(current.Sys.Sunrise), 0)},
			Sunset:      &utils.Timestamp{Time: time.Unix(int64(current.Sys.Sunset), 0)},
			Temp:        current.Main.Temp,
			TempMin:     current.Main.TempMin,
			TempMax:     current.Main.TempMax,
			Pressure:    current.Main.Pressure,
			Humidity:    current.Main.Humidity,
			Weather:     current.Weather[0].Main,
			Description: current.Weather[0].Description,
			ID:          current.Weather[0].ID,
		}

		jWeather.Updated = &utils.Timestamp{Time: time.Now()}

		byteArray, err := json.Marshal(jWeather)

		if err == nil {
			f.Write(byteArray)
		} else {
			log.Fatalln(err)
		}
	}
}