Lazarus

Free Pascal => Beginners => Topic started by: Christian Becker on January 15, 2020, 07:56:16 pm

Title: [SOLVED]I need some pointers (querying OpenWeatherMap API)
Post by: Christian Becker on January 15, 2020, 07:56:16 pm
Hi there,

first of all, I'm new here.  :)

I want to write a (very) simple weather applet that queries OpenWeatherMap (I have an API key), outputs (some of) the data in a pleasing way and does nothing more.
The problem is, I don't really know how to do it and trying to get into it on my own wasn't successful so far.

I'm running Lazarus 2.0.2 with FPC 3.0.4 on Gentoo Linux.

I found a guide to querying APIs on the net (https://lazplanet.blogspot.com/2019/03/basic-rest-api-implementation.html - https://lazplanet.blogspot.com/2019/03/how-to-get-contents-of-url-in-2-ways.html), but it won't run. (Project proj_rest_api_tutorial raised exception class 'External: SIGSEGV'. At address 5FB555)

When I searched that error on the net I stumbled upon these two threads:
https://forum.lazarus.freepascal.org/index.php/topic,47432.msg339571.html#msg339571
https://forum.lazarus.freepascal.org/index.php/topic,46636.msg332814.html#msg332814

From that it seems that I won't be able to do anything before I install FPC 3.2 - but I'm not quite sure if the problem described in those threads is the same one I'm having.

So, any help, hints, pointers to tutorials would be appreciated.
Title: Re: I need some pointers (querying OpenWeatherMap API)
Post by: MarkMLl on January 15, 2020, 08:17:41 pm
What does the Lazarus debugger tell you about that exception?

I can't comment on the SSL side of things, but a lot really depends on what exactly you're trying to do. The only thing that I've done in this area was "old school" collection of synopsis etc. using Perl, massaging projection appropriately and overlaying onto Google Earth (which is still a fairly competent GIS, even if Google doesn't want people to know that).

MarkMLl
Title: Re: I need some pointers (querying OpenWeatherMap API)
Post by: simone on January 15, 2020, 08:39:56 pm
I read in the past this tutorial, so I tried again to compile and run the example under Windows using Lazarus 2.0.6+FPC 3.0.4, without encountering problems. In the zip file with the demo project, along with sources, are present libeay32.dll and ssleay32.dll, that are dynamic library for Windows, so they cannot run on Linux directly.

Title: Re: I need some pointers (querying OpenWeatherMap API)
Post by: MarkMLl on January 15, 2020, 08:57:20 pm
I read in the past this tutorial, so I tried again to compile and run the example under Windows using Lazarus 2.0.6+FPC 3.0.4, without encountering problems. In the zip file with the demo project, along with sources, are present libeay32.dll and ssleay32.dll, that are dynamic library for Windows, so they cannot run on Linux directly.

Which suggests that it might be possible to get round the libssl version program on Linux (and possibly other unix variants) using the LD_PRELOAD hack.

MarkMLl
Title: Re: I need some pointers (querying OpenWeatherMap API)
Post by: simone on January 15, 2020, 10:59:34 pm
I'm running Lazarus 2.0.2 with FPC 3.0.4 on Gentoo Linux.

Is Openssl package installed on your system?
Title: Re: I need some pointers (querying OpenWeatherMap API)
Post by: john horst on January 16, 2020, 12:02:03 am
Code: Pascal  [Select][+][-]
  1. program openw;
  2.  
  3. uses
  4.   sysutils, opensslsockets, fphttpclient;
  5.  
  6. begin
  7.   with tfphttpclient.create(nil) do
  8.     begin
  9.       writeln(get('https://samples.openweathermap.org/data/2.5/weather?zip=94040,us&appid=b6907d289e10d714a6e88b30761fae22'));
  10.       free;
  11.     end;
  12. end.

works for me on ubuntu 19.04, fpc 3.2
john@oddio:~/source/code/pascal/openweather$ openssl version
OpenSSL 1.1.1b  26 Feb 2019

If you do have openssl installed, make sure its symlinked to what the unit wants considering you are using gentoo. Stuff like ssl1.1.1b""".o""" will fail.
Title: Re: I need some pointers (querying OpenWeatherMap API)
Post by: Christian Becker on January 16, 2020, 01:14:26 pm
Thanks so far. :D
Will get back to trying things this weekend.
Title: Re: I need some pointers (querying OpenWeatherMap API)
Post by: Christian Becker on January 18, 2020, 01:00:46 pm
Code: Pascal  [Select][+][-]
  1. program openw;
  2.  
  3. uses
  4.   sysutils, opensslsockets, fphttpclient;
  5.  
  6. begin
  7.   with tfphttpclient.create(nil) do
  8.     begin
  9.       writeln(get('https://samples.openweathermap.org/data/2.5/weather?zip=94040,us&appid=b6907d289e10d714a6e88b30761fae22'));
  10.       free;
  11.     end;
  12. end.

works for me on ubuntu 19.04, fpc 3.2
john@oddio:~/source/code/pascal/openweather$ openssl version
OpenSSL 1.1.1b  26 Feb 2019

If you do have openssl installed, make sure its symlinked to what the unit wants considering you are using gentoo. Stuff like ssl1.1.1b""".o""" will fail.
This does not work for me.
"project1.lpr(4,13) Fatal: Can't find unit opensslsockets used by openw"
This seems to be because opensslsockets was not used previously to fpc320 and I have 3.0.4

Replacing opensslsockets with plain openssl raises an exception:
Exception class ESSL with message:
Failed to create SSL context
At address 4AA895

Title: Re: I need some pointers (querying OpenWeatherMap API)
Post by: Christian Becker on January 22, 2020, 03:55:43 pm
I'm running Lazarus 2.0.2 with FPC 3.0.4 on Gentoo Linux.

Is Openssl package installed on your system?
Oh, yes, sure.
OpenSSL 1.1.1d  10 Sep 2019
Title: Re: I need some pointers (querying OpenWeatherMap API)
Post by: lainz on January 23, 2020, 12:18:03 am
You need to install FPC trunk to use latest version of OpenSSL.

Edit: or try installing package openssl-dev
Title: Re: I need some pointers (querying OpenWeatherMap API)
Post by: Thaddy on January 23, 2020, 09:20:11 am
3.2.0 will suffice: it is back-ported.
Title: Re: I need some pointers (querying OpenWeatherMap API)
Post by: Christian Becker on January 05, 2021, 03:53:30 pm
Hello again,
I finally came back to Lazarus after getting fpc 3.20 on my Gentoo installation, which took some effort because it's not in the official repositories. :)

Works well so far.
TinyPortal © 2005-2018