David's Astronomy Pages
|
Notes (S1020) |
Notes Main |
Home Page |
Notes (S1021) |
Session Aims & Highlights | |
- Observing Result - Night Summary Plot - Session Event Log |
|
Operational Issues | |
- Critical Issues (0),
Major Issues (0),
Minor Issues (2),
Small Defects (1), Continuous Improvement
(5) |
|
No images from session [ Local Files >> ] | |
Apple WeatherKit (successor to Dark Sky Weather API) | |
Main aims
Equipment & Software
Highlights
Summary Plots & Logs
Observing Plan | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
No plan was generated for the session | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Observing Result (S2021A) |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Dome & Scope Slewing Performance | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
No data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Night Sky Summary Plot Top axis: Sky Brightness at Zenith (in ADU/s) Lefthand axis: Local Time (hh LT). Righthand axis: Sun Altitude (degs) |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Actual Weather vs Pre-Session Weather Forecast |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Session Event Log | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Session Alerts | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Back to Top
at CCDApp2.globals.SetAutoSaveFolder()
in C:\Users\David\Documents\Visual Studio
2022\Projects\AstroMain\globals.vb:line 6647
at
CCDApp2.ObsConsole.ChangeSession(String SName) in
C:\Users\David\Documents\Visual Studio
2022\Projects\AstroMain\ObsConsole.vb:line 2914
at
CCDApp2.ObsConsole.SelectSession(String SName) in
C:\Users\David\Documents\Visual Studio
2022\Projects\AstroMain\ObsConsole.vb:line 3056
at
CCDApp2.ObsConsole.btnSelectLastSession_Click(Object sender, EventArgs e) in
C:\Users\David\Documents\Visual Studio
2022\Projects\AstroMain\ObsConsole.vb:line 38028
Continuous ImprovementContinuous Improvement
Back to Top
Introduction
Apple Inc bought out DarkSky company a
couple of years ago, and indicated that DarkSky Site and API would become no
longer available at some point. The API has continued to function and provide
weather information for the Clair Observatory, but an announcement from Apple on
2022-06-13 stated that from March 31st, 2023 the Dark Sky API will no longer be
available and encouraged users to migrate to WeatherKit, a new Apple API
available on iOS, iPadOS, macOS, tvOS, and web will that provide access to the
new Apple Weather forecast data. DarkSky was free for up to 1000 API calls
per day. AppleKit is free for up to 500,000 calls/month with membership of
Apple Developer Program.
Details about WeatherKit can be found at
https://developer.apple.com/weatherkit/.
and at
https://betterprogramming.pub/wwdc22-get-started-with-weatherkit-202794853c01
Proposal
The new WeatherKit API should be
investigated and if suitable its use should be built into AstroWeather.
The key components of the program
- Join Apple Developer Program
-
Creating and signed a Developer Token for accessing WeatherKit
- Create
a working REST API request (with authentication header) that pulls weather
data from WeatherKit
Apple Developer Program
Membership of Apple
Developer Program requires AppleID with 2-factor authentication turned-on in
order to enroll. Membership of AppleKit allows up to 500,000
calls/month free during & after program development
Enable WeatherKit on App ID
In Certificates,
Identifiers & Profiles, click Identifiers in the sidebar.
Note : Remember to also enable WeatherKit in the App Capabilities
tab when editing your App ID.
Rest API
DarkSky :
https://api.darksky.net/forecast/{secretkey}/{latitude},{longitude}?units=uk2
WeatherKit
: GET
https://weatherkit.apple.com/api/v1/weather/{language}/{latitude}/{longitude}:
The header of every WeatherKit REST API request requires a signed
developer token to identify the authorized ADP member and application or
service making the request. WeatherKit only supports developer tokens
signed with the ES256 algorithm,
Decoded Token looks like:
{
"alg": "ES256",
"kid": "ABC123DEFG",
"id":
"DEF123GHIJ.com.example.weatherkit-client"
}
{
"iss": "DEF123GHIJ",
"iat": 1437179036,
"exp": 1493298100,
"sub":
"com.example.weatherkit-client"
}
Request authentication for
WeatherKit REST API :
Create Token :
https://developer.apple.com/documentation/weatherkitrestapi/request_authentication_for_weatherkit_rest_api
https://jwt.io/
Pass the developer token as a parameter to the Authorization: Bearer
header in each request. Here's an example of a request:
curl -v -H
'Authorization: Bearer [developer token]'
"https://weatherkit.apple.com/api/v1/availability/{latitude}/{longitude}?country=US"
Looking at VB.Net code examples suggest the following style of
coding could be used:
Dim myReq
As HttpWebRequest
Dim myResp
As HttpWebResponse
myReq = HttpWebRequest.Create("https://meineURI.net")
myReq.Method =
"POST"
myReq.ContentType =
"application/json"
myReq.Headers.add("Authorization",
"Basic " & Convert.ToBase64String(Encoding.UTF8.GetBytes("username:password")))
Dim myData
As
String =
"yourDataHere"
myReq.GetRequestStream.Write(System.Text.Encoding.UTF8.GetBytes(myData),
0, System.Text.Encoding.UTF8.GetBytes(myData).Count)
myResp = myReq.GetResponse
Dim myreader
As
New System.IO.StreamReader(myResp.GetResponseStream)
Dim myText
As
String
myText = myreader.ReadToEnd
result will be a HttpResponseMessage, and result.Content.ReadAsStringAsync should give you back the JSON data as a string.
Epoch Convertor for getting iat, exp
https://www.epochconverter.com/
Step 1 :
Add 2-factor authentication to existing Apple Account
Step 2 :
Enroll in Apple Developer Program (annoying to find it cost £79/year to
enroll as individual)
Step 3 :
Record Team Name and Team ID
Step 4:
Create Key (WeatherKit), Create Service ID,
Step 5:
Create
JWT Developer Token ' see C:\Data\Computer\Apple
Developer\WeatherKit\JWT_Token_2022-07-19.txt
Step 6:
CreateTWeatherKit class and WeatherKit object in AstroWeather, based on
DarkSky class & object
Step 7:
Modify .BuildRequest for WeatherKit Rest API
Step
8:
Modify .SendRequest to pass the JWT developer token as a parameter to the Authorization:
Bearer
header
for request
Step 9:
Create btnWeatherKitForecast button and GetWeatherKitForecast() routine
Step 10a:
Test GetWeatherKitForecast(). Failing with exception on line
myReq.GetRequestStream() :
"The request was aborted: Could not create SSL/TLS secure channel."
Step
10b:
Add additional code line ServicePointManager.SecurityProtocol = 3072
Step 10c:
Retest GetWeatherKitForecast(). Failing with exception : but VS
provided no details about the exception
Step 10d:
Retest GetWeatherKitForecast(). Failing with exception on line myResp
= myReq.GetResponse
"The remote server returned an error: (403) Forbidden." (i.e. server
refuses to fulfill the request).
Step 10e:
Added additional code lines
Dim postData As String =
""
Dim byteArray As Byte() =
Encoding.UTF8.GetBytes(postData)
myReq.ContentLength =
byteArray.Length
dataStream = myReq.GetRequestStream()
dataStream.Write(byteArray, 0, byteArray.Length)
Step 10f:
Retest GetWeatherKitForecast(). Failing with exception on line myResp
= myReq.GetResponse
"The remote server returned an error: (403) Forbidden." (i.e. server
refuses to fulfill the request).
Step 10g Changed
code to use
Dim MyWebClient As New WebClient
MyWebClient.Headers.Add("Authorization", token)
' also tried with "Authorization: Bearer", token and with
"Authorization", "Bearer " + token
MyWebClient.DownloadFile(Request, JSON_File)
Update 2023-06-01
After investigation and review it was decided
not to pursue the WeatherKit API option due to i) difficult &
inadequate support/help, ii) cost of annual developer program fee, iii)
doesn't replace some useful attributes that were in DarkSky Api, iv) another
(free) option, OpenWeather API is available which supports equivalent
functionality (though still not as good as DarkSky API).
Back to Top
This Web Page: | Notes - Session 1021A (2022-07-07) |
Last Updated : | 2024-09-25 |
Site Owner : | David Richards |
Home Page : | David's Astronomy Web Site |