GetHTTPData in Wiser

Discussion in 'C-Bus Wiser 1 Controller' started by ssaunders, Sep 1, 2012.

  1. ssaunders

    ssaunders

    Joined:
    Dec 17, 2008
    Messages:
    232
    Likes Received:
    31
    Location:
    Melbourne
    Hi guys.

    I'm wanting to use the GetHTTPData and related commands in a Wiser project, but it's not supported for the platform - only the C-Touch Colour.

    Other TCP/IP network functions (like SendEMail) are available, so just wondering why the HTTP-based functions are not. Slated for sometime, or never?

    Thanks in advance,
    Steve.
     
    ssaunders, Sep 1, 2012
    #1
  2. ssaunders

    Roosta

    Joined:
    Nov 22, 2011
    Messages:
    560
    Likes Received:
    1
    Location:
    Australia
    New piced firmware supports this now for wiser..

    Wiser Firmware History
    Version 1.30.0
    Improve string handling memory utilization for ReadClientSocket
    Implement support for PostHTTPData, ReadHTTPPostData, GetHTTPData, and ReadHTTPData in Logic
    Improve robustness of port forwarding when handling CTCs behind Wiser
    24738 - tag database error if Schedule with Scene is edited on Wiser using Adobe Flash UI and then project is retrieved from unit
    Fix bug that was limiting number of client sockets to 3 rather than 4
    Fix bug that was limiting WriteClientSocket and WriteServerSocket to 30 byte strings

    Cheers..
     
    Roosta, May 30, 2013
    #2
  3. ssaunders

    ssaunders

    Joined:
    Dec 17, 2008
    Messages:
    232
    Likes Received:
    31
    Location:
    Melbourne
    You little bloody ripper! :) Thanks for posting, Roosta.
     
    ssaunders, May 31, 2013
    #3
  4. ssaunders

    Roosta

    Joined:
    Nov 22, 2011
    Messages:
    560
    Likes Received:
    1
    Location:
    Australia
    Hey..

    Did you manage to get this to work in the wiser? I have been trying to utilise the HTTP functions but no joy!!!

    Cheers..
     
    Roosta, Jun 21, 2013
    #4
  5. ssaunders

    kjayakumar

    Joined:
    Oct 27, 2008
    Messages:
    448
    Likes Received:
    0
    What are you seeing? Any errors? Wireshark the connection if possible as that would help reveal what's happening.

    Here's are the examples I have which do http get from a web page and then parse a string out of it to display in a system io, the other does a http post and then the same. These work fine on my unit. I hope it helps:
    GetHTTPData('http://192.168.100.246/index.html');
    // wait for data to come back
    delay(5);
    // read the data into a string
    ReadHTTPData(DataString);
    if DataString <> '' then
    begin
    // Find where the data starts and ends
    DataStart := pos('forecast is', DataString) + 12;
    DataEnd := pos('</body>', DataString);
    // extract the data into the string ForecastString
    Copy(TheFirstNameString, DataString, DataStart, DataEnd - DataStart);
    SetStringSystemIO("showsomething", DataString);
    end;

    PostHTTPData('http://192.168.100.246/cgi-bin/hello.cgi',
    'fname=John&lname=Doe');
    // wait for data to come back
    delay(5);
    // read the data into a string
    ReadHTTPPostData(DataString);
    if DataString <> '' then
    begin
    // Find where the data starts and ends
    DataStart := pos('First name: ', DataString) + 12;
    DataEnd := pos('</p>', DataString);
    // extract the data into the string TheFirstNameString
    Copy(TheFirstNameString, DataString, DataStart, DataEnd - DataStart);
    SetStringSystemIO("showsomething", DataString);
    end;
     
    kjayakumar, Jun 22, 2013
    #5
  6. ssaunders

    Roosta

    Joined:
    Nov 22, 2011
    Messages:
    560
    Likes Received:
    1
    Location:
    Australia
    Hey Kjayakumar..

    Yer its strange.. My code is below.. I transfered exactly the same code onto a ctc mk2 connected it to the LAN and works a treat.. So unsure what the go is..

    Cheers..
     
    Roosta, Jun 23, 2013
    #6
  7. ssaunders

    kjayakumar

    Joined:
    Oct 27, 2008
    Messages:
    448
    Likes Received:
    0
    I believe for Wiser, you have to call ReadHTTPPostData as well as there is no guarantee that PostHTTPData completes all of its work in a single call. CTC has a more powerful engine and so there are multiple threads servicing tasks. Wiser has only a single thread so if the socket connection and POST send did not complete in the PostHTTPData, it will only be completed during the ReadHTTPPostData call. I think that's a constraint that's Wiser specific. I'll ask that this be documented.
     
    kjayakumar, Jun 24, 2013
    #7
  8. ssaunders

    Roosta

    Joined:
    Nov 22, 2011
    Messages:
    560
    Likes Received:
    1
    Location:
    Australia
    Thanks Kjayakumar..

    Could you give me an example snippet of code that I should/could try using the readHTTP command in reference to what i am trying to do?

    Cheers..
     
    Roosta, Jun 24, 2013
    #8
  9. ssaunders

    kjayakumar

    Joined:
    Oct 27, 2008
    Messages:
    448
    Likes Received:
    0
    Sure. I would do:
    once (GetLightingState("IP Cam Pos1") = ON) then
    Begin
    PostHTTPData('http://10.1.1.33:1900/decoder_control.cgi?command=31&user=admin&pwd=','' ); {Command to send camera to preset 1}
    Delay("0:00:01");
    { Would be better to call read in a while loop until data is received but for simplicity, just call it a couple of times }
    ReadHTTPPostData(DataString);
    Delay("0:00:01");
    ReadHTTPPostData(DataString);
    SetLightingState("IP Cam Pos1", OFF);
    End;
     
    kjayakumar, Jun 24, 2013
    #9
  10. ssaunders

    Roosta

    Joined:
    Nov 22, 2011
    Messages:
    560
    Likes Received:
    1
    Location:
    Australia
    Kjayakumar.. Thanks so much.. It worked a treat.. :-D

    Although I dont quiet understand why, or what the read command does..

    Cheers..
     
    Roosta, Jun 24, 2013
    #10
  11. ssaunders

    kjayakumar

    Joined:
    Oct 27, 2008
    Messages:
    448
    Likes Received:
    0
    I can explain what I know. Short story, the read is intended to get the data output generated by the server.

    Long story. The first post call doesn't guarantee that the data got to the server. This is because there are multiple things that the post needs to do that can take a lot of time beyond what would be acceptable for a logic function. This includes converting a DNS name to an IP, connecting and establishing a connection to that IP, then sending the http post data to that IP. So what Wiser does is just start the task in the first post call. It tries to convert the name, connect to the IP, if it doesn't finish in time, it doesn't stop the task but instead shelves it to be done later when the readhttppostdata is called. The expectation here is that typical operation would be like this:
    - PostHTTPData to send some HTTP POST command and parameters to a server
    - keep calling ReadPostHTTPData to get the servers complete response and/or complete any incomplete tasks in PostHTTPData

    Hope that helps.
     
    kjayakumar, Jun 24, 2013
    #11
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.