Commit 7298bea5 authored by Caughlin Bohn's avatar Caughlin Bohn
Browse files

Network LED update

parent bac7cba1
...@@ -3,6 +3,8 @@ import sys ...@@ -3,6 +3,8 @@ import sys
from neopixel import * from neopixel import *
import argparse import argparse
from random import randint from random import randint
import os, stat
import subprocess
# LED strip configuration: # LED strip configuration:
LED_COUNT = 100 # Number of LED pixels. LED_COUNT = 100 # Number of LED pixels.
LED_PIN = 18 # GPIO pin connected to the pixels (18 uses PWM!). LED_PIN = 18 # GPIO pin connected to the pixels (18 uses PWM!).
...@@ -54,7 +56,7 @@ NetLights ={ ...@@ -54,7 +56,7 @@ NetLights ={
'CA' : [12,11,10,9,8,7,6,5,4,3,2,1,0], 'CA' : [12,11,10,9,8,7,6,5,4,3,2,1,0],
'CB' : [12,13,14,15,16,17,18,19], 'CB' : [12,13,14,15,16,17,18,19],
'CD' : [22,23,24,25,26,27,28,29,30], 'CD' : [22,23,24,25,26,27,28,29,30],
'DC' : [30,29,28,2,7,26,25,24,23,22], 'DC' : [30,29,28,27,26,25,24,23,22],
'DE' : [31,50,51], 'DE' : [31,50,51],
'ED' : [51,50,31], 'ED' : [51,50,31],
'DG' : [31,32,33], 'DG' : [31,32,33],
...@@ -77,8 +79,8 @@ NetLights ={ ...@@ -77,8 +79,8 @@ NetLights ={
'KG' :[38,37,34], 'KG' :[38,37,34],
'HI' :[43,44,45], 'HI' :[43,44,45],
'IH' :[45,44,43], 'IH' :[45,44,43],
'HJ' :[43,46,47], 'HJ' :[45,46,47],
'JH' :[47,46,43] 'JH' :[47,46,45]
} }
...@@ -104,37 +106,65 @@ def find_path(graph, start, end, path=[]): ...@@ -104,37 +106,65 @@ def find_path(graph, start, end, path=[]):
print("starting") print("starting")
import random import random
iter = 0 iter = 0
while iter < int(sys.argv[3]): def delFile(fileName):
start = NodePath[sys.argv[1]] pipe = os.popen("su pi",'w')
end = NodePath[sys.argv[2]]
pipe.write("rm %s" % fileName)
while True:
### To do random
start_path = find_path(NetPath,start,end)
path = []
try:
for i in range(0,len(start_path)-1):
path.append(start_path[i]+start_path[i+1])
except:
print("empty path")
try: try:
for a in path: files = [filename for filename in os.listdir('/work/netLogs/') if "host" in filename]
data = 128 filesTemp = []
for i in NetLights.get(a): for l in files:
strip.setPixelColor(i,Color(255,128,255)) filesTemp.append(str(l[5:]))
strip.show() for l in files:
time.sleep(0.01) if min(filesTemp) in l:
fi = l
fi = "/work/netLogs/" + fi
#fi = "/work/netLogs/"+os.listdir("/work/netLogs/")[0]
f = open(fi,'r')
data = f.readline().split(",")
delFile(fi)
print(data)
iter = 0
while iter < int(data[2]):
for i in range(0,100): start = NodePath[data[0]]
strip.setPixelColor(i, Color(0,0,0)) end = NodePath[data[1]]
strip.show() ### To do random
time.sleep(0.05) start_path = find_path(NetPath,start,end)
iter += 1 path = []
try:
for i in range(0,len(start_path)-1):
path.append(start_path[i]+start_path[i+1])
except:
print("empty path")
old = 100
r,g,b = randint(0,255),randint(0,255),randint(0,255)
r,g,b = 255,255,255
try:
for a in path:
data = 128
for i in NetLights.get(a):
strip.setPixelColor(i,Color(r,g,b))
strip.setPixelColor(old,Color(0,0,0))
old = i
strip.show()
time.sleep(0.01)
strip.setPixelColor(old,Color(0,0,0))
for i in range(0,100):
strip.setPixelColor(i, Color(0,0,0))
strip.show()
#time.sleep(0.05)
iter += 1
except Exception as e:
print(str(e))
x=0
print("ERROR")
except Exception as e: except Exception as e:
print(str(e)) pass
x=0
print("ERROR")
...@@ -7,23 +7,26 @@ def sendCommand(command): ...@@ -7,23 +7,26 @@ def sendCommand(command):
p = subprocess.Popen(command.split(" "), stdout=subprocess.PIPE, stderr=subprocess.PIPE) p = subprocess.Popen(command.split(" "), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(stdout, stderr) = p.communicate() (stdout, stderr) = p.communicate()
def sendFile(host,command):
f = open("/work/netLogs/host%s%d" % (host,int(time.time())),'w')
f.write(command)
f.close()
###Get Master Number ###Get Master Number
host = socket.gethostname()[-1:] host = socket.gethostname()[-1:]
workers = ["1","2","3","4","5","6","7","8"] workers = ["1","2","3","4","5","6","7","8"]
###Send job from head to master, M - > F - > M ###Send job from head to master, M - > F - > M
sendCommand("bash net.sh head worker"+host+" 5") sendFile(host,"head,worker"+host+",5")
sendCommand("bash net.sh worker"+host+" file 5") sendFile(host,"worker"+host+",file,5")
sendCommand("bash net.sh file worker"+host+" 5") sendFile(host,"file,worker"+host+",5")
for i in workers: for i in workers:
if i != host: if i != host:
#sendCommand("bash net.sh worker"+host+" worker"+i+" 1") #sendCommand("bash net.sh worker"+host+" worker"+i+" 1")
time.sleep(0.75) time.sleep(0.25)
print("sbatch slave"+i+".sh")
sendCommand("sbatch slave"+i+".sh") sendCommand("sbatch slave"+i+".sh")
sendCommand("bash net.sh worker"+host+" worker"+i+" 1") sendFile(host,"worker"+host+",worker"+i+",1")
#sendCommand("ssh -i /work/LegionKey pi@192.168.1.1"+i+" \"screen -md python /work/usage.py\"") #sendCommand("ssh -i /work/LegionKey pi@192.168.1.1"+i+" \"screen -md python /work/usage.py\"")
print("ssh -i /work/LegionKey pi@192.168.1.1"+i+" \"screen -md python /work/usage.py\"") print("ssh -i /work/LegionKey pi@192.168.1.1"+i+" \"screen -md python /work/usage.py\"")
...@@ -31,8 +34,8 @@ for i in workers: ...@@ -31,8 +34,8 @@ for i in workers:
#sendCommand("bash slaveSubmit.sh") #sendCommand("bash slaveSubmit.sh")
end = time.time() + 40 end = time.time() + 40
while time.time() < end: while time.time() < end:
sendCommand("bash net.sh worker"+str(randint(1,8))+" worker"+str(randint(1,8))+" 1") sendFile(host,"worker"+str(randint(1,8))+",worker"+str(randint(1,8))+",1")
x = 0 x = 0
sendCommand("bash net.sh worker"+host+" file 5") sendFile(host,"worker"+host+",file,5")
sendCommand("bash net.sh worker"+host+" head 5") sendFile(host,"worker"+host+",head,5")
from piglow import PiGlow
import time
import socket
import subprocess
import psutil
from random import randint
p = PiGlow()
val = 100
colour = 1
def sendCommand(command):
p = subprocess.Popen(command.split(" "), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(stdout, stderr) = p.communicate()
x = 0
start = time.time()
host = socket.gethostname()[-1:]
time.sleep(randint(1,3))
#sendCommand("bash /work/net.sh head worker"+host+" 3")
f = open("/work/netLogs/host%s%d" % (host,int(time.time())),'w')
#with open("/work/netlogs/host%s%d" % (host,int(time.time())),'w') as f:
f.write("head,worker"+host+",3")
f.close()
time.sleep(0.5)
while True and (time.time() - start) < randint(5,20):
print("in")
p.white(10)
time.sleep(0.1)
p.blue(20)
time.sleep(0.1)
p.green(30)
time.sleep(0.1)
p.yellow(40)
time.sleep(0.1)
p.orange(50)
time.sleep(0.1)
p.red(60)
time.sleep(0.1)
p.white(255)
time.sleep(0.1)
p.red(0)
time.sleep(0.1)
p.orange(0)
time.sleep(0.1)
p.yellow(0)
time.sleep(0.1)
p.green(0)
time.sleep(0.1)
p.blue(0)
time.sleep(0.1)
p.white(0)
time.sleep(0.1)
p.all(0)
host = socket.gethostname()[-1:]
time.sleep(3)
#sendCommand("bash /work/net.sh worker"+host+" head 2")
f = open("/work/netLogs/host%s%d" % (host,int(time.time())),'w')
f.write("worker"+host+",head,2")
f.close()
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment