Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Hybrid View

  1. #1

    Default Controlling a powerswitch in StartupObs

    As newcomer to ACP I'm working on StartupObs to include control of my powerswitch TCW181B.
    For some reason I failed to get snmp control to function, so I tried a htpp command in the internet browser.
    This worked fine. eg "http://device.ip.address/status.xml?rX=1" with X being the relais number.


    My question: is there a way to execute the http command via a RUN command in the StartupObs script?

  2. #2
    Join Date
    Oct 2005
    Location
    Mesa, AZ
    Posts
    33,784

    Default

    Not by RUN but you can use AJAX technique to directly script HTTP. I'll assume you can read and write JavaScript, so I will point you to the SampleStartupObs.js. At the end is this function to turn on Power in the NetBooter via HTTP command.

    Code:
    //
    // Turn on a switch for the SynAccess NetBooter NP8
    // Ref: http://synaccess-net.com/downloadDoc/NPStartup-B.pdf
    // NOTE: Assumes the username/password of all switches are the same
    //
    function NBPowerOn(IP, switchNumber, switchName)
    {
        // --- user config ---
        var USER = "admin";
        var PASS = "admin";
        // -------------------
        var cmdline = "$A3 " + switchNumber + " 1";
        var http = new ActiveXObject("MSXML2.XMLHTTP");
        http.open("GET", "http://" + IP + "/cmd.cgi?" + encodeURI(cmdline), false, USER, PASS);
        http.send();
        if(http.status == 200) {
            Console.PrintLine("...powered on " + switchName);
            Console.PrintLine("   " + http.responseText);
        } else {
            throw "** Power on failed for " + switchName + " " + http.status + " " + http.statusText;
        }
    }
    Change cmd.cgi to status.xml and use

    var cmdline = "r" + switchNumber + "=1";

    Change the function name to MyHttpPowerOn or ??? and fix the descriptive comments for your future reference.

    You should create a separate test script with the function and then a

    function main()
    {
    MyHttpPowerOn();
    }

    and run in the ACP console. Once you have it copy MyHttpPowerOn {...} to the StartupObs and call it.
    -- Bob

  3. #3

    Default

    Running the "MyHttpPowerOn.js" in the ACP console throws following:
    -------------------------
    Source: msxml3.dll
    the system cannot locate the resource specified.
    -------------------------
    I've checked Windows\System 32 and Windows\SysWOW64, and both show the msxml3.dll

  4. #4
    Join Date
    Oct 2005
    Location
    Mesa, AZ
    Posts
    33,784

    Default

    The error message is strange. The "resource" is the thing that is accessed via the URL. The message is coming from the MSXML component. So this means that the URL is not being found. Post your simple MyHttpPowerOn.js here and I'll try to see it. But the first thing to check is the IP address and port.
    -- Bob

  5. #5

    Default

    Hi Bob,
    Meanwhile I ran my script on an other PC with an identical but not the same TCW powerbox (PB_B) and it works fine.
    So I assume that the script is ok.
    Username and password are the same for the two powerboxes, but the http ports are different
    Also different is the web access authentication (waa)
    PB_A port: 6998 waa: enabled this one throws the error
    PB_B port: 80 waa: disabled this one is ok
    I'll do some further testing with PB_A
    Ton

  6. #6

    Default

    Some further testing gave following results:
    - For the not-responding powerbox I've changed the http port to 80.
    After that the box is responsive.
    - if the http monitor window is open, the script run fails repeatedly. (1 out of 5 to 1 out of 10)
    - starting Google Chrome when running the script results in failure (almost 100%)
    - the script runs successfully when not simultaneously using the internet or having the http monitor open (100% score


    for 200 successive runs)


    To minimize the risk of failure, would it be possible to read the switchstate after eg a PowerOn command and, if not


    successful, repeat the PowerOn command?


    For your information I've added the script and two Console Outputs.



    Ton


    ==============================================
    function main()
    {
    TCW_PowerOn("192.168.1.2", 6, "MyTestRelay")
    //Util.WaitForMilliseconds(2000);
    //TCW_PowerOff("192.168.1.2", 6, "MyTestRelay")
    //Util.WaitForMilliseconds(2000);
    }
    //TCW_PowerOn
    // Turn on a switch for the TCW181B
    // Ref: http://synaccess-net.com/downloadDoc/NPStartup-B.pdf
    // NOTE: Assumes the username/password of all switches are the same
    //
    function TCW_PowerOn(IP, switchNumber, switchName)
    {
    // --- user config ---
    var USER = "admin";
    var PASS = "admin";
    // -------------------
    var cmdline = "r" + switchNumber + "=2";
    var http = new ActiveXObject("MSXML2.XMLHTTP");
    http.open("GET", "http://" + IP + "/status.xml?" + encodeURI(cmdline), false, USER, PASS);
    http.send();
    if(http.status == 200) {
    Console.PrintLine("...powered on " + switchName);
    Console.PrintLine(" " + http.responseText);
    } else {
    throw "** Power on failed for " + switchName + " " + http.status + " " + http.statusText;
    }
    }
    ==============================================
    Console Output "Success"
    ...powered on MyTestRelay
    <?xml version="1.0" encoding="windows-1251"?>
    <Monitor>
    <Device>TCW181B-CM</Device>
    <ID>00:04:A3:AA:4D:BA</ID>
    <Hostname>TCW181B-CM </Hostname>
    <FW>2.17</FW>
    <DigitalInputDescription></DigitalInputDescription>
    <DigitalInput>OPEN</DigitalInput>
    <Relay1Description></Relay1Description>
    <Relay1>OFF</Relay1>
    <pw1>1.0</pw1>
    "etc"
    "etc"
    <Relay8Description></Relay8Description>
    <Relay8>OFF</Relay8>
    <pw8>4.5</pw8>
    </Monitor>
    ==========================================
    Console Output "failure"
    **Script Error**
    Source: msxml3.dll
    Message: No data is available for the requested resource.


    Location: line 22 column 5.

  7. #7
    Join Date
    Oct 2005
    Location
    Mesa, AZ
    Posts
    33,784

    Default

    This one completely confuses me, I am sorry. First let's just try to change the port in the URL and get the username/password to work. It's hard for me to believe that your switch needs to be repeatedly told to turn on and checked over and over until it actually does it.
    -- Bob

  8. #8

    Default

    As suggested I did some further testing using a script as shown below.
    Two different Powerboxes, unit A and unit B, were tested, both set to port 80.
    Username/password set to "admin" "admin" for both.
    Opening the internet browser while a test is running results immediately in an error.
    Whatver the cause, the error is always the same:


    **Script Error**
    Source: msxml3.dll
    Message: The download of the specified resource has failed.
    Location: line 51 column 5.


    The location is always at http.send in the PowerOn or the PowerOff function.
    When running the tests the internet was not used.


    -----------------------------------------------------Resuls---------------------------------------------------------------------
    waa enabled yes yes no no
    xml/http auth enabled yes no no yes
    nr of successful
    On/Off cycles
    unit A 0 * 24,0,26,9,0,24 7,17,10,22,2 no option
    unit B 0 * 98,32,7 1,34,12,200


    * nothing happens
    -------------------------------------------------------------------------------------------------------------------------------------
    ================================
    function main() // as used for testing
    {
    var i;
    for (i = 0; i < 200; i++) {
    TCW_PowerOn("192.168.1.252", 6, "MyTestRelay")
    Util.WaitForMilliseconds(1000);
    TCW_PowerOff("192.168.1.252", 6, "MyTestRelay")
    Console.Printline(i);
    Util.WaitForMilliseconds(1000);
    }
    }
    ==================================

  9. #9
    Join Date
    Oct 2005
    Location
    Mesa, AZ
    Posts
    33,784

    Default

    Well I'm confused. How can opening a web browser affect a script running in the ACP console? Why did you open it anyway? Can you turn the switches off and on with ACP not running a script, just with the URLs you gave me at the beginning? I think I'm going to need to get on with you and try to write it myself. Are you living in Spain, or ?? I think we can do this during my normal office hours (I am UTC - 7) and we should be able to find a mutually agreeable time. I can easily be here as early as 0700 here (1400 UTC), or earlier if needed.
    -- Bob

  10. #10

    Default

    Sounds like a good idea. Anytime between 14:00 UTC and 18:00 UTC is convenient. (I will be here anyhow with the spanish lockdown.)
    Just let me know the approx time. I have TeamViewer installed and can send you my landline phone number or you can give me yours..
    And yes, control with the URL sent earlier is possible.
    Sorry for causing so much trouble with something that looked like a simple question (for you)
    Ton

 

 

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [closed] Controlling Dust Cover
    By Peter Brackenridge in forum Hardware/Software/Driver Topics Not Directly Related to Our Software
    Replies: 112
    Last Post: Feb 12, 2020, 13:59
  2. Controlling Digital Logger Power Switch
    By Stacey E. Mills in forum Hardware/Software/Driver Topics Not Directly Related to Our Software
    Replies: 13
    Last Post: Feb 5, 2020, 17:45

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •