PostHTTPData gettingblocked ?

Discussion in 'C-Bus Wiser 1 Controller' started by impact, Mar 5, 2015.

  1. impact

    impact

    Joined:
    Feb 10, 2008
    Messages:
    117
    Likes Received:
    14
    Oh what am I doing wrong... Wrote a small module for the wiser, compiling it, and testing it with a connection to cbus...

    I have an Aurelius controller I want to talk with, but not playing fair from wiser - it works well in a browser, so I know the command is correct - but its like my wiser is not connected to the LAN ?

    MY code looks something like;

    u := 'http://admin:[email protected]/set.cgi?addr=1&gp=1&val=up';

    PostHTTPData(u,'' );
    delay(5);
    ReadHTTPData(s);


    Doing the ReadHTTP although not necessary, as the unit will return nothing from the request... but I had read somewhere on the forum that it may be necessary to do a read to force any buffers to send something...

    Either way the value of s is blank if I explore it.

    Substituting the URL to the age.com.au also gives no response. That's why I am guessing my Wiser is not wanting to connect to the LAN properly.

    I certainly can use a browser to display the wiser pages. I can go into the setup on the wiser and use diagnostics to ping other machines on my internal network....

    I can also try the following code to communicate with the unit - I don't care which way - but both are not working for me at present.


    u := '0101U';
    append (u,chr(13));
    append (u,chr(10));

    OpenClientSocket(1, '192.168.1.26', 6000);
    WriteClientSocket(1, u);
    CloseClientSocket(1);


    Again nothing happens - the actual string I need to send is '0101U\r\n' Its very very particular in needing a CR then NL only... I am only guessing Writesocket uses text and not hex.

    Still thinking its a network issue somehow - no firewall I can see blocking port 60 or other internal ports - any suggestions...
     
    Last edited by a moderator: Mar 5, 2015
    impact, Mar 5, 2015
    #1
  2. impact

    jboer

    Joined:
    Apr 27, 2012
    Messages:
    458
    Likes Received:
    35
    Location:
    Sydney
    A couple of suggestions,

    1.Download Wireshark and do a capture on your network to see what Wiser is actually spitting out. The other thing is to ensure Wiser is actually sending stuff. and if so what it is sending and what the difference is to your browser

    Also see: http://www.cbusforums.com/forums/showthread.php?t=8676&highlight=wiser


    try GetHTTPData rather than POST, As you are technically sending an http request Get is more appropriate and often the other end doesnt know what POST is. Most browsers send Get by default.

    J
     
    jboer, Mar 6, 2015
    #2
  3. impact

    impact

    Joined:
    Feb 10, 2008
    Messages:
    117
    Likes Received:
    14
    Getting closer....

    Wireshark has confirmed the wiser sending commands to the network - yipppeee - process of elimination begins.

    I tried the ReadHTTPData method - and got a response back! A 401 Unauthorised Password required error.

    The PostHTTPData returns nothing though - so good call on some equipment responding better to a Read or Get command.

    Not experienced enough with Wireshark as yet - I can see the /set.cgi etc part in the packets of information - but I do not see anywhere the userid and password in the URL or packet information.

    The userid and password are correct ! My only guess is that the ReadHTTPData method operates similar to a browser and removes the inline userid and password parameters - just like how you can no longer do that in a URL in the browser....

    If that's the case, ReadHTTPData may be no good to me, and the device does not respond to a PostHTTPData, and with no other commands available to set up basic authentication in the header packet.... I might be dead in the water....


    Might have to just preserver with the TCP Socket method - which again wireshark is seeing, but the device is not responding... Probably format errors on the strong and CR LF...

    Thought a Format(u, '0101U', #10#13); is what I needed to get the \r\n after the 0101U command...

    Need more time to play!
     
    Last edited by a moderator: Mar 6, 2015
    impact, Mar 6, 2015
    #3
  4. impact

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    1,586
    Likes Received:
    189
    Location:
    Adelaide, Australia
    It TCP version might not like the fact you are sending a LF CR rather than a CR LF. Also, you can just create this string directly as in '0101U'#13#10. No need for the format or append command. Constructs like 'abc'#13#10'def'#13#10 etc are equally valid.
     
    Ashley, Mar 6, 2015
    #4
  5. impact

    jboer

    Joined:
    Apr 27, 2012
    Messages:
    458
    Likes Received:
    35
    Location:
    Sydney
    That is interesting, I have used the USER:pASS@ syntax not that long ago with a CTC and it worked ok.

    Can you post your logic that you tried when you got your auth error? I might give it a whirl with wireshark myself and see what it is doing..
     
    jboer, Mar 6, 2015
    #5
  6. impact

    impact

    Joined:
    Feb 10, 2008
    Messages:
    117
    Likes Received:
    14
    So I have gone back to TCP....

    Here is my code;

    My module bl;

    Code:
    if (a <> 0) then
    
    begin
            writeln('Starting');
            t :=  #48#49#48#49#85#13#10;
            writeln(t);
            
            OpenClientSocket(1, '192.168.1.26', 6000);
                 err := ClientSocketError(1);
                 if err > 0 then
                 begin
                      format(errorstring, 'Error open ', err:0);
                      writeln(errorstring);
                 end;
              
             WriteClientSocket(1, t);
                 writeln('Client Sent');
                 err := ClientSocketError(1);
                 if err > 0 then
                 begin
                      format(errorstring, 'Error write ', err:0);
                      writeln(errorstring);
                 end;
                 
             CloseClientSocket(1);
                 err := ClientSocketError(1);
                 if err > 0 then
                 begin
                      format(errorstring, 'Error close ', err:0);
                      writeln(errorstring);
                 end;
                          
              writeln('done sent');
    
          a := 0;
     end;
    And I have this in Global Variables
    Code:
    s : String;
    u : array[0..70] of char;
    a : Integer;
    t : array[0..7] of char;
    err : Integer;
    errorstring : String;
    And this in initialisation
    Code:
          a := 1;
          t :=  #48#49#48#49#85#13#10;
    Not the nicest way - but I did it this way so I can run it in the logic engine and test it by running the module. Sometimes I have tried using a delay and hence needed it to execute once, and having a delay would just stop the execution and not continue...

    Within the Logic Engine I have allowed use of all functions for testing so I can write to a log file, and I am connected to the c-bus network...

    The resulting log file shows;
    Code:
    7/03/2015 12:05:30 PM  Info     : Logic Engine Started
    7/03/2015 12:05:30 PM  Logic    : Client 1 closed
    7/03/2015 12:05:30 PM  Logic    : Starting
    7/03/2015 12:05:30 PM  Logic    : 0101U
    
    7/03/2015 12:05:30 PM  Logic    : Client 1 opened 192.168.1.26:6000
    7/03/2015 12:05:30 PM  Logic    : Client Sent
    7/03/2015 12:05:30 PM  Logic    : Client 1 closed
    7/03/2015 12:05:30 PM  Logic    : done sent
    7/03/2015 12:05:31 PM  Info     : Logic Engine Stopped
    Not showing any errors.

    From Wireshark I can see the opening / setting up - but there is no TCP/ IP packet information - its as if it is setting up to send something, and then closes.

    I used Docklight Scripting to set up a TCP session with exactly the same string - and running this I can see that there is indeed a TCP packet with the command I want 0101U being sent, and it works.

    I thought maybe I could not use Client Socket within the logic engine, So I removed all the written statements, compiled it correctly and transferred it to the wiser, which did its reboot, and I expected it to run immediately (I added a statement to turn on a light at the start and off when it finished). The light flashed, but nothing in the TCP packet on wireshark...

    So I know my network supports the transaction through the use of the scripting tool, I know the code executed - but its not forming the TCP packet at all ?
     
    impact, Mar 7, 2015
    #6
  7. impact

    impact

    Joined:
    Feb 10, 2008
    Messages:
    117
    Likes Received:
    14
    Oh Forget it !

    Solved !!!!!

    Happy boy !

    I was opening the connection, and writing to the connection immediately, not giving it enough time to fully open the connection. Putting a delay in between the two statements of a second - and voil? !

    Now I have it done as proof of concept, I can write it properly, in opening the TCP IP connection at initialisation time, keep it open, and have my buttons issue the commands I need when I want them !

    - Its always the last thing you do that solves the problem !
     
    impact, Mar 7, 2015
    #7
  8. impact

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    1,586
    Likes Received:
    189
    Location:
    Adelaide, Australia
    There is a ClientSocketConnected function just for that purpose.

    i.e.

    Code:
    waitUntil(clientSocketConnected(1)); 
     
    Ashley, Mar 7, 2015
    #8
  9. impact

    poldim

    Joined:
    Dec 7, 2010
    Messages:
    166
    Likes Received:
    2
    Location:
    San Francisco, CA
    impact,

    for someone not upto snuff on coding, what does this ultimately achieve for you? HTML (webpage) buttons to control wiser?
     
    poldim, Mar 31, 2015
    #9
  10. impact

    impact

    Joined:
    Feb 10, 2008
    Messages:
    117
    Likes Received:
    14
    Poldim,
    I had some Somfy blinds which were controlled through their RF interface. To get these to work via computer you can use a 1810872 URTS II module which is basically a 16 channel device controlled through rs232 or rs485.

    I had great difficulty just getting a PC to work properly with the device - let alone try to get it to work on cubs... Documentation was scant and various versions conflicted - it was a project I would work on for a day and then try again in 6 months.

    I tried a cheap ebay IP to RS232 converter, but no luck, then I found a specific device by Aurelius. A SC100S IP Interface for Somfy RTS units. It worked first go on the PC (Finally)

    So my code was to either send a POST command to this device, which was userid / password protected (couldn't get to work), or to use a TCP IP connection to this device - so I could send blind commands up and down to a specific channel.

    The Wiser code, was just for when I either pressed a spare c-bus button near the blind to turn a group on or off, and have the wiser monitor that change to send a command across tcpip to raise or lower the blind. In my example the group is on means the blind is up, group is off, blind is down - why I did it that way I will never know...

    I also tried setting up a schedule of events to open or close blinds on times of day - sunset minus an hour - it sends the commands to close blinds, 7am in the morning it opens them etc. I ended up not using the schedule function instead using a bunch of IF macros checking date / time / daylight savings to control the schedule in what I wanted to do... (I didn't like the scheduler for various reasons - I know its not the most efficient way I have done it - but it works for me...

    From there my next enhancement was to get the BOM temperature for the maximum of the day, which would override my scheduled events if I consider it being too hot (ice for testing if the temp will reach a max of 30 then the blinds stay closed - going to play more with this next summer!)

    So that's what I was trying to do - just send IP commands to a device on certain conditions.

    I think I have outgrown the wiser in what I want, and never been happy with the interface (also I have moved away from apple / IOS devices to Windows Phone).

    I like the Wiser 2, but its still limited in my mind. I like how its now a dedicated device, the z wave stuff might be interesting... But I feel its way over priced (Sorry) - it would be a better unit at the $600 mark not $1300.

    My next endeavour will be to play with Home gate - when I can find a cheap dongle for v4, I will buy that, and consider replacing some of my screens in the house with a Surface Pro 3 or similar - mounting it vertically as that would suit my house map, then I can centralise a lot of other neat features I have in mind... Utilising the PC functionality wherever I can to implement family calendars, notes to family, reminders, shopping lists, messaging to family etc..
     
    impact, Apr 1, 2015
    #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
Loading...