Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2015
    Location
    Southern Hemisphere
    Posts
    96

    Default Difficulties sending http string to IP Switch in startup script

    I have been trying to get my IP Switch to except commands from the startup script. So far I have been unsuccessful. If it if I drop the following into a browser I can successfully control this device. As an example, if I want to turn on relay 10 and 11 and turn relay 2 off I would send the following command:

    http://192.168.10.95/current_state.x...11=1&Output2=0

    To turn on relay switch 1:

    http://192.168.10.95/current_state.x...dmin&Output1=1

    I tried to alter the NBPowerOn function in the startup script (original function below). It looked like a great place to start, but my efforts failed. I get no syntax errors with my mofication, but nothing happens.

    function NBPowerOn(switchNumber, switchName)
    {
    // --- user config ---
    var IP = "192.168.1.100";
    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;
    }
    }

    The hardware is an ethernet relay board, and seems to be fairly feature rich. It's been running continually for the last three months in my dome. I hope to leverage the ability of this device to measure humidity and temperature and have it shut everything off during those days of high fire danger or high heat. I really do not wish to have stuff running at +40C.

    http://denkovi.com/internet-ethernet...p4-io-snmp-web

    Terry

  2. #2
    Join Date
    Oct 2005
    Location
    Mesa, AZ
    Posts
    26,235

    Default

    It has been a while... did you solve this? If not, I looked at your strings and the code and they aren't much alike ha ha. The strings got mangled by the Forum software so I repeat them here using the [noparse]...[/noparse] tags:

    if I want to turn on relay 10 and 11 and turn relay 2 off I would send the following command:
    http://192.168.10.95/current_state.xml?pw=admin&Output10=1&Output11=1&O utput2=0

    To turn on relay switch 1:
    http://192.168.10.95/current_state.xml?pw=admin&Output1=1

    Try this (untested)

    Code:
    function PowerCtrl(switchNumber, switchName, TurnOn)  // TurnOn = true for on, false for off{
        // --- user config ---
        var IP = "192.168.10.95";
        var PASS = "admin";
        // -------------------
        var state = TurnOn ? 1 : 0;
        var cmdline = "pw=" + PASS + "&Output" + switchNumber + "=" + state;
        var http = new ActiveXObject("MSXML2.XMLHTTP");
        http.open("GET", "http://" + IP + "/current_state.xml?" + encodeURI(cmdline), false, "", "");
        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;
        }
    }
    -- Bob

  3. #3
    Join Date
    Dec 2015
    Location
    Southern Hemisphere
    Posts
    96

    Default

    Thanks Bob,

    I will give that a go. I had an ugly solution where I just inserted the code below in the Main(). Not very elegant but it worked. It looked like this: (donít laugh too much, still learning)

    // ================================================== ================
    var http = new ActiveXObject("MSXML2.XMLHTTP");
    Console.PrintLine("Turning Power On Relays 1 and 2");
    http.open("GET","http://192.168.10.95/current_state.xml?pw=admin&Output1=1&Output2=1", true);
    http.send();
    Util.WaitForMilliseconds(10000); // Wait 10 seconds
    // ================================================== ================

    Thank you for your help on this.

    Terry

  4. #4
    Join Date
    Oct 2005
    Location
    Mesa, AZ
    Posts
    26,235

    Default

    What the hey? If that works OK. It just won't detect any errors (like no connectivity to the switch or no power to the switch etc.)
    -- Bob

 

 

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. ASCOM Switch Driver for Digital Loggers Switch
    By Jeff Lewis in forum Hardware/Software/Driver Topics Not Directly Related to Our Software
    Replies: 18
    Last Post: Apr 7, 2017, 16:30

Posting Permissions

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