myNOC.WeatherLink 0.2.3

dotnet add package myNOC.WeatherLink --version 0.2.3
                    
NuGet\Install-Package myNOC.WeatherLink -Version 0.2.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="myNOC.WeatherLink" Version="0.2.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="myNOC.WeatherLink" Version="0.2.3" />
                    
Directory.Packages.props
<PackageReference Include="myNOC.WeatherLink" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add myNOC.WeatherLink --version 0.2.3
                    
#r "nuget: myNOC.WeatherLink, 0.2.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package myNOC.WeatherLink@0.2.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=myNOC.WeatherLink&version=0.2.3
                    
Install as a Cake Addin
#tool nuget:?package=myNOC.WeatherLink&version=0.2.3
                    
Install as a Cake Tool

Overview

A library for communicating with the WeatherLink v2 API.

This library is initially built for my needs as I am building a new Weather Website form my station, and in the process I thought this library may be useful to more people.

Supported Data Structures

This support Current Conditions and Archive data structures for WeatherLink Live ISS and AirLink. I will be adding the WeatherLink Console soon, as I just got one.

Setup and Configuration

To use myNOC.WeatherLink you will need to add it to your IServiceCollection

services.AddWeatherLink();

AddWeatherLink has an overload to either add the IAPIContext as a singled or scoped. The default is that it is added as a singleton.

You will need to setup ILogger in your project as the APIRepository uses it to log the API Uri and the response.

services.AddLogging(options => options.AddConsole());

In my sample console application I am just using IServiceProvider and GetService<> to get the instances of the objects I need.

Before using IClient you will need to setup the BaseUri, APIKey, and APISecret needed to access the WeatherLink v2 API.

BaseUri

var apiHttpClient = serviceProvider.GetService<IAPIHttpClient>()!;
apiHttpClient.BaseUri = "https://api.weatherlink.com/v2";

APIKey and APISecret

var apiContext = serviceProvider.GetService<IAPIContext>()!;
apiContext.APIKey = "{yourApiKey}";
apiContext.APISecret = "{yourApiSecret}";

Calling the API

To call the WeatherLink v2 API you will need and instance of Client and you can inject that using IClient.

Getting Station List

To get a list of the stations under your account you will use the GetStations method.

var apiClient = serviceProvider.GetService<IClient>()!;
var stations = await apiClient.GetStations();

This will return StationResponse which includes Stations of IEnumerable<Station>.

{
    "stations": [
        {
            "station_id": 1234,
            "station_name": "Milton Township",
            "product_number": "6100",
            "username": "username",
            "user_email": "user@email.com",
            "company_name": "",
            "active": true,
            "private": false,
            "recording_interval": 15,
            "firmware_version": null,
            "imei": null,
            "meid": null,
            "registered_date": 1588082732,
            "RegsisteredDate": "2020-04-28T14:05:32+00:00",
            "subscription_end_date": 0,
            "SubscriptionEndDate": "1970-01-01T00:00:00+00:00",
            "time_zone": "America/Detroit",
            "city": "Niles",
            "region": "MI",
            "country": "United States of America",
            "latitude": 41.000,
            "longitude": -86.000,
            "elevation": 839.25586
        }
    ],
    "generated_at": 1672536462,
    "GeneratedAt": "2023-01-01T01:27:42+00:00"
}

Getting Current Conditions

Once you have your station_id you can then pass that into the GetCurrent method to get the current sensor readings.

var apiClient = serviceProvider.GetService<IClient>()!;
var current = await apiClient.GetCurrent(stationId);

This will return WeatherDataResponse which includes a property Sensors of IEnumerable<Sensor>.

{
    "station_id": 88769,
    "sensors": [
        {
            "lsid": 307588,
            "sensor_type": 46,
            "data_structure_type": 10
        },
        {
            "lsid": 446594,
            "sensor_type": 323,
            "data_structure_type": 16
        }
    ],
    "generated_at": 1672536813,
    "GeneratedAt": "2023-01-01T01:33:33+00:00"
}

To properly serialize the response from GetCurrent you will need to use the SensorJsonConverterFactory.

JsonSerializerOptions options = new();
var converterFactory = serviceProvider.GetService<SensorJsonConverterFactory>();
options.Converters.Add(converterFactory!);

var current = await apiClient.GetCurrent(stationId);
var output = JsonSerializer.Serialize(current, options);

This will properly serialize all of the Sensor<T> data. Data is of IEnumerable<ISensorData>.

Deserialize

If you store the data and want to Deserialize it back into WeatherDataResponse you will again need to use the SensorJasonConverterFactory.

JsonSerializerOptions options = new();
var converterFactory = serviceProvider.GetService<SensorJsonConverterFactory>();
options.Converters.Add(converterFactory!);

var storedCurrent = GetCurrentFromStorage();
var WeatherDataResponse = JsonSerializer.Deserialize<WeatherDataResponse>(storedCurrent, options);
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.2.3 136 12/31/2024
0.2.2 129 12/31/2024
0.2.1 127 12/31/2024
0.2.0 179 3/23/2024
0.1.16 214 5/13/2023
0.1.15 215 5/7/2023
0.1.14 282 3/26/2023
0.1.13 298 3/11/2023
0.1.12 303 3/6/2023
0.1.11 303 3/6/2023
0.1.10 325 3/4/2023
0.1.9 301 3/4/2023
0.1.8 307 3/4/2023
0.1.7 315 2/26/2023
0.1.6 360 1/1/2023
0.1.5 378 1/1/2023
0.1.4 371 1/1/2023
0.1.3 361 12/31/2022
0.1.2 387 12/26/2022