Recent

Author Topic: I need some pointers (querying OpenWeatherMap API)  (Read 1445 times)

Christian Becker

  • Newbie
  • Posts: 4
I need some pointers (querying OpenWeatherMap API)
« 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.

MarkMLl

  • Hero Member
  • *****
  • Posts: 1470
Re: I need some pointers (querying OpenWeatherMap API)
« Reply #1 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
Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.

simone

  • Sr. Member
  • ****
  • Posts: 361
Re: I need some pointers (querying OpenWeatherMap API)
« Reply #2 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.

« Last Edit: January 15, 2020, 08:41:29 pm by simone »
Microsoft Windows 10 64 bit - Lazarus 2.0.10

MarkMLl

  • Hero Member
  • *****
  • Posts: 1470
Re: I need some pointers (querying OpenWeatherMap API)
« Reply #3 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
Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.

simone

  • Sr. Member
  • ****
  • Posts: 361
Re: I need some pointers (querying OpenWeatherMap API)
« Reply #4 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?
Microsoft Windows 10 64 bit - Lazarus 2.0.10

john horst

  • Jr. Member
  • **
  • Posts: 66
    • JHorst
Re: I need some pointers (querying OpenWeatherMap API)
« Reply #5 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.

Christian Becker

  • Newbie
  • Posts: 4
Re: I need some pointers (querying OpenWeatherMap API)
« Reply #6 on: January 16, 2020, 01:14:26 pm »
Thanks so far. :D
Will get back to trying things this weekend.

Christian Becker

  • Newbie
  • Posts: 4
Re: I need some pointers (querying OpenWeatherMap API)
« Reply #7 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


Christian Becker

  • Newbie
  • Posts: 4
Re: I need some pointers (querying OpenWeatherMap API)
« Reply #8 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

lainz

  • Hero Member
  • *****
  • Posts: 3809
  • Leandro Diaz
Re: I need some pointers (querying OpenWeatherMap API)
« Reply #9 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
« Last Edit: January 23, 2020, 12:52:38 am by lainz »
https://lainz.github.io/
Download LazPaint https://lazpaint.github.io/
Download BGRABitmap and BGRAControls https://github.com/bgrabitmap

Thaddy

  • Hero Member
  • *****
  • Posts: 10605
Re: I need some pointers (querying OpenWeatherMap API)
« Reply #10 on: January 23, 2020, 09:20:11 am »
3.2.0 will suffice: it is back-ported.

 

TinyPortal © 2005-2018