Jump to content

Banner.jpg.b89429c566825f6ab32bcafbada449c9.jpg

IP Power 9258 Power Control - DIY Software?


Recommended Posts

Hi all, I'm hoping someone can help.  I'm just finishing a DIY obsy, and trying to wrap up the various control packages.  For mains power control I'm using an IP 9258 remote switch from IP Power.  It works, but the supplied web management software  is very poor and I cannot integrate it with the rest of the obsy's  control software which is largely based on 3 LAN webservers (Raspberry Pis).  I have produced a simple LAN server-hosted web page to switch it on and off - but cannot read the resulting on/Off  state of the switches (I think largely for reasons linked to cross-server security which are way ahead of my IT skills).  I can't get at the firmware for the box.  I don't like controlling switches "blind", and unless I can find a software solution I may have  to build a new Arduino controlled switch.   Has anyone produced a web-based front end for the IP 9258 switch that reads the switch state that I could please copy or at least learn how from? 

Thanks in advance

 

Tim Brandt

Link to comment
Share on other sites

I'm not familiar with the hardware, but I'm not sure why you'd be able to set the state of the switch but not read it if both are supported by the firmware (which I assume is presenting an HTTP front end that you're connecting to from one of the RPis?).

Can you explain a bit more about how you're attempting to read the switch state and what goes wrong?

James

Link to comment
Share on other sites

Hi James, thanks for replying.

The switch has an HTTP command format "http://login:password@ipaddress/set.cmd?cmd=setpower+switchnumber=1" ( for on or 0 for off) .  The read command is of tthe format "http://login:password@ipaddrss:port/set.cmd?cmd=getpower".  Both should return a string.  If  used in a straight browser window, the get power command generates a string like  "p61=1,p62=0 etc".  

I'd tried several approaches, mostly with Javascript and jQuery.  Simply sending a window.open command with the url turns the switch on and of ok, but opens a new window with the response code rather than returning it (no surprise).  Using an "HTTP get" command  gives me a CORS access error and a 401 error.  If I suppress CORS  protection in the browser  (which is not long-term viable on my system) I still get a 401 error.  I am out past the boundary of my IT knowledge and after several days of trying would be really grateful for a steer.  The code which gave me the latest CORS and 401 errors was:

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $.get("http://[user]:[password]@192.168.178.76/set.cmd?cmd=getpower", function(data, status){
      alert("Data: " + data + "\nStatus: " + status);
    });
  });
});
</script>
</head>
<body>

<button>Button</button>

</body>
</html>

Thanks, 

Tim

Link to comment
Share on other sites

I don't really do much more than dabble in Javascript, preferring in the main to leave coding with it to the hardcore masochists (or in fact anyone I can sucker into doing it rather than me), but I'd guess the CORS error is because you're trying to load a javascript library (jQuery in this case) from a domain/hostname different from the one for the main loaded window.  If you downloaded the library and copied it to your webserver (or perhaps better, grabbed your own copy from the jQuery website) and loaded it from there then that might well sort it.  If you still get a 401 after that, at what point does it occur?

If you want your main web page to update itself from the data returned rather than load a new page you may need to look at using $.ajax() rather than $.get(), but it's somewhat more complex to do things that way.

If you aren't already using it (I think you may be, but I'm not certain), then the browser console window can be helpful for debugging.

James

Link to comment
Share on other sites

James, thanks.  I tried  a local copy of jQuery as you suggested , but the same result.  I think the CORS error is because I'm trying to do a GET from a different server (the switch), which does not explicitly allow the access .  I have tried both straight javascript and jQuery, and get the same error.  On the other points, this is very much a test fragment;. if I can get it to work then I'll create the webserver itself - I'm already using others to control the 12V supply relays to the mount and the roof.  I've also spent a lot of time on the browser console debugging the other servers...  Any other ideas gratefully received!

Thanks

Tim

Link to comment
Share on other sites

Hmmm.  The nicest way to get this to work would probably be for the switch manufacturer to update their firmware such that you can specify the content of any "Access-Control-Allow-Origin" header that it returns, but I can't see that happening in a hurry.  They may even take the view that you shouldn't be trying to do things the way you're doing them, though that's not very helpful given that it is clearly technically possible to do things the way you want.

Once you have the page being served by a webserver you could have the webserver proxy certain URLs, sending the requests to the switch.  That's not too hard to do in either Apache or nginx assuming you're using one of the two and should circumvent the issue.  It would have the small bonus of avoiding the need to have the login credentials for the switch in the web page, too.  I'd probably set things up such that requests of the form:

  http://<webserver-host>/switch/<command-string>

are proxied to:

  http://[user]:[password]@<switch-host>/<command-string>

If that didn't work then I think I'd resort to writing some code that would run on the webserver and make the request to the switch itself, returning the data.  If you can handle writing Javascript, I'm sure you could handle writing some PHP or similar to do the job.  So, for example, a request to

  http://<webserver-host>/switch-set.php?<cgi-parameters>

would run the PHP script switch-set.php and it in turn would return the results of the request:

  http://[user]:[password]@<switch-host>/set.cmd?<cgi-parameters>

James

Link to comment
Share on other sites

Hi James, I've been trying to set up a webserver on my NAS to try your idea, but can't get all the javascript plugins to work and I don't want to use PHP.  I've ordered another Raspberry Pi, as I know how to make them work and will try again.  I think you may be correct as the problems with access control seem to be browser related and should be bypassed by the server.   I'll let you know how I fare!

Regards

Tim  

Link to comment
Share on other sites

You could use other languages if you wanted to -- PHP is just a relatively easy one to get started with.  Are you trying to use node.js or something like that?

James

Link to comment
Share on other sites

I've tried PHP, nodejs and python, but for what I want to do nodejs works nicely with sockets.io to link to the client.  My other webservers use nodejs, so I can reuse most of the code - much of which has been derived from stuff posted online by those who know much more.  I'm also trying to keep my options open to add INDI support and also to bring together my "distributed" observatory control system into a single cabinet at some point.  At present I've several control boxes containing RPis and arduinos spread around the place as I've tackled different aspects of remote control.  

Regards

Tim

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. By using this site, you agree to our Terms of Use.