Skip to content

Solcast/solcast_net

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

47 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Live Glitch 🌞Demo🌞

NuGet Build Status Build status Join the chat at https://gitter.im/Solcast/Lobby

Solcast .NET API Client library

.NET client library for querying the Solcast API async/sync

This module allows a registered users to query the Solcast API https://api.solcast.com.au. You will need to register your user account to obtain an API key https://solcast.com.au/api/register. Without an API key you will not be able to successfully obtain valid API results.

Windows setup Solcast API Key

Setup System/User environment variable. Details on advanced editing StackOverflow superuser walkthrough

WinKey + R

Copy and Paste the following text to the Open: input text box for the Run Dialog

%windir%\System32\rundll32.exe sysdm.cpl,EditEnvironmentVariables

That will present this screen

Run Windows Environment Editor

Add a USER or SYSTEM environment variable to hold the Solcast API key. User environment variables will only be available to your particular user, system environment variables are shared for all users on the system

Add Windows User Solcast API key

After you have added the environment variable you will see the key listed in the current variables

Added Windows User Solcast API key

NOTE: To reference this key you will need to reopen your shell prompt to read these variables again from the system (cmd, command.com, powershell, etc)

Linux / mac OS

Open a terminal prompt

  • mac OS: Spotlight search for terminal
  • Linux: Open bash
nano .bash_profile

If you do not have nano it is a simpler text editor than vi. Use your package manager to download and install or use vi. The preferred package manager for mac OS is Homebrew and once installed on your system you can issue similar commands to Linux apt-get and yum with the brew package manager.

Add the Solcast API Key to your user profile variables.

Added mac OS User Solcast API key

Latitude and Longitude

  • First as stated above you will need an API key to make valid API requests to the Solcast system.
  • Second for all current library calls you will need a valid Lat/Lng coordinate in the EPSG:4326 format. If you are familiar with modern web maps you most likely have used the expected format or a decimal point that expresses a position on the Earth.

Clarification as I often forget the coordinate planes of Latitude and Longitude along with bounds. Lat/Lng

Credits - Learner.org

The Solcast API expects West for Longitude and South for Latitude to be expressed as a negative numbers

Example Locations on the Globe

Name Latitude Longitude
Sydney, Australia -33.865143 151.209900
Mumbai, India β€Ž 19.228825 72.854118
Tokyo, Japan 35.6895 139.69171
Paris, France 48.864716 2.349014
Los Angeles, USA 34.052235 -118.243683

Need help?

How to contribute

  • Fork the repository
  • Add something awesome
  • Create a pull request
  • 🌞 Celebrate 🌞

Example CLI provided for reference with multiple querying strategies

Examples

NOTE:

You can use standard environment variables to hold your API key and not need to pass the optional apiKey to the current methods

Environment variable name if you care to work with it directly

SOLCAST_API_KEY

Accessible through process environment variable directly or with helper API method.

RECOMMENDED

var key = API.Key();

OR IF YOU MUST

var key = Environment.GetEnvironmentVariable("SOLCAST_API_KEY");

C# sync Single request

using (var client = new SolcastClient())
{
	return client.GetPvPowerForecasts(new Location
	{
		Latitude = 32,
		Longitude = -97
	});
}

C# async Single request

using (var client = new SolcastClient())
{
	return await client.GetPvPowerForecastsAsync(new Location
	{
		Latitude = 32,
		Longitude = -97
	});
}

C# sync Single request with Wait and Retry

// Set a policy on WebServiceExceptions with StatusCode of 429 to wait and retry the request again in 5 seconds
var policy = Policy
	.Handle<WebServiceException>(z => z.StatusCode == 429)
	.WaitAndRetry(new[] { TimeSpan.FromSeconds(5) });

return policy.Execute(() =>
{
	using (var client = new SolcastClient())
	{
		return client.GetPvPowerForecasts(new Location
		{
			Latitude = 32,
			Longitude = -97
		});
	}
});

C# sync Sequential requests as batch

using (var client = new SolcastClient())
{
	return locations.Select(location => client.GetPvPowerForecasts(location)).ToList();
}

C# sync Parallel requests as batch

var results = new List<GetPvPowerForecastsResponse>();
using (var client = new SolcastClient())
{
	Parallel.ForEach(locations, location =>
	{
		results.Add(client.GetPvPowerForecasts(location));
	});                
}
return results;

C# Change Client properties this is only a sample of a few of the available properties

// Timeout is now set to 5 minutes
client.GetHttpClient().Timeout = TimeSpan.FromMinutes(5);
// Use a different API KEY
client.Key = "<DIFFERENT API KEY>";
client.RateLimitExceededFn = message =>
{
	// Custom Action<HttpResponseMessage> if RateLimit has been exceeded
};

License

License can be found here: LICENSE