ReadHTTPData

Discussion in 'C-Touch/HomeGate/SchedulePlus/PICED Software' started by DarylMc, Jan 5, 2012.

  1. DarylMc

    DarylMc

    Joined:
    Mar 24, 2006
    Messages:
    1,319
    Likes Received:
    49
    Location:
    Cleveland, QLD, Australia
    Hello everyone
    I have been trying to write some logic to turn a group address on and off with a reply from a http request to an IP camera's motion events.
    Have been reading quite a bit but I am still missing many of the concepts for the logic.
    At this stage I can send the request and show the reply with writeln in the messages.
    If anyone is able to have a look at this and point me to the methods to get the string data to operate a group address I would appreciate it.
    With writeln I see the message as do0=1 but according to the documentation the reply looks like this and if anyone can give me a brief explanation and methods to view the full response would be a big help.
    HTTP/1.0 200 OK\r\n
    Content-Type: text/plain\r\n
    Content-Length: <length>\r\n
    \r\n
    [do0=<state>]\r\n

    {Variables DataString: string;}
    {Turn on group address "camera motion" when camera digital output is on}
    {Turn off group address "camera motion" when camera digital output is off}

    {Get the data}
    GetHTTPData('http://192.168.1.86/cgi-bin/dido/getdo.cgi?');

    {Wait for data to come back, delay in seconds}

    delay(5);

    {Read the data into a string}

    ReadHTTPData(DataString);

    if (DataString <> '')then

    begin writeln (DataString);

    end;

    {the camera will reply "do0=0" when DO is off}
    {the camera will reply "do0=1" when DO is on}

    Thanks
    Daryl
     
    DarylMc, Jan 5, 2012
    #1
  2. DarylMc

    Darren Senior Member

    Joined:
    Jul 29, 2004
    Messages:
    2,361
    Likes Received:
    0
    Location:
    Adelaide, South Australia
    If I understand your post correctly, you are successfully getting the reply from the web cam containing either "do0=0" or "do0=1" and you want to switch a group address on or off accordingly.

    I would do something like:

    Code:
    if DataString <> '' then
    begin 
      if pos('do=1', DataString) > 0 then
        SetLightingState("Group 1", ON)
      else
        SetLightingState("Group 1", OFF);
    end;
    
     
    Darren, Jan 7, 2012
    #2
  3. DarylMc

    DarylMc

    Joined:
    Mar 24, 2006
    Messages:
    1,319
    Likes Received:
    49
    Location:
    Cleveland, QLD, Australia
    Hi Darren
    Yes I am getting the reply.
    I was reading up on it still right now.
    Will try what you just said.
    Thanks
     
    DarylMc, Jan 7, 2012
    #3
  4. DarylMc

    DarylMc

    Joined:
    Mar 24, 2006
    Messages:
    1,319
    Likes Received:
    49
    Location:
    Cleveland, QLD, Australia
    Hello Darren
    That seems to have done the trick.
    Could you have a quick look at it and tell me if it looks OK otherwise.
    Motion from the ip camera is set to operate its digital output and is now operating the group address.
    I am very excited.
    Thank you


    Code:
    {Variables DataString: string;}
    {Turn on group address "camera motion" when camera digital output is on}
    {Turn off group address "camera motion" when camera digital output is off} 
     
      GetHTTPData('http://192.168.1.86/cgi-bin/dido/getdo.cgi?');   {Get the data}      
      
      delay(5);                   {Wait for data to come back, delay in seconds}
       
      ReadHTTPData(DataString);   {Read the data into a string}
    
    begin 
      if pos('do0=1', DataString) > 0 then
        SetLightingState("Camera Motion", ON)
      else
        SetLightingState("Camera Motion", OFF);
    end;
    
    
        
    
     
    Last edited by a moderator: Jan 8, 2012
    DarylMc, Jan 7, 2012
    #4
  5. DarylMc

    Darren Senior Member

    Joined:
    Jul 29, 2004
    Messages:
    2,361
    Likes Received:
    0
    Location:
    Adelaide, South Australia
    You left out this line of code immediately before the "begin":

    Code:
    if DataString <> '' then
    It will mostly work without it, but this will make it more reliable. Apart from that it looks good.

    LOL. Good to hear :)
     
    Darren, Jan 9, 2012
    #5
  6. DarylMc

    DarylMc

    Joined:
    Mar 24, 2006
    Messages:
    1,319
    Likes Received:
    49
    Location:
    Cleveland, QLD, Australia
    Thanks Darren
    I was doing a bit of cut and pasting and got carried away.
    I noticed it still works without that line but was wondering if it would create extra load in the process.
     
    DarylMc, Jan 9, 2012
    #6
  7. DarylMc

    Darren Senior Member

    Joined:
    Jul 29, 2004
    Messages:
    2,361
    Likes Received:
    0
    Location:
    Adelaide, South Australia
    It will work without that line, but if no reply from the camera is received, it will result in the "Camera Motion" group being switched off. That is probably not the desired behaviour.

    That line of code will have negligible effect on processor load.
     
    Darren, Jan 10, 2012
    #7
  8. DarylMc

    DarylMc

    Joined:
    Mar 24, 2006
    Messages:
    1,319
    Likes Received:
    49
    Location:
    Cleveland, QLD, Australia
    Thanks Darren
    Just for reference "if DataString <> '' then" , if the reply does equal nothing.
    Does that skip or stop the line below with the "pos" function from running and using resources.
     
    Last edited by a moderator: Jan 10, 2012
    DarylMc, Jan 10, 2012
    #8
  9. DarylMc

    Darren Senior Member

    Joined:
    Jul 29, 2004
    Messages:
    2,361
    Likes Received:
    0
    Location:
    Adelaide, South Australia
    With the if..then in place, if the condition is false (ie. DataString is blank) then everything in the begin..end block will be skipped.
     
    Darren, Jan 12, 2012
    #9
  10. DarylMc

    DarylMc

    Joined:
    Mar 24, 2006
    Messages:
    1,319
    Likes Received:
    49
    Location:
    Cleveland, QLD, Australia
    Thanks Darren
     
    DarylMc, Jan 12, 2012
    #10
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.
Similar Threads
There are no similar threads yet.
Loading...