RISC OS Open
A fast and easily customised operating system for ARM devices
ROOL
Home | News | Downloads | Bugs | Bounties | Forum | Documents | Photos | Contact us
Account
Forums → Community Support →

URL_Fetcher examples

Subscribe to URL_Fetcher examples 10 posts, 4 voices

 
Mar 31, 2019 12:20pm
Avatar Jon Abbott (1421) 2131 posts

Are there any examples on how to use the URL_Fetcher Module?

It only ever seems to return a status of 0 – which isn’t valid, so I must be doing it wrong. eg.

DIM data% 16
!data%=0
SYS "URL_Register" TO ,S%
SYS "URL_GetURL", 0, S%, 1, "http://a.valid.www/url", data%, 2, 0 TO status%
WHILE (status% AND %1111111)=0
  SYS "URL_Status", 0, S% TO status%
ENDWHILE

EDIT: Example code to download a file

ON ERROR REPORT:PRINT " line ";ERL:SYS "URL_Deregister", 0, S%:END

*RMEnsure URL_Fetcher 0.58 RMLoad System:Modules.Network.URL.URL
*RMEnsure AcornHTTP 1.01 RMLoad System:Modules.Network.URL.AcornHTTP
*RMEnsure AcornSSL 1.05 RMLoad System:Modules.Network.URL.AcornSSL

URL$="https://a.valid.www/url"
FILE$="$.downloaded.file"

buffer_size%=8*1024
DIM data% 1024, buffer% buffer_size%

PROCdownload(URL$, FILE$)
END


DEF PROCdownload(URL$, FILE$)
  LOCAL A%
  SYS "URL_Register", 0 TO ,S%
  !data%=0
  SYS "URL_GetURL", %00, S%, 1, URL$+CHR$0, data%, 2, 0 TO A%
  
  PROCread_header
  PROCread_contents(FILE$)
  
  SYS "URL_Deregister", 0, S%
ENDPROC


DEF PROCread_header
  LOCAL response%

  response%=FNread_data(0)
ENDPROC


DEF PROCread_contents(F$)
  LOCAL F%, response%

  SYS "OS_Find", &83, F$ TO F%
  REPEAT UNTIL (FNread_data(F%) AND (%11<<5))>0
  SYS "OS_Find", 0, F%
ENDPROC


DEF FNread_data(F%)
  LOCAL now%, A%, C%, L%

  now%=TIME
  REPEAT
    SYS "URL_ReadData", 0, S%, buffer%, buffer_size% TO A%,,,,C%,L%
    IF TIME>now%+100 THEN now%=TIME:PRINT "Waiting for response ";L%;" bytes remaining"
    IF (A% AND (1<<4))>0 AND C%>0 THEN
      PRINT "Received data ("+STR$ C%+" bytes)"
      IF F%<>0 THEN SYS "OS_GBPB", 2, F%, buffer%, C%
    ENDIF
    IF C%=0 THEN REPEAT:WAIT:UNTIL TIME>now%+20
  UNTIL C%>0 OR L%=0
=A%
 
Mar 31, 2019 11:30pm
Avatar Chris Mahoney (1684) 1687 posts

You need to call URL_ReadData before it’ll actually return anything. URL_GetURL only starts off the process.

 
Apr 1, 2019 2:00pm
Avatar Jon Abbott (1421) 2131 posts

You need to call URL_ReadData

I’m doing that, but as stated above it only returns zero, which is why I’m after a code example.

From the documentation, my snippet above looks correct in that it should eventually return a status to say it’s connected. Once connection is established, you then read the data via URL_ReadData.

 
Apr 1, 2019 10:38pm
Avatar Chris Mahoney (1684) 1687 posts

I haven’t tried using the module from BASIC. I’m happy to share the C source to HTTPLib if you like, although it’s not exactly a simple example :)

 
Apr 2, 2019 4:49am
Avatar Jon Abbott (1421) 2131 posts

I’m happy to share the C source to HTTPLib

Yes please, as you’re doing exactly what I’m trying to do but in BASIC.

 
Apr 2, 2019 6:09am
Avatar Chris Mahoney (1684) 1687 posts

I’ve put the source on my site, under HTTPLib.

 
Apr 6, 2019 9:02am
Avatar Jon Abbott (1421) 2131 posts

I’ve put the source here.

Thanks. Shame that isn’t in a Module so it can be used from BASIC as you’ve already coded exactly what I’m trying to code.

Turns out I was doing it correctly, but URL_GetURL doesn’t appear to actually do anything, so calling URL_Status after it and waiting for connection confirmation was never going to work.

 
Feb 22, 2021 10:16am
Avatar Bryan (8467) 214 posts

Has anybody got any examples of code written in BASIC

 
Feb 23, 2021 7:20am
Avatar Jon Abbott (1421) 2131 posts

I’ve put my example code in the OP. I’m not sure why Textile has completely knackered the formatting, I’ll sort it out later.

 
2 days ago
Avatar DavidS (1854) 2055 posts

… I’m not sure why Textile has completely knackered the formatting, I’ll sort it out later.

You have to have a blank line before the pre tag at the beginning and after the slash pre tag at the end. Otherwise it will muck it up in the way it is.

Reply

To post replies, please first log in.

Forums → Community Support →

Search forums

Social

Follow us on and

ROOL Store

Buy RISC OS Open merchandise here, including SD cards for Raspberry Pi and more.

Donate! Why?

Help ROOL make things happen – please consider donating!

RISC OS IPR

RISC OS is an Open Source operating system owned by RISC OS Developments Ltd and licensed primarily under the Apache 2.0 license.

Description

Community-provided support for all users of RISC OS.

Voices

  • Jon Abbott (1421)
  • Chris Mahoney (1684)
  • Bryan (8467)
  • DavidS (1854)

Options

  • Forums
  • Login
Site design © RISC OS Open Limited 2018 except where indicated
The RISC OS Open Beast theme is based on Beast's default layout

Valid XHTML 1.0  |  Valid CSS

Powered by Beast © 2006 Josh Goebel and Rick Olson
This site runs on Rails

Hosted by Arachsys