Jump to content

How do I execute a Python script on the ISY994?


rafarataneneces

Recommended Posts

Dear programmers

 

I have a wonderful Python script that will allow me to turn on/off my FLUX/MagicLight bulbs.

 

These bulbs are running HORRIBLY as for some reason they turn RED, then they change color, every single time I turn them on.

 

Therefore, I learned how to turn them on/off via a python script that is over 1300+ lines long.

 

I would like to somehow execute that server via a network service or I don't know a web server or a ssh in the ISY

 

Any ideas?

 

Link to comment

Having a python interpreter on the ISY would be a huge breakthrough. All the hardware is there in ISY to support anything you want to do, and could not only eliminate all the second computer proxies/brides/nodes, but also be the lead-in for a multicore ISY995i.

 

Unfortunately, I have never heard these capabilities.

Link to comment

You cannot run outside scrips on the ISY itself. It's operating system is not designed for general purpose use.

 

Many on here use a device like a RaspberryPI, and have scripts by executable via a network call from the ISY.

Link to comment

You cannot run outside scrips on the ISY itself. It's operating system is not designed for general purpose use.

 

Many on here use a device like a RaspberryPI, and have scripts by executable via a network call from the ISY.

 

Ok but if I save a python script on a remote computer, how can I execute that python script through a http call?

 

I know how to set up Apache + PHP, I don't have experience with Python.

Link to comment

You don't need anything as complicated as setting-up an Apache server and PHP just to run a Python REST service!

 

The standard Python library include a module that you can use to build simple services in just a few lines of code.

 

For Python 2:

 

https://docs.python.org/2/library/simplehttpserver.html

 

Or Python 3:

 

https://docs.python.org/3.4/library/http.server.html

 

I haven't used this myself, but I have written simple services in a few lines of code in Ruby (using the Sinatra mini-framework) and Javascript (nodejs). Here are a couple of links showing simple examples.

 

https://www.xplatform.rocks/2014/04/28/create-a-lightweight-rest-service-using-sinatra/

 

https://blog.nodejitsu.com/a-simple-webservice-in-nodejs/

 

The approach is very similar for all 3 languages. You use a powerful HTTP server class/module to create a server, and with only a little bit of code you can create a server that can easily examine requests and make replies. There is no need for a standalone web server.

Link to comment

You don't need anything as complicated as setting-up an Apache server and PHP just to run a Python REST service!

 

The standard Python library include a module that you can use to build simple services in just a few lines of code.

 

For Python 2:

 

https://docs.python.org/2/library/simplehttpserver.html

 

Or Python 3:

 

https://docs.python.org/3.4/library/http.server.html

 

I haven't used this myself, but I have written simple services in a few lines of code in Ruby (using the Sinatra mini-framework) and Javascript (nodejs). Here are a couple of links showing simple examples.

 

https://www.xplatform.rocks/2014/04/28/create-a-lightweight-rest-service-using-sinatra/

 

https://blog.nodejitsu.com/a-simple-webservice-in-nodejs/

 

The approach is very similar for all 3 languages. You use a powerful HTTP server class/module to create a server, and with only a little bit of code you can create a server that can easily examine requests and make replies. There is no need for a standalone web server.

 

Is there a Google App or something that I can create on the cloud?

Link to comment

Is there a Google App or something that I can create on the cloud?

 

There are MANY, MANY "cloud"-based (whatever that really means...) services for running little REST servers, periodic cron jobs, etc. etc. Some are for a specific language/environment (for example, services that offer nothing else but running Sinatra servers, or nodejs servers, or...) some are more general. e.g. a low-end VPS, or Virtual Private Server.

 

 

You probably don't want it on the cloud, though. Then you'd need to have your router redirect a port to the ISY, and open your ISY up to the Internet. Yes, you can use HTTPS. No, still not really a good idea...

 

And then you are dependent on the Internet.

 

Better to run it on a local device. An always-on computer. A Raspberry Pi. Your router, running open-source Linux-based router firmware.

Link to comment

There are MANY, MANY "cloud"-based (whatever that really means...) services for running little REST servers, periodic cron jobs, etc. etc. Some are for a specific language/environment (for example, services that offer nothing else but running Sinatra servers, or nodejs servers, or...) some are more general. e.g. a low-end VPS, or Virtual Private Server.

 

 

