Skip to content
Snippets Groups Projects
Commit 40761891 authored by am0ebe's avatar am0ebe
Browse files

catch OLA Module not found exception for integration from dataSync script in...

catch OLA Module not found exception for integration from dataSync script in ecotron. change skyglow-list construction from dict.
parent 0884ffb4
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/python3 #!/usr/bin/python3
#TODO catch if no ola is installed
# Traceback (most recent call last):
# File "./skyglow.py", line 5, in <module>
# from ola.ClientWrapper import ClientWrapper
# ImportError: No module named ola.ClientWrapper
from __future__ import print_function #python 2 from __future__ import print_function #python 2
import os import os, sys, array
from ola.ClientWrapper import ClientWrapper
from datetime import datetime as dt from datetime import datetime as dt
import array
import sys
# error / return codes # error / return codes
# # # # # # # # # # # # # #
...@@ -21,6 +11,7 @@ FAIL_DMX_SEND=4 ...@@ -21,6 +11,7 @@ FAIL_DMX_SEND=4
FAIL_DMX_RECEIVE=5 FAIL_DMX_RECEIVE=5
FAIL_LOG=6 FAIL_LOG=6
FAIL_MOON=7 FAIL_MOON=7
FAIL_NO_OLA=8
# either fullpath or just name (then logFile will be created in scriptdir) # either fullpath or just name (then logFile will be created in scriptdir)
# or fullpath containing '/' # or fullpath containing '/'
...@@ -36,35 +27,38 @@ dmxDataReceived = False ...@@ -36,35 +27,38 @@ dmxDataReceived = False
MAX_DMX_FRAME_SIZE = 512 MAX_DMX_FRAME_SIZE = 512
skyglowDict = {
15: 0.08, # one
54: 0.3, # one
4: 1, # all
19: 0.1, # one
0: 0, # none
1: 0.01, # one
5: 0.03, # one
0: 0, # none
40: 10, # all
12: 3, # all
123: 30, # all
123: 30, # all
}
skyglow = list( skyglowDict.keys() )
skyglow.insert(7,0) #exit twice
skyglow.append(123) #exit twice
assert len(skyglow)==12, "skyglow len doesn't fit number pf ecounits!"
#change according to needs #change according to needs
dmx_addr = [10,20,30,40,50,60,70,80,90,100,110,120] dmx_addr = [10,20,30,40,50,60,70,80,90,100,110,120]
NUM_ECO_UNITS = len(dmx_addr)
# assert len(dmx_addr) == NUM_ECO_UNITS
# assert len(skyglow) == NUM_ECO_UNITS
#Mapping byte to lux
skyglow = [ 15, # one 0.08
54, # one 0.3
4, # all 1
19, # one 0.1
0, # none 0
1, # one 0.01
5, # one 0.03
0, # none 0
40, # all 10
12, # all 3
123, # all 30
123, # all 30
]
NUM_ECO_UNITS = len(skyglow)
sunrise = 0 sunrise = 0
sunset = 0 sunset = 0
#UTC: utcfromtimestamp() / datetime.now(timezone.utc) #UTC: utcfromtimestamp() / datetime.now(timezone.utc)
now = dt.utcnow().replace(second=0, microsecond=0) # ignore seconds and microseconds now = dt.utcnow().replace(second=0, microsecond=0) # ignore seconds and microseconds
#mlx (idx is also dmx-byte value) #mlx (idx is also dmx-byte value)
moon = [ 1.409, moon = [
1.409,
8.369, 8.369,
12.333, 12.333,
16.210, 16.210,
...@@ -125,8 +119,8 @@ moon = [ 1.409, ...@@ -125,8 +119,8 @@ moon = [ 1.409,
277.267, 277.267,
281.433, 281.433,
287.467, #60 287.467, #60
] ]
#moonFile #moonFile
DATE_COLUMN=0 DATE_COLUMN=0
...@@ -181,7 +175,7 @@ def readLux(): ...@@ -181,7 +175,7 @@ def readLux():
return moonLux return moonLux
def log(msg): def log(msg):
msg = str(now) + msg + "\n" msg = str(now) + "\t" + msg + "\n"
if not os.access(logFile, os.X_OK) or os.access(logFile, os.W_OK): if not os.access(logFile, os.X_OK) or os.access(logFile, os.W_OK):
print("writing log to file ", logFile) print("writing log to file ", logFile)
...@@ -263,6 +257,11 @@ def main(args=""): ...@@ -263,6 +257,11 @@ def main(args=""):
print("welcome to skyglow!") print("welcome to skyglow!")
print(args) print(args)
try:
from ola.ClientWrapper import ClientWrapper
except Exception as e:
error(FAIL_NO_OLA, e)
global data, moonLux, moonDmx global data, moonLux, moonDmx
init() init()
...@@ -299,6 +298,7 @@ def main(args=""): ...@@ -299,6 +298,7 @@ def main(args=""):
print("DMX-Data:",data) print("DMX-Data:",data)
try: try:
global wrapper global wrapper
wrapper = ClientWrapper() wrapper = ClientWrapper()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment