Cruisers Forum
 


Join CruisersForum Today

Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
Old 06-08-2018, 06:27   #1
Registered User

Join Date: May 2012
Posts: 593
UKTidalEvents Plugin

UKHO has published an open API that enables developers to retrieve HW/LW times for 600 tidal stations around the UK.

https://www.admiralty.co.uk/digital-...s/uk-tidal-api

I have been able to download all the GeoJSON files via MS Internet Explorer but Firefox shows errors for the tidal events and stations download.

Using 'OCPN_downloadFile' from the OpenCPN API caused the downloads to fail. Does the function work with an 'https' url? Can the appropriate headers be sent? When Curl (with SSL enabled) was used it was necessary to treat the URL as insecure.

I would like to keep all the code within the plugin. If necessary the Curl program could be included, but then Windows only. Trying to avoid libCurl to keep things simple.

If anyone can point me to a solution for using 'OCPN_downloadFile' with the UKHO API it would be much appreciated.

Mike
__________________

Rasbats is offline   Reply With Quote
Old 06-08-2018, 06:59   #2
Marine Service Provider
 
bdbcat's Avatar

Join Date: Mar 2008
Posts: 5,501
Re: UKTidalEvents Plugin

Mike...

Show us some code snippets, and results.

Dave
__________________

bdbcat is online now   Reply With Quote
Old 06-08-2018, 07:13   #3
Registered User

Join Date: Jun 2015
Posts: 330
Re: UKTidalEvents Plugin

Quote:
Originally Posted by Rasbats View Post
UKHO has published an open API that enables developers to retrieve HW/LW times for 600 tidal stations around the UK.

https://www.admiralty.co.uk/digital-...s/uk-tidal-api

Using 'OCPN_downloadFile' from the OpenCPN API caused the downloads to fail. Does the function work with an 'https' url? Can the appropriate headers be sent? When Curl (with SSL enabled) was used it was necessary to treat the URL as insecure.

Mike

It does https but some servers may not always work with curl linked against gnutls, which curl version or opencpn are you using?


For testing mitmproxy can help a lot.


Didier
did-g is offline   Reply With Quote
Old 06-08-2018, 11:41   #4
Registered User

Join Date: May 2012
Posts: 593
Re: UKTidalEvents Plugin

Quote:
Originally Posted by did-g View Post
It does https but some servers may not always work with curl linked against gnutls, which curl version or opencpn are you using?
Curl binary with SSL came from here:
cURL groks URLs - CURL 7.61.0
OpenCPN at V 4.8.4, API 1.13


Quote:
Show us some code snippets, and results.
================================================
wxString s = _T("/");
wxString defaultDir = *GetpSharedDataLocation() + _T("plugins")
+ s + _T("uktidalevents_pi") + s + _T("data") + s;

wxString stations = _T("json.txt");

wxString fn = defaultDir + stations;
wxFile f(fn);

wxString urlString = _T("https://admiraltyapi.azure-api.net/uktidalapi/api/V1/Stations/0014/TidalEvents?key=80d84068452d4f58ad1b9dcf9cacf18c") ;
wxURI url(urlString);

_OCPN_DLStatus ret = OCPN_downloadFile(url.BuildURI(), fn,
_T("UKTidalEvents"), _T("")
, wxNullBitmap, this,
OCPN_DLDS_ELAPSED_TIME | OCPN_DLDS_ESTIMATED_TIME | OCPN_DLDS_REMAINING_TIME | OCPN_DLDS_SPEED | OCPN_DLDS_SIZE | OCPN_DLDS_CAN_PAUSE | OCPN_DLDS_CAN_ABORT,
20);

if (ret == OCPN_DL_FAILED){
wxMessageBox(_("Download failed"));
wxRemoveFile(fn);
return;
}
else if (ret == OCPN_DL_NO_ERROR) {
wxMessageBox(_("Success"));
return;
}
================================================
The URL works with CTRL+Click in VS2013.

Thanks
Mike
Rasbats is offline   Reply With Quote
Old 06-08-2018, 16:16   #5
Marine Service Provider
 
bdbcat's Avatar

Join Date: Mar 2008
Posts: 5,501
Re: UKTidalEvents Plugin

Mike...

Code is clear enough.
Have you tried to trace the execution of the API call? Exactly why does it return "OCPN_DL_FAILED"?

Dave
bdbcat is online now   Reply With Quote
Old 07-08-2018, 04:39   #6
Registered User

Join Date: Jun 2015
Posts: 330
Re: UKTidalEvents Plugin

There's something with the server but I don't have time below one is working one is returning an error from the server.


Quote:


2018-08-07 10:45:29 GET https:// ...
<- 500 Internal Server Error text/html 3.34k 100ms
Request Response Detail
Server Connection:
Address admiraltyapi.azure-api.net:443
Resolved Address 51.141.89.70:443
HTTP Version HTTP/1.1
ALPN http/1.1
Server Certificate:
Type RSA, 2048 bits
SHA1 digest CB:33:E9:27:A7:6A:CB:77:C8:21:5A:AF:4F:98:A3:FF:78 :13:90:69
Valid to 2020-01-11 18:29:16
Valid from 2018-01-11 18:29:16
Serial 490616592448058144929574954273345938441409796
Subject CN *.azure-api.net
Issuer C US
ST Washington
L Redmond
O Microsoft Corporation
OU Microsoft IT
CN Microsoft IT TLS CA 4
Alt names *.azure-api.net, *.portal.azure-api.net, *.management.azure-api.net, *.scm.azure-api.net, *.configuration.azure-api.net,
*.regional.azure-api.net
Client Connection:
Address ::ffff:10.8.0.21:38555
HTTP Version HTTP/1.1
TLS Version TLSv1.2
Server Name Indication admiraltyapi.azure-api.net
Cipher Name ECDHE-RSA-AES128-GCM-SHA256
ALPN http/1.1
Timing:



Request:


Host: admiraltyapi.azure-api.net
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:61.0) Gecko/20100101 Firefox/61.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: fr,en-US;q=0.7,en;q=0.3
Accept-Encoding: gzip, deflate, br
DNT: 1
Connection: keep-alive
Upgrade-Insecure-Requests: 1
Cache-Control: max-age=0

Quote:

2018-08-07 10:56:23 GET https:// ...
<- 200 OK application/json 4.15k 337ms
Request Response Detail
Server Connection:
Address admiraltyapi.azure-api.net:443
Resolved Address 51.141.89.70:443
HTTP Version HTTP/1.1
Server Certificate:
Type RSA, 2048 bits
SHA1 digest CB:33:E9:27:A7:6A:CB:77:C8:21:5A:AF:4F:98:A3:FF:78 :13:90:69
Valid to 2020-01-11 18:29:16
Valid from 2018-01-11 18:29:16
Serial 490616592448058144929574954273345938441409796
Subject CN *.azure-api.net
Issuer C US
ST Washington
L Redmond
O Microsoft Corporation
OU Microsoft IT
CN Microsoft IT TLS CA 4
Alt names *.azure-api.net, *.portal.azure-api.net, *.management.azure-api.net, *.scm.azure-api.net, *.configuration.azure-api.net,
*.regional.azure-api.net
Client Connection:
Address ::ffff:10.8.0.21:38565
HTTP Version HTTP/1.1
TLS Version TLSv1.2
Server Name Indication admiraltyapi.azure-api.net
Cipher Name ECDHE-RSA-AES128-GCM-SHA256
Timing:
Client conn. established 2018-08-07 10:56:22.784
Client conn. TLS handshake 2018-08-07 10:56:23.049



Request
User-Agent: curl/7.35.0
Host: admiraltyapi.azure-api.net
Accept: */*
Accept-Encoding: deflate, gzip
Finding what trigger the server error shouldn't be too hard.
did-g is offline   Reply With Quote
Old 07-08-2018, 08:04   #7
Registered User

Join Date: May 2012
Posts: 593
Re: UKTidalEvents Plugin

Thanks Didier. This sort of stuff is beyond me.

This came back when using Curl + SSL without the -k option:

Quote:
C:\plugins\admiralty>curl -o "c:/plugins/admiralty/output.txt" -X GET "https:
//admiraltyapi.azure-api.net/uktidalapi/api/V1/Stations/0014/TidalEvents?duratio
n=1&key=80d84068452d4f58ad1b9dcf9cacf18c"
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
curl: (60) SSL certificate problem: unable to get local issuer certificate
More details here: https://curl.haxx.se/docs/sslcerts.html

curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.
Is there any way of forcing an insecure request?
Mike
Rasbats is offline   Reply With Quote
Old 07-08-2018, 23:01   #8
Registered User

Join Date: Jun 2015
Posts: 330
Re: UKTidalEvents Plugin

Quote:
Originally Posted by Rasbats View Post
Thanks Didier. This sort of stuff is beyond me.

This came back when using Curl + SSL without the -k option:

Is there any way of forcing an insecure request?
Mike
Yes there's, but is it a good idea? Updating certificates list is likely a better solution.

Anyway issue seems to be

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8



ie server doesn't like:


wget -v --debug --header='Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' ...

which BTW is a sample coming from https://developer.mozilla.org/en-US/...Headers/Accept


it's set in src/wxcurl/base.cp, IMO should be 'Accept: */*'
did-g is offline   Reply With Quote
Old 08-08-2018, 06:34   #9
Marine Service Provider
 
