Recent

Author Topic: How to get a JSON file from weather forecast website (Raspbian)?  (Read 7226 times)

washburn_it

  • New Member
  • *
  • Posts: 15
Hi,

I'm new with Lazarus under Raspbian (raspberry pi), I usually use Turbo Delphi under Windows.
I'm trying to port a windows program (written with Lazarus for Windows) to a raspberry pi.
This program simply receives a JSON file from a weather forecast website.
Under Windows I use the unit "WinInet" but which is the equivalent unit under Raspbian?
Should I download some package?
Thank you, best regards.

Roberto

Leledumbo

  • Hero Member
  • *****
  • Posts: 8111
  • Programming + Glam Metal + Tae Kwon Do = Me

washburn_it

  • New Member
  • *
  • Posts: 15
Re: How to get a JSON file from weather forecast website (Raspbian)?
« Reply #2 on: March 11, 2015, 09:13:21 am »
I will try "TFPCustomHTTPClient.SimpleGet..." in the evening (it works with Windows 7).
Thanks !
Regards,

Roberto

Leledumbo

  • Hero Member
  • *****
  • Posts: 8111
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: How to get a JSON file from weather forecast website (Raspbian)?
« Reply #3 on: March 11, 2015, 10:42:39 am »
I will try "TFPCustomHTTPClient.SimpleGet..." in the evening (it works with Windows 7).
Thanks !
Regards,

Roberto
Use TFPHTTPClient please, TFPCustomHTTPClient is meant to be extended, as are many classes in RTL/FCL/LCL.

washburn_it

  • New Member
  • *
  • Posts: 15
Re: How to get a JSON file from weather forecast website (Raspbian)?
« Reply #4 on: March 11, 2015, 10:49:34 am »
Ok, thanks.
Regards,


Roberto

washburn_it

  • New Member
  • *
  • Posts: 15
Re: How to get a JSON file from weather forecast website (Raspbian)?
« Reply #5 on: March 11, 2015, 07:59:00 pm »
I tried the code on the Raspberry but I'm getting this errors:("url" and "str" are two strings containing the web address where to get the JSON data and "str" contains the name of the text file where the JSON data are saved)

with
Code: [Select]
TFPHTTPClient.SimpleGet(url, str) I get "identifier idents no member SimpleGet"

then I corrected with:

Code: [Select]
TFPHTTPClient.Get(url, str) but I get "Only class class methods, class properties and class variables can be accessed in class methods"

Where's the mistake?  :o

Roberto

Leledumbo

  • Hero Member
  • *****
  • Posts: 8111
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: How to get a JSON file from weather forecast website (Raspbian)?
« Reply #6 on: March 12, 2015, 01:13:19 am »
I tried the code on the Raspberry but I'm getting this errors:("url" and "str" are two strings containing the web address where to get the JSON data and "str" contains the name of the text file where the JSON data are saved)

with
Code: [Select]
TFPHTTPClient.SimpleGet(url, str) I get "identifier idents no member SimpleGet"
Learn to read thoroughly: "If you want to write even less lines of code, in FPC 2.7.1 you can use the class method:"
Obviously your version is lower.
then I corrected with:

Code: [Select]
TFPHTTPClient.Get(url, str) but I get "Only class class methods, class properties and class variables can be accessed in class methods"

Where's the mistake?  :o
Where do you declare url and str? Your call to Get is still wrong as Get is an instance method, not class method. Refer to the example in the wiki.

washburn_it

  • New Member
  • *
  • Posts: 15
Re: How to get a JSON file from weather forecast website (Raspbian)?
« Reply #7 on: March 12, 2015, 09:01:26 am »
Thanks for the reply...I will check the release of the installed FPC and in case I will update it.
In any way I fixed the "TFPHTTPClient" by declaring a variable of TFPHTTPClient type (HTTPClient:= TFPFHTTPClient.Create(nil)) and then calling "HTTPClient.Get(.....)".
It worked.
Now the problem is another: since I have to parse the JSON file, I found a piece of code that used the function "GetJSON" (unit fpjson) that worked under Windows but is not present in the same unit for RaspBian  :o
Maybe is it again a problem of the installed version of FPC ?

Regards,

Roberto


avra

  • Hero Member
  • *****
  • Posts: 1712
    • Additional info
Re: How to get a JSON file from weather forecast website (Raspbian)?
« Reply #8 on: March 12, 2015, 09:35:33 am »
I found a piece of code that used the function "GetJSON" (unit fpjson) that worked under Windows but is not present in the same unit for RaspBian
As a quick and dirty workaround you could try to copy pc fpc fpjson unit to your project dir and see if it can compile without errors. It has little dependencies so maybe you can get away with this. Otherwise try to install some newer FPC/LAZ which contains it.
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

washburn_it

  • New Member
  • *
  • Posts: 15
Re: How to get a JSON file from weather forecast website (Raspbian)?
« Reply #9 on: March 14, 2015, 07:27:12 pm »
I tried that solution but it didn't work.
Anyway...the current installed version of Lazarus is 0.9.30.4 and fpc version is 2.6.0 (in Windows I have 1.2.6 for Lazarus and 2.6.4 for FPC).
How could I upgrade those versions?
I found some suggestion but they didn't work.
Thank you, regards.

Roberto

Leledumbo

  • Hero Member
  • *****
  • Posts: 8111
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: How to get a JSON file from weather forecast website (Raspbian)?
« Reply #10 on: March 14, 2015, 07:37:17 pm »
How could I upgrade those versions?
As how you upgrade things in debian desktop (sudo apt-get update && sudo apt-get upgrade). AFAIK raspbian has 2.6.4 with ARMHF patch backported in their repo so you should be able to use that.

washburn_it

  • New Member
  • *
  • Posts: 15
Re: How to get a JSON file from weather forecast website (Raspbian)?
« Reply #11 on: March 15, 2015, 12:46:39 pm »
I tried with the usual "apt-get update and upgrade" but the versions remained the same.
I also followed the tutorial at http://otapi.com/2015/02/10/raspberry-pi-2-freepascal-lazarus-and-delphi/ but ended up with an error that I'm not able to fix while compiling Lazarus.
So...I'm stuck !
What else could I try?

avra

  • Hero Member
  • *****
  • Posts: 1712
    • Additional info
Re: How to get a JSON file from weather forecast website (Raspbian)?
« Reply #12 on: March 16, 2015, 09:45:44 am »
the current installed version of Lazarus is 0.9.30.4 and fpc version is 2.6.0 (in Windows I have 1.2.6 for Lazarus and 2.6.4 for FPC). How could I upgrade those versions?

Not 1.2.6 but certainly better then 0.9.30.4:
http://forum.lazarus.freepascal.org/index.php/topic,23248.msg138609.html#msg138609
http://forum.lazarus.freepascal.org/index.php/topic,22610.msg133708.html#msg133708
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib