×

INDI Library v2.0.6 is Released (02 Feb 2024)

Bi-monthly release with minor bug fixes and improvements

Help script Python3 from Stellarmate

  • Posts: 123
  • Thank you received: 10
Hello,
I need help.
I write two scripts to use with the Shutdown Observatory Procedure of Stellarmate. One to shutdown my mount and camera (GPIO) and one to email me a message (with some informations from Openweather).
I can run my script (Python3) from the console and all is right.
But when I use the panel "Shutdown Observatory Procedure of Stellarmate", I've a problem :
"Shutdown script failed, aborting..."

So, do we have a difference between the panel of SM and the console ? How can I execute a script Python 3 ?
Or is the problem come from my code ?
Thank you,
Frank
 
The following user(s) said Thank You: Jasem Mutlaq
2 years 9 months ago #72752

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

  • Posts: 194
  • Thank you received: 20
Please post the script name you have configured in Ekos, and the script code itself. Just the first 10 lines or so will do. Also, type this in the console:
which python3

Thanks
Last edit: 2 years 9 months ago by David Allmon.
2 years 9 months ago #72757

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

  • Posts: 123
  • Thank you received: 10
Hello Dave,
At first, it's important to know that it's my firt steps with the code...
My first script is to manage the GPIO. This script is ok until the last line :

Script to manage my observatory
#!/usr/bin/python3
# Import des bibliotheques et numerotation des GPIO
from tkinter import *
import subprocess
import RPi.GPIO as GPIO
import socket
import os
import shutil
import time
GPIO.setmode(GPIO.BCM)

Prise01 = 5
#!GPIO.setup(Prise01, GPIO.OUT)
#!GPIO.output(Prise01, not GPIO.input(Prise01))

print ("Turning off observatory equipment... Wait 5s.")
time.sleep(5)

#Execute l'envoi d'email ->>> run the second script
exec(open("Email.PY", encoding="utf-8").read(),globals())

And the script 'Email.PY" to email me the weather. from Openweather :

#!/usr/bin/python3
print ("Envoi message... ")

import requests
import json
import datetime
import time

#Meteo
#Consultation API météo avec openweathermap

#récupération de la ville choisie par l'utilisateur
ville = "Pouzauges"

#récupère le temps actuel
url_weather = "api.openweathermap.org/data/2.5/weather?...xxxxxx&units={metric}"
r_weather = requests.get(url_weather)
data = r_weather.json()
#print (data)

now = datetime.datetime.now()

#Fonction de conversion temps
def time_converter(time):
converted_time = datetime.datetime.fromtimestamp(
int(time)
).strftime('%I:%M %p')
return converted_time

#Soleil
Lever_sun = data
Coucher_sun = data

#état du ciel
temps = data[0]

#Nuage
Nuage = data

#temperature actuelle
t = round(data,1)

#écart de température
t_min = round(data,1)
t_max = round(data,1)

#temperature ressentie
tr = round(data,1)

#taux d'humidité
humidite = data

#Pression
Pression = data

#Vent
Vent_speed = data
Vent_deg = data

#Mise à jour serveur meteo
majs = data

#Création du message à envoyer
message_meteo = ("Données Météo à Home Observatory") \
+ '\n' + "*******************************************************" \
+ '\n' + "Fin de session StellarMatte : " + (now.strftime("%Y-%m-%d %H:%M:%S")) \
+ '\n' + ("Lever du soleil : {}".format(time_converter(Lever_sun))) \
+ '\n' + ("Coucher du soleil : {}".format(time_converter(Coucher_sun))) \
+ '\n' + ("Conditions climatiques : {}".format(temps)) \
+ '\n' + ("Couverture nuageuse : {} %".format(Nuage)) \
+ '\n' + ("Taux d'humidite de {} %".format(humidite)) \
+ '\n' + ("Pression : {} hpa".format(Pression)) \
+ '\n' + ("Vitesse Vent : {} km/h".format(round(Vent_speed*60*60/1000),1)) \
+ '\n' + ("Orientation : {} ° (N=0° / Est = 90° / Sud = 180° / Ouest = 270°)".format(Vent_deg)) \
+ '\n' + ("La temperature en fin de session est de {} °c".format(round(t-273.15),1)) \
+ '\n' + ("La temperature ressentie en fin de session est de {} °c".format(round(tr-273.15),1)) \
+ '\n' + ("Les temperatures varient entre {}".format(round(t_min-273.15),1) + " a {} °c ce jour".format(round(t_max-273.15),1)) \
+ '\n' + "*******************************************************" \
+ '\n' + ("Mise à jour serveur météo : {} ".format(time_converter(majs))) \
#Fin Meteo

#!Envoi email de fin de session : Email me

import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

msg = MIMEMultipart()
msg = 'This email address is being protected from spambots. You need JavaScript enabled to view it.'
msg = This email address is being protected from spambots. You need JavaScript enabled to view it.'
msg = 'STELLARMATE. End = ' + now.strftime("%Y-%m-%d %H:%M:%S")
message = 'La session de Stellarmate est finie. ' +'\n' + '\n' + message_meteo
msg.attach(MIMEText(message))
mailserver = smtplib.SMTP('smtp.gmail.com', 587)
mailserver.ehlo()
mailserver.starttls()
mailserver.ehlo()
mailserver.login(This email address is being protected from spambots. You need JavaScript enabled to view it.', xxxxxxx')
mailserver.sendmail('This email address is being protected from spambots. You need JavaScript enabled to view it.', 'This email address is being protected from spambots. You need JavaScript enabled to view it.', msg.as_string())
mailserver.quit()
print ("Message envoyé... ")
exit(0)


