Commit 805b7b7d authored by Caughlin Bohn's avatar Caughlin Bohn
Browse files

Updated WorkerNetwork to use websockets, speed of files without io wait

parent 7298bea5
......@@ -3,8 +3,7 @@ import sys
from neopixel import *
import argparse
from random import randint
import os, stat
import subprocess
import socket
# LED strip configuration:
LED_COUNT = 100 # Number of LED pixels.
LED_PIN = 18 # GPIO pin connected to the pixels (18 uses PWM!).
......@@ -57,8 +56,8 @@ NetLights ={
'CB' : [12,13,14,15,16,17,18,19],
'CD' : [22,23,24,25,26,27,28,29,30],
'DC' : [30,29,28,27,26,25,24,23,22],
'DE' : [31,50,51],
'ED' : [51,50,31],
'DE' : [31,50,51,52],
'ED' : [52,51,50,31],
'DG' : [31,32,33],
'GD' :[33,32,31],
'EM' :[52,53,54],
......@@ -73,8 +72,8 @@ NetLights ={
'FP' :[61,64,65],
'GH' : [39,40,41,42],
'HG' :[42,41,40,39],
'LG' :[36,35,24],
'GL' :[24,35,36],
'LG' :[36,35,34],
'GL' :[34,35,36],
'GK' :[34,37,38],
'KG' :[38,37,34],
'HI' :[43,44,45],
......@@ -106,65 +105,51 @@ def find_path(graph, start, end, path=[]):
print("starting")
import random
iter = 0
def delFile(fileName):
pipe = os.popen("su pi",'w')
pipe.write("rm %s" % fileName)
while True:
try:
files = [filename for filename in os.listdir('/work/netLogs/') if "host" in filename]
filesTemp = []
for l in files:
filesTemp.append(str(l[5:]))
for l in files:
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]):
start = NodePath[data[0]]
end = NodePath[data[1]]
### 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")
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
HOST = '' # Symbolic name meaning all available interfaces
PORT = 50007 # Arbitrary non-privileged port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#sock = socket()
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind((HOST, PORT))
s.listen(1)
#conn, addr = s.accept()
while 1:
conn, addr = s.accept()
data = conn.recv(1024)
tempData = data.split(" ")
iter = 0
while iter < int(tempData[2]):
start = NodePath[tempData[0]]
end = NodePath[tempData[1]]
except Exception as e:
print(str(e))
x=0
print("ERROR")
except Exception as e:
pass
### 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:
for a in path:
data = 128
for i in NetLights.get(a):
r,g,b = 255,0,0
strip.setPixelColor(i,Color(r,g,b))
strip.show()
time.sleep(0.001)
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")
conn.close()
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