×

INDI Library v2.0.7 is Released (01 Apr 2024)

Bi-monthly release with minor bug fixes and improvements

start indiserver via python [SOLVED]

  • Posts: 2255
  • Thank you received: 223
I have a python script to start my observatory, which is the following
#!/usr/bin/env python2.7
# -*- coding: utf-8 -*-
 
import os
import time
import sys
import pykush
import wiringpi
 
wiringpi.wiringPiSetup()
#set EQ5 pin 2 to OUT
wiringpi.pinMode(2, 1)
#set Atik314 pin 3 to OUT
wiringpi.pinMode(3, 1)
 
 
def rain_check():
        print "Checking for rain"
        io = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_PINS)
        rain_check = io.digitalRead(6)
        if rain_check is 0:
                ykushon("YKC4434")
		time.sleep(2)
                ykushon("YKC4445")
		time.sleep(2)
		eq5()
		time.sleep(1)
		Atik314()
                exit(0)
        else:
                print 'Raining'
        exit(1)
 
def ykushon(serial_number):
        yk = pykush.YKUSH(serial=serial_number)
        yk.set_allports_state_up()
 
def eq5():
	eq5 = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_PINS)
	eq5.digitalWrite(2,0)
 
def Atik314():
        atik314 = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_PINS)
        atik314.digitalWrite(3,0)
 
rain_check()

I would like to add the ability to start the indiserver via the same script, I am aware of Pyindi-client but is there another python library I could use please?
Any pointers is appreciated.
3 years 7 months ago #59918

Please Log in or Create an account to join the conversation.

  • Posts: 2255
  • Thank you received: 223
Might be able to achieve this via the indiweb API github.com/knro/indiwebmanager
3 years 7 months ago #59920

Please Log in or Create an account to join the conversation.

  • Posts: 1957
  • Thank you received: 420
How about using the os module and simply invoking the indiserver command line with the drivers you need?
The following user(s) said Thank You: Gonzothegreat
3 years 7 months ago #59922

Please Log in or Create an account to join the conversation.

  • Posts: 2255
  • Thank you received: 223

didn't think of that one, I shall give it a try, thanks
3 years 7 months ago #59927

Please Log in or Create an account to join the conversation.

  • Posts: 2255
  • Thank you received: 223
heidenrod@heidenrod-obs:~$ python
Python 3.8.2 (default, Jul 16 2020, 14:00:26) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> response = requests.get("http://localhost:8624/api/server/status")
>>> print(response.json())
[{'status': 'False', 'active_profile': ''}]
>>> 
>>> response = requests.post('http://localhost:8624/api/server/start/Simulators')
>>> 
>>> response = requests.get("http://localhost:8624/api/server/status")
>>> print(response.json())
[{'status': 'True', 'active_profile': 'Simulators'}]
>>> 
>>> response = requests.post('http://localhost:8624/api/server/stop')
>>> response = requests.get("http://localhost:8624/api/server/status")
>>> print(response.json())
[{'status': 'False', 'active_profile': ''}]
>>> 
heidenrod@heidenrod-obs:~$
3 years 7 months ago #59933

Please Log in or Create an account to join the conversation.

  • Posts: 2255
  • Thank you received: 223
I have been able to port my start up script to Python3 and add the curl to start the indiserver (done the same for the shutdown script)
heidenrod@heidenrod-obs:~/scheduler$ cat p3obs_up.py 
#!/usr/bin/env python
# -*- coding: utf-8 -*-
 
import os
import time
import sys
from pykush import pykush
import odroid_wiringpi as wiringpi
import requests
 
wiringpi.wiringPiSetup()
# set EQ5 pin 2 to OUT
wiringpi.pinMode(2, 1)
# set Atik314 pin 3 to OUT
wiringpi.pinMode(3, 1)
 
 
def rain_check():
        print("Checking for rain")
        io = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_PINS)
        rain_check = io.digitalRead(6)
        if rain_check == 0:
                ykushon("YKC4434")
                time.sleep(2)
                ykushon("YKC4445")
                time.sleep(2)
                eq5()
                time.sleep(1)
                Atik314()
                time.sleep(2)
                indiON()
                exit(0)
        else:
                print("Raining")
        exit(1)
 
# ykush boards ON
def ykushon(serial_number):
        yk = pykush.YKUSH(serial=serial_number)
        yk.set_allports_state_up()
 
# EQ5 power ON
def eq5():
	eq5 = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_PINS)
	eq5.digitalWrite(2,0)
 
# Atik314 power ON
def Atik314():
        atik314 = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_PINS)
        atik314.digitalWrite(3,0)
 
# indiserver ON (via indiweb)
def indiON():
	response = requests.post('http://localhost:8624/api/server/start/Heidenrod')
 
rain_check()
heidenrod@heidenrod-obs:~/scheduler$
3 years 7 months ago #60004

Please Log in or Create an account to join the conversation.

  • Posts: 2255
  • Thank you received: 223
heidenrod@heidenrod-obs:~/scheduler$ cat p3obs_down.py 
#!/usr/bin/env python
# -*- coding: utf-8 -*-
 
import os
import time
import sys
from pykush import pykush
import odroid_wiringpi as wiringpi
import requests
 
wiringpi.wiringPiSetup()
#set EQ5 pin 2 to OUT
wiringpi.pinMode(2, 1)
#set Atik314 pin 3 to OUT
wiringpi.pinMode(3, 1)
 
def ykushoff():
        yk1 = pykush.YKUSH(serial="YKC4434")
        yk1.set_allports_state_down()
 
def eq5():
	eq5 = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_PINS)
	eq5.digitalWrite(2,1)
 
def Atik314():
        atik314 = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_PINS)
        atik314.digitalWrite(3,1)
 
def indiOFF():
	response = requests.post('http://localhost:8624/api/server/stop')
 
indiOFF()
time.sleep(4)
ykushoff()
time.sleep(3)
eq5()
time.sleep(2)
Atik314()
print("Observatory off")
exit(0)
heidenrod@heidenrod-obs:~/scheduler$
3 years 7 months ago #60006

Please Log in or Create an account to join the conversation.

Time to create page: 0.239 seconds