In fact, at the end of the first script, I would like to the Email.PY. As I said, the scripts run in the console with the command "python3 Email.PY".
Last edit: 2 years 9 months ago by Frank.
2 years 9 months ago #72759

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

  • Posts: 123
  • Thank you received: 10
And the command "Which python3" send me  : /usr/bin/python3

I tried to compile my two scripts in one. If I try with the console, no problem. If I try with the Panel of SM, I've this message ;  Executing script /home/stellarmate/Scripts/Fin_session.PY... and nothing.

My last script (all in one) :

#!/usr/bin/python3
from tkinter import *
import subprocess
import RPi.GPIO as GPIO
import socket
import os
import shutil
import time

import requests
import json
import datetime

#Manage mount and camera
GPIO.setmode(GPIO.BCM)

Monture = 17
Alimentation = 26
Camera = 27

GPIO.setup(Monture, GPIO.OUT)
GPIO.output(Monture, not GPIO.input(Monture))

GPIO.setup(Alimentation, GPIO.OUT)
GPIO.output(Alimentation, not GPIO.input(Alimentation))

GPIO.setup(Camera, GPIO.OUT)
GPIO.output(Camera, not GPIO.input(Camera))


#The weather at the end of session
now = time.localtime(time.time())

#Consultation API météo avec openweathermap
#récupération de la ville choisie par l'utilisateur
ville = "Pouzauges"
    
#récupère le temps actuel 
url_weather = "api.openweathermap.org/data/2.5/weather?...*****e&units={metric}"

r_weather = requests.get(url_weather)
data = r_weather.json()
#print (data)

now = datetime.datetime.now()

#Conversion temps 
def time_converter(time):
    converted_time = datetime.datetime.fromtimestamp(
        int(time)
    ).strftime('%I:%M %p')
    return converted_time

#Soleil
Lever_sun = data
Coucher_sun = data

#état du ciel 
temps = data[0]

#Nuage
Nuage = data

#temperature actuelle
t = round(data,1)       

#écart de température
t_min = round(data,1)
t_max = round(data,1)

#temperature ressentie
tr = round(data,1)

#taux d'humidité
humidite = data

#Pression
Pression = data

#Vent
Vent_speed = data
Vent_deg = data

#Mise à jour serveur meteo
majs = data

message_meteo = ("Données Météo à Home Observatory") \
+ '\n' + "*******************************************************" \
+ '\n' + "Fin de session StellarMatte : " + (now.strftime("%Y-%m-%d %H:%M:%S")) \
+ '\n' + ("Lever du soleil : {}".format(time_converter(Lever_sun))) \
+ '\n' + ("Coucher du soleil : {}".format(time_converter(Coucher_sun))) \
+ '\n' + ("Conditions climatiques : {}".format(temps)) \
+ '\n' + ("Couverture nuageuse : {} %".format(Nuage)) \
+ '\n' + ("Taux d'humidite de {} %".format(humidite)) \
+ '\n' + ("Pression : {} hpa".format(Pression)) \
+ '\n' + ("Vitesse Vent : {} km/h".format(round(Vent_speed*60*60/1000),1)) \
+ '\n' + ("Orientation : {} ° (N=0° / Est = 90° / Sud = 180° / Ouest = 270°)".format(Vent_deg)) \
+ '\n' + ("La temperature en fin de session est de {} °c".format(round(t-273.15),1)) \
+ '\n' + ("La temperature ressentie en fin de session est de {} °c".format(round(tr-273.15),1)) \
+ '\n' + ("Les temperatures varient entre {}".format(round(t_min-273.15),1) + " a {} °c ce jour".format(round(t_max-273.15),1)) \
+ '\n' + "*******************************************************" \
+ '\n' + ("Mise à jour serveur météo : {} ".format(time_converter(majs))) \

#End Weather

#!Send an email
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
msg = MIMEMultipart()
msg = 'This email address is being protected from spambots. You need JavaScript enabled to view it.'
msg = 'This email address is being protected from spambots. You need JavaScript enabled to view it.'
msg = 'STELLARMATE. End = ' + (now.strftime("%Y-%m-%d %H:%M:%S"))
message = 'It's the END !!!. ' +'\n' + '\n' + message_meteo
msg.attach(MIMEText(message))
mailserver = smtplib.SMTP('smtp.gmail.com', 587)
mailserver.ehlo()
mailserver.starttls()
mailserver.ehlo()
mailserver.login('This email address is being protected from spambots. You need JavaScript enabled to view it.', 'PWD')
mailserver.sendmail(This email address is being protected from spambots. You need JavaScript enabled to view it.', 'This email address is being protected from spambots. You need JavaScript enabled to view it.', msg.as_string())
mailserver.quit()
print ("Message envoyé... ")
exit(0)
 
Last edit: 2 years 9 months ago by Frank.
2 years 9 months ago #72760

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

  • Posts: 123
  • Thank you received: 10
Hmmm, I've found my problem...
I've forgotten to change the right to execute the script.
I'm so...
Frank
2 years 9 months ago #72765

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

  • Posts: 194
  • Thank you received: 20
I'm so... I should have asked that question.
2 years 9 months ago #72772

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

  • Posts: 123
  • Thank you received: 10
It's my first script so I've to learn a ton of things.
Thank you David.
2 years 8 months ago #72810

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

Time to create page: 0.546 seconds