You probably don't want it on the cloud, though. Then you'd need to have your router redirect a port to the ISY, and open your ISY up to the Internet. Yes, you can use HTTPS. No, still not really a good idea...

 

And then you are dependent on the Internet.

 

Better to run it on a local device. An always-on computer. A Raspberry Pi. Your router, running open-source Linux-based router firmware.

 

So if I install DD WRT on my router I can SSH to it and run Apache + PHP + Python?

 

That would be awesome!!

 

Has anybody done that?

Link to comment

You don't need anything as complicated as setting-up an Apache server and PHP just to run a Python REST service!

 

The standard Python library include a module that you can use to build simple services in just a few lines of code.

 

For Python 2:

 

https://docs.python.org/2/library/simplehttpserver.html

 

Or Python 3:

 

https://docs.python.org/3.4/library/http.server.html

 

I haven't used this myself, but I have written simple services in a few lines of code in Ruby (using the Sinatra mini-framework) and Javascript (nodejs). Here are a couple of links showing simple examples.

 

https://www.xplatform.rocks/2014/04/28/create-a-lightweight-rest-service-using-sinatra/

 

https://blog.nodejitsu.com/a-simple-webservice-in-nodejs/

 

The approach is very similar for all 3 languages. You use a powerful HTTP server class/module to create a server, and with only a little bit of code you can create a server that can easily examine requests and make replies. There is no need for a standalone web server.

For python3 where does this HTTPServer come from?

 

I only ever get no such module. I have tried every import xxx I can think of and find in the referenced links.

Even the docs have syntax errors in them so I suspect some are untested.

 

 

 

UPDATE: I got it from another site

 

from http.server import BaseHTTPRequestHandler, HTTPServer

 

Thanks!

Link to comment

So if I install DD WRT on my router I can SSH to it and run Apache + PHP + Python?

 

That would be awesome!!

 

Has anybody done that?

 

 

In theory, you could do that.  In the real world, there isn't enough storage or memory in a router to support an application written in python.

 

If you are capable of installing DD-WRT and setting up Apache/PHP, etc, then you can also set up a Raspberry PI -- just do that, it'll be far, far easier.

Link to comment

In theory, you could do that.  In the real world, there isn't enough storage or memory in a router to support an application written in python.

 

If you are capable of installing DD-WRT and setting up Apache/PHP, etc, then you can also set up a Raspberry PI -- just do that, it'll be far, far easier.

 

I have the Netgear R7000 but I have doubts I will be able to run Apache + PHP + Python as I read DDWRT only allows Apache + PHP but no CGI (and I need that to execute Python)

 

I am going to use a Raspberry PI at some moment, right now I am using Google App Engine and it works wonderful

 

I don't want to buy a computer unless I see myself starting to write so many APIs that I am afraid the cloud will fail or I want to gain speed from a local IP address talking directly to my bulbs/ISY.

Link to comment

Ladies and Gentlemen

 

Thank you for all your suggestions!!

I have a WD My Cloud EX4

 

It had python already installed!

 

And it had an Apache server already installed

 

and it executed cgi-bin files in a special folder already!

 

All I had to do was create links from the /Shares/cgi-bin to /var/www/cgi-bin/

 

That's It!!!

Now I can upload Python scripts (in this case, I am controlling my MagicLights)

 

And I can turn them ON/OFF!!!

 

All with Network Module from ISY994!!!

Link to comment

You do NOT need Apache!

 

You do NOT need CGI!

 

You do NOT need PHP!

 

You need Python. Period. You can create one or more HTTP servers using the HTTP server package. It's only a few lines of code. Your Python program is the server.

 

You might need to get the http module online using a package manager. I'm not a regular Python user, sorry.

 

Your router with ddwrt is perfectly suited for running Python scripts. Unsure about ddwrt, but much of the OpenWrt UI is WRITTEN in Python.

Link to comment
you don't understand I found an Apache server in my house (WD EX4) perfectly capable of running Python scripts so I chose that route instead of buying a small computer just for that 

 

I do understand.

 

Just pointing-out for the benefit of others that the Apache server, PHP, and CGI are all unnecessary. Might save somebody else a LOT of trouble!

 

