Shop OBEX P1 Docs P2 Docs Learn Events
Code to access data on webpage — Parallax Forums

Code to access data on webpage

Rich-GTRich-GT Posts: 2
edited 2012-07-25 11:59 in Accessories
Hi I wonder if anyone can help me with what I am sure will just be a couple of lines of simple code.

I have a fairly big, for me, project using the propeller chip to control a digital slot car track. I have working lap counting & timing, VGA display, digital track drive & wireless throttles using the Nordic NRF24L01 chip. All that is working fine and I sort of understand what I am doing.

I have a one off need, and only a short time, to use the same project to access a web page to pick up Tweet information which will then be used to move the cars round the track. I am completely unfamiliar with web based stuff, hence this plea for help...

I want to use the Spinneret as I can hopefully use it to access the information and port all my existing code. I have got up and running Tim's "W5100 TCP Client Echo Demo, and can connect to the Simple.com tool. However I am at a complete loss as to what needs to be sent on a repetative basis to access the ascii string that will be updated with Tweet data.

This is the web address.
http://trademover.net/poweredbyrs/api/main.svc/GetLatest?getTime=true

I wonder if anyone could show me what to put where to access the information, using the Client Echo as a basis, or something else if that is more appropriate?


Many Thanks


Richard

Comments

  • Mike GMike G Posts: 2,702
    edited 2012-07-25 07:17
    Rich-GT, welcome to the forums. Down playing the difficulty of a task while asking for help on the same task is bit irritating. Many of the forum members took the time and worked hard to learn the concepts required to complete an HTTP request/response.

    You already have the couple of lines of simple code to complete the task. I imagine you're missing is the proper HTTP protocol to invoke the remote service.

    The remote host ip:port for trademover.net is 81.95.51.4:80. Use the remote IP and port in the Spinneret initialization.

    Below is the request header used to invoke the getTime service on the trademover.net domain.
    GET /poweredbyrs/api/main.svc/GetLatest?getTime=true HTTP/1.1
    Host: trademover.net
    User-Agent: Spinneret
    Connection: keep-alive
    

    Here is the response header and message body. The message body - the part you are looking for - is one line below the header.
    HTTP/1.1 200 OK
    Cache-Control: private
    Content-Length: 26
    Content-Type: application/json; charset=utf-8
    Server: Microsoft-IIS/7.5
    X-AspNet-Version: 4.0.30319
    X-Powered-By: ASP.NET
    Date: Wed, 25 Jul 2012 13:51:36 GMT
    
    {"d":"33,0,14:51:37.2173"}
    

    As suggested in the response to your PM, the following tutorial briefly explains - with source code - how to invoke a remote HTTP GET.
    http://spinneret.servebeer.com:5000/client/sget.htm
  • Rich-GTRich-GT Posts: 2
    edited 2012-07-25 08:30
    Hi Mike. Thanks for the welcome & your patience. I can assure you that my mention of a "few lines of code" was in no way intended to trivialise the tremendous amount of work you and others have put into supporting the Propeller & Spinneret, more so a comment on my inability to come up with the few additional lines needed on top of the code you have created.

    I can see from the code and response that you are able to access the data I need, so I will now go and try to work out where to use the Get command, to Get the same response.

    As I don't want to start from scratch could you comment on using the TCP Client Echo Demo as a starting point, or is there a better Demo to use?


    Thanks again


    Richard
  • Mike GMike G Posts: 2,702
    edited 2012-07-25 11:59
    In the TCP Clinet Echo Demo, replace the data sent with an HTTP GET.
    GET /poweredbyrs/api/main.svc/GetLatest?getTime=true HTTP/1.1
    Host: trademover.net
    User-Agent: Spinneret
    Connection: keep-alive
    

    Update the remote host IP and remote port using the following values.
    81.95.51.4
    80
    

    Make sure the local port number is large, 5000 is good

    The Spinneret must have access to the Internet which means a router. There may be router configuration required.

    Execute the request.
Sign In or Register to comment.