Jump to content

MY project to make ISY push variables to Raspberry Pi Python


johnstonf

Recommended Posts

Posted (edited)

Here are the overall steps i used to get my ISY passing variables to my RaspberryPi RPi3...
(Just thought I'd throw them up to help any NEWBIES like me... starting is the hardest)

HUGE shoutout of thanks to my buddy LarryLIX who seems to always be there to help!
(Even past midnight)
 
-Notes: (where you see ip’s below, substitute yours)…
  -My SCREENSHOTS can be a bit confusing... so to clarify...
    -My ISY CONSOLE Is always ran on my MAC
    -All the Python code is done on the RPi3, via VNC remoted to the RPi3
      (that's how i was able to screenshot BOTH at the same time)
  -My ISY is 192.168.77.147
  -My Raspberry Pi3 is 192.168.77.209
  -RPi3 is Raspberry Pi3 running Raspbian and Python3
  -Note the attached SCREENSHOTS where noted below!!! 
    (stick them in at those points)
 
 
-Install ISY networking module if not installed
  -Console> Help> PurchaseModules
  -Reboot ISY: Console> Configuration(Tab)> Reboot(button)
 
-Create 5 test variables (Test1,Test2...Test5)
  -Console> Programs> Variable> Integer(Tab)
  (Note their ID#'s in left column)
 
-Create "Network Resource"
  -Console> Configuration> Networking(tab)> NetworkResources(tab)
   -Add> Name="RPi3", URL>
    -http:
    -GET
    -Host: 192.168.77.209
    -Port: 8000  (This is port we set on the RPi3 later)
    -Path: /1/2/3/4/5  (This is TEST set of values to pass to RPi3)
    -Click UPDATE and make screen look like below… then SAVE button
 
SEE SCREENSHOT 1 HERE...
 
-Create a PROGRAM to run on ISY:
  -Console> Programs> Details(tab)> NewProgram(button)
  -Name it 000TEST (000 Keeps near top of list so handy)
  -In ‘Then’ section, want to see “Resource ‘RPi3” (what you named it above)
    (Click “Action”> Networking(dropdown)> Resource> RPi3(dropdown))
  -Now ready to run it… LATER…
 
-NOW ON RPi3…
-Paste the code below into file, example /IsyToPython/TEST001.py
  (be careful that each new indent level is 2 spaces, hopefully copy/paste works ok)
 
#!/usr/bin/python3.4
fjversion="v1.01b/18feb15/BuddyISY-SAMPLE-002.py"
#Thanks for code from LarryLIX!
#!/usr/bin/env python
from http.server import BaseHTTPRequestHandler, HTTPServer
###
# HTTPRequestHandler class
class myHTTPServer_RequestHandler(BaseHTTPRequestHandler):
  # GET
  def do_GET(self):
    words = self.requestline.split()
    params = words[1].split("/",7)
    if len(params) > 5:
      # Send response status code
      self.send_response_only(200)
      self.send_header('Content-type','text/html')
      self.end_headers()
      self.wfile.write(bytes("GET OK", "utf8"))
      Test1 = params[1]
      Test2 = params[2]
      Test3 = params[3]
      Test4 = params[4]
      Test5 = params[5]
      print("Test1:",Test1, " Test2:",Test2, " Test3:",Test3, " Test4:",Test4, " Test5:",Test5)
    else:
      # Send response status code
      self.send_error(400)
      self.send_header('Content-type','text/html')
      self.end_headers()
      self.wfile.write(bytes("GET Bad", "utf8"))
      print("GET:format error!")
      return
###
###
def run():
  print('starting server...')
###
  # Server settings
  server_address = ('192.168.77.209', 8000)
  httpd = HTTPServer(server_address, myHTTPServer_RequestHandler)
###
  print('running server...')
  httpd.serve_forever()
###
###
run()
 
 
-Substitue YOUR RPi3 ipAddress above, and note port is 8000
-Run the above .py python file in Python3 (Run Python3-IDLE, then File> Open… then F5 to run
-On the ISY console, run the THEN section of the 000TEST program by…
  -RightClick on 000TEST, then “Run Then” line…
  -Now on the RPi3 you should see Test1: 1  Test2:2  Test3:3  Test4:4  Test5:5
  -The Python variables are Test1, Test2, etc

 

 

SEE SCREENSHOT 2 HERE...
 
 
 
-Now put ACTUAL variables into the Program Resource on the ISY…
  -Replace /1/2/3/4/5 in above path with, for example…
 …with 
  /${var.1.20}/${var.1.21}/${var.1.22}/${var.1.23}/${var.1.24}
…where 1=INTEGER, and 20,20,etc are the Variable# we recorded above when creating them
…substitue your own, if you used STATE variables, they would be 2.20 and 2.21 etc
-Run the program again, and now the values you give to Test1 to Test5 should appear in the ISY
  (I set values of Test1=11, Test2=12, etc…)
  Now see 11,12,13,14,15, so it is pushing VARIABLES over!
 
 

SEE SCREENSHOT 3 HERE...

 

~end~

 

 

Screen Shot 2018-02-16 at 9.40.21 AM.png

Screen Shot 2018-02-16 at 9.42.31 AM.png

Screen Shot 2018-02-16 at 9.44.27 AM.png

Edited by johnstonf
  • Like 2
Posted

Nicely done Fred!

 

I find it easier to just write my own a lot of the time as the docs these days on hobby level stuff is so bad I have no idea where to even type in the lines given.

 

Confused by your overlays. You aren't running admin console on the RPi are you?

 

Sent from my SGH-I257M using Tapatalk

 

 

 

 

Posted (edited)

Ya, i see that... i'll edit/add a note  that ISY console is always ran from MAC, not Linux/RPi3

Thx

(update: this has been done)

Edited by johnstonf
Posted
3 hours ago, larryllix said:

Nicely done Fred!

 

I find it easier to just write my own a lot of the time as the docs these days on hobby level stuff is so bad I have no idea where to even type in the lines given. emoji20.png

 

Confused by your overlays. You aren't running admin console on the RPi are you?

 

Sent from my SGH-I257M using Tapatalk

 

 

 

 

Ya, some of the stuff put up these days is so bad, causing a lot of work for someone trying to do it.
Wish people would just take a little time to think about how it looks from others' perspective, and at least TRY...

Sometimes better just to NOT post that to do a poor job and cause others grief.

 

 

 

Guest
This topic is now closed to further replies.

×
×
  • Create New...