Live Glitch 🌞Demo🌞
.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.
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
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
After you have added the environment variable
you will see the key listed in the current variables
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)
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.
- 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.
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 |
- Fork the repository
- Add something awesome
- Create a pull request
- 🌞 Celebrate 🌞
Example CLI provided for reference with multiple querying strategies
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");
using (var client = new SolcastClient())
{
return client.GetPvPowerForecasts(new Location
{
Latitude = 32,
Longitude = -97
});
}
using (var client = new SolcastClient())
{
return await client.GetPvPowerForecastsAsync(new Location
{
Latitude = 32,
Longitude = -97
});
}
// 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
});
}
});
using (var client = new SolcastClient())
{
return locations.Select(location => client.GetPvPowerForecasts(location)).ToList();
}
var results = new List<GetPvPowerForecastsResponse>();
using (var client = new SolcastClient())
{
Parallel.ForEach(locations, location =>
{
results.Add(client.GetPvPowerForecasts(location));
});
}
return results;
// 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 can be found here: LICENSE