With the http server module, you can write a tiny dedicated server in just a few lines of code. You would typically use some port OTHER than port 80. (So it would not interfere with any existing web server running on the same machine.) You just write a small Python script and run it. It listens for HTTP connections on a port.

 

Was not suggesting you buy a small computer. You found your always-on small computer!

 

A stand-alone server just to run your REST service would divorce it from the complexities of Apache.

Link to comment

You do NOT need Apache!

 

You do NOT need CGI!

 

You do NOT need PHP!

 

You need Python. Period. You can create one or more HTTP servers using the HTTP server package. It's only a few lines of code. Your Python program is the server.

 

You might need to get the http module online using a package manager. I'm not a regular Python user, sorry.

 

Your router with ddwrt is perfectly suited for running Python scripts. Unsure about ddwrt, but much of the OpenWrt UI is WRITTEN in Python.

I've ben attempting use some of this python easy code and "a few lines of code" will probably turn out to be a few hundred before anything can be done, with any functionality.

 

Python offers some BaseHTTPRequestHandler package along with a few others that support REST style commands. The package allows you to send back select information from a hit on your IP address and port. It doesn't matter what the URL contains the package is labelled as a "GET" and no decoding or simplicity is offered othe than handing the whole URL to you in a string variable.

 

So now a complete parser is required to be written, as well as the downstream device handlers etc. The very basics may be there, but a long long way from just a few lines of code.

 

It does get the URL call into python though.

Link to comment

I'd suggest doing some searches on creating REST servers in Python. I think you may want to look at using a "micro framework". It looks like Flask is popular:

 

http://flask.pocoo.org/

 

Like I said, I don't write much Python. I would do this in Ruby myself, but only because I am more familiar with Ruby. Python is certainly more universal. For Ruby, I would use the Sinatra micro-framework. Flask looks similar.

Link to comment

I'd suggest doing some searches on creating REST servers in Python. I think you may want to look at using a "micro framework". It looks like Flask is popular:

 

http://flask.pocoo.org/

 

Like I said, I don't write much Python. I would do this in Ruby myself, but only because I am more familiar with Ruby. Python is certainly more universal. For Ruby, I would use the Sinatra micro-framework. Flask looks similar.

Thanks.

For a very small and simple REST command centre it shouldn't be too bad, now that I am getting a handle on it somewhat.

Maybe a hundred lines of python code should hook me into other modules to drive devices. Of course the REST interface module will have to expand every time I hook another into it to split the URLs into various jobs.

 

Thanks for pointing me there in the first place. It gives me more hope for python hooks into the world. This is where I am lacking. Python is new and quite confusing as it is such a mess as is all the linux versions and the RPi in general. :)

I never realised how bad lack standards can make our S.Jobs so tough. :)

Link to comment

I already chose Google App Engine as my server, and my python script works great!!!

I can turn on/off MagicLights (search for MagicLights on Amazon, AMAZING lights!!!)

 

through internal API local network

 

What I don't understand is if I have said that I had a Python code that I wanted to use, why this topic deviated to 'Which frameworks should I use to develop in Python??'

 

I NEVER asked that question, it's ONE SIMPLE Python script and I wanted to know how to hook it up to Apache.

 

At the end of the day, Google App Engine allowed me to deploy the Python script online, and then I hooked it up to WD My Cloud EX4 which already had a Apache Server.

 

I appreciate the people that recommended Raspberry PI since that would be the cheapest way to hook it up if I wouldn't have found a solution.

Link to comment

<snippage>

 

What I don't understand is if I have said that I had a Python code that I wanted to use, why this topic deviated to 'Which frameworks should I use to develop in Python??'

 

I NEVER asked that question, it's ONE SIMPLE Python script and I wanted to know how to hook it up to Apache.

 

At the end of the day, Google App Engine allowed me to deploy the Python script online, and then I hooked it up to WD My Cloud EX4 which already had a Apache Server.

 

I appreciate the people that recommended Raspberry PI since that would be the cheapest way to hook it up if I wouldn't have found a solution.

In your OP you asked

"I would like to somehow execute that server via a network service or I don't know a web server or a ssh in the ISY"

 

Read the thread again. 95% of this thread has been about connecting a RPi python program to an ISY, just as you requested. People were trying to help you, with some sidetracks, of course. :)

Link to comment

Archived

This topic is now archived and is closed to further replies.


×
×
  • Create New...