bdbcat's Avatar

Join Date: Mar 2008
Posts: 5,501
Re: UKTidalEvents Plugin

Mike...

I had some trouble with this also in ofc_pi. Not the same, but similar.

Ended up deriving a class from curl, so that I had finer control. Take a look at ofc_pi source:
https://github.com/bdbcat/ofc_pi


Look in ofcShop.cpp:

class wxCurlHTTPNoZIP : public wxCurlHTTP

Dave
bdbcat is online now   Reply With Quote
Old 09-08-2018, 05:28   #10
Registered User
 
rgleason's Avatar

Join Date: Mar 2012
Location: Boston, MA
Boat: 1981 Bristol 32 Sloop
Posts: 12,346
Re: UKTidalEvents Plugin

Mike, I am curious, would this data be able to populate the Admiralty Tides pi which requires manual input at this point? --On the other hand, perhaps you have something else in mind like OTcurrent?
rgleason is offline   Reply With Quote
Old 09-08-2018, 13:00   #11
Registered User

Join Date: May 2012
Posts: 593
Re: UKTidalEvents Plugin

Rick ...

Admiralty Tides pi requires hard copy UKHO tide tables. Everything off-line. Predictions only limited by the annual edition of the tide tables.

UKTidalEvents - if I can crack the server problem - works on-line. Predicts HW/LW for up to seven days in the future. No tidal current predictions from the API. It is the number of tidal stations that can be accessed easily that is the main attraction.

Mike
Rasbats is offline   Reply With Quote
Old 10-08-2018, 12:50   #12
Registered User

Join Date: May 2012
Posts: 593
Re: UKTidalEvents Plugin

Thanks for the help, but it is not worth spending any more time on this at the moment.

The same data is available online e.g.:
https://www.tidetimes.org.uk/cotehele-quay-tide-times

Mike
Rasbats is offline   Reply With Quote
Old 20-03-2019, 08:34   #13
Registered User
 
OlleH's Avatar

Join Date: Dec 2015
Location: Bredared, SWEDEN
Boat: Fantasi 37
Posts: 11
Re: UKTidalEvents Plugin

Hi, is it possible to save the file downloaded for UK Tides plugin? If I am crossing the North Sea from Norway I will download Tides for 7 days and I might not want all waypoints active for three days during passage. Only choise I see as it is today is to turn of wapoints and rutes, but I still want my rutes visible on such a trip.
__________________
OlleH
OlleH is offline   Reply With Quote
Old 20-03-2019, 12:14   #14
Registered User

Join Date: May 2012
Posts: 593
Re: UKTidalEvents Plugin

Sorry, the tidal station waypoints are only active when you have an Internet connection. In the middle of the North Sea they will not be needed. They will not be there when OpenCPN is re-opened and the plugin has not been started.

UK Hydrographic Office does not allow the data to be saved by the plugin. Nothing would stop the user taking a screenshot of a set of tide predictions for future reference.

Mike

p.s. Thanks, I found a bug. If you leave the predictions screen open and close OpenCPN you will get a crash. Easy to fix!
Attached Thumbnails
Click image for larger version

Name:	ukTides.png
Views:	29
Size:	47.7 KB
ID:	188393  
Rasbats is offline   Reply With Quote
Old 20-03-2019, 12:25   #15
Registered User
 
OlleH's Avatar

Join Date: Dec 2015
Location: Bredared, SWEDEN
Boat: Fantasi 37
Posts: 11
Re: UKTidalEvents Plugin

Thanks for your answer Rasbats. The reason was not to use it on the North sea. It was to have it avaliable when arriving coast of Scottland. Is it possible to make a funktion to save a pdf-file instead of a screen shot?
/Olleh
__________________

__________________
OlleH
OlleH is offline   Reply With Quote
Reply

Tags
events, plug

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
OpenCPN PlugIn Development bdbcat OpenCPN 157 12-02-2019 18:12
BSB 4 PlugIn bdbcat OpenCPN 98 25-04-2018 18:46
Plugin development... How to receive chart objects in my plugin? dmartinez OpenCPN 6 04-08-2017 00:56
Plugin: DashBoard SethDart OpenCPN 470 24-08-2016 20:34
Writing Plugin for nv.digital Map Format ? Netsurfer OpenCPN 7 17-08-2010 16:09



Copyright 2002- Social Knowledge, LLC All Rights Reserved.

All times are GMT -7. The time now is 18:55.


Google+
Powered by vBulletin® Version 3.8.8 Beta 1
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Social Knowledge Networks
Powered by vBulletin® Version 3.8.8 Beta 1
Copyright ©2000 - 2019, vBulletin Solutions, Inc.

ShowCase vBulletin Plugins by Drive Thru Online, Inc.