finished light functionality
This commit is contained in:
@@ -20,6 +20,7 @@ class BaseMiner:
|
||||
self.api = api
|
||||
self.api_type = None
|
||||
self.model = None
|
||||
self.light = None
|
||||
|
||||
async def _get_ssh_connection(self) -> asyncssh.connect:
|
||||
"""Create a new asyncssh connection"""
|
||||
@@ -56,6 +57,9 @@ class BaseMiner:
|
||||
conn = self._get_ssh_connection()
|
||||
await asyncssh.scp((conn, src), dest)
|
||||
|
||||
async def check_light(self):
|
||||
return self.light
|
||||
|
||||
async def get_board_info(self):
|
||||
return None
|
||||
|
||||
|
||||
@@ -41,12 +41,14 @@ class BOSMiner(BaseMiner):
|
||||
async def fault_light_on(self) -> None:
|
||||
"""Sends command to turn on fault light on the miner."""
|
||||
logging.debug(f"{self}: Sending fault_light on command.")
|
||||
self.light = True
|
||||
await self.send_ssh_command("miner fault_light on")
|
||||
logging.debug(f"{self}: fault_light on command completed.")
|
||||
|
||||
async def fault_light_off(self) -> None:
|
||||
"""Sends command to turn off fault light on the miner."""
|
||||
logging.debug(f"{self}: Sending fault_light off command.")
|
||||
self.light = False
|
||||
await self.send_ssh_command("miner fault_light off")
|
||||
logging.debug(f"{self}: fault_light off command completed.")
|
||||
|
||||
|
||||
@@ -17,18 +17,10 @@ CONFIG_FILE = os.path.join(os.path.dirname(__file__), "files", "config.toml")
|
||||
(START, UNLOCK, INSTALL, UPDATE, REFERRAL, DONE) = range(6)
|
||||
|
||||
|
||||
class testbenchMiner:
|
||||
class TestbenchMiner:
|
||||
def __init__(self, host: ip_address):
|
||||
self.host = host
|
||||
self.state = START
|
||||
self.light = False
|
||||
|
||||
async def fault_light(self):
|
||||
miner = await MinerFactory().get_miner(self.host)
|
||||
if self.light:
|
||||
await miner.fault_light_off()
|
||||
else:
|
||||
await miner.fault_light_on()
|
||||
|
||||
async def add_to_output(self, message):
|
||||
await ConnectionManager().broadcast_json(
|
||||
|
||||
@@ -9,6 +9,7 @@ from fastapi.templating import Jinja2Templates
|
||||
|
||||
from tools.web_testbench._network import miner_network
|
||||
from tools.web_testbench.feeds import update_installer_files
|
||||
from miners.miner_factory import MinerFactory
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
@@ -51,9 +52,18 @@ class ConnectionManager:
|
||||
|
||||
async def connect(self, websocket: WebSocket):
|
||||
await websocket.accept()
|
||||
await websocket.send_json(
|
||||
{"miners": [str(miner) for miner in miner_network.hosts()]}
|
||||
miners = []
|
||||
for host in miner_network.hosts():
|
||||
if host in MinerFactory().miners.keys():
|
||||
miners.append(
|
||||
{
|
||||
"IP": str(host),
|
||||
"Light_On": await MinerFactory().miners[host].get_light(),
|
||||
}
|
||||
)
|
||||
else:
|
||||
miners.append({"IP": str(host), "Light_On": None})
|
||||
await websocket.send_json({"miners": miners})
|
||||
ConnectionManager._connections.append(websocket)
|
||||
|
||||
def disconnect(self, websocket: WebSocket):
|
||||
@@ -73,7 +83,14 @@ async def ws(websocket: WebSocket):
|
||||
await ConnectionManager().connect(websocket)
|
||||
try:
|
||||
while True:
|
||||
data = await websocket.receive()
|
||||
data = await websocket.receive_json()
|
||||
if "IP" in data.keys():
|
||||
print(data)
|
||||
miner = await MinerFactory().get_miner(data["IP"])
|
||||
if data["Data"] == "unlight":
|
||||
miner.fault_light_off()
|
||||
if data["Data"] == "light":
|
||||
miner.fault_light_on()
|
||||
except WebSocketDisconnect:
|
||||
ConnectionManager().disconnect(websocket)
|
||||
except RuntimeError:
|
||||
|
||||
@@ -79,7 +79,15 @@ var options_fans = {
|
||||
|
||||
|
||||
var ws = new WebSocket("ws://{{request.url.hostname}}:{% if request.url.port %}{{request.url.port}}{% else %}80{% endif %}/ws");
|
||||
ws.onmessage = function(event) {
|
||||
function lightMiner(ip, checkbox) {
|
||||
// if the checkbox is checked turn the light on, otherwise off
|
||||
if (checkbox.checked){
|
||||
ws.send(JSON.stringify({"IP": ip, "Data": "light"}))
|
||||
} else if (!(checkbox.check)) {
|
||||
ws.send(JSON.stringify({"IP": ip, "Data": "unlight"}))
|
||||
}
|
||||
};
|
||||
ws.onmessage = function(event) {
|
||||
var data = JSON.parse(event.data)
|
||||
if (data.hasOwnProperty("miners")) {
|
||||
var container_all = document.getElementById('chart_container');
|
||||
@@ -88,24 +96,24 @@ var ws = new WebSocket("ws://{{request.url.hostname}}:{% if request.url.port %}{
|
||||
// create column with ID being the IP for later use
|
||||
var column = document.createElement('div');
|
||||
column.className = "col border border-dark p-3"
|
||||
column.id = miner
|
||||
column.id = miner["IP"]
|
||||
|
||||
// create IP address header
|
||||
var header = document.createElement('button');
|
||||
header.className = "text-center btn btn-primary w-100"
|
||||
header.onclick = function(){window.open("http://" + miner, '_blank');}
|
||||
header.innerHTML += miner
|
||||
header.onclick = function(){window.open("http://" + miner["IP"], '_blank');}
|
||||
header.innerHTML += miner["IP"]
|
||||
|
||||
column.append(header)
|
||||
|
||||
// create install stdout
|
||||
var row_text = document.createElement('div');
|
||||
row_text.className = "row p-3"
|
||||
row_text.id = miner + "-stdout"
|
||||
row_text.id = miner["IP"] + "-stdout"
|
||||
|
||||
// create text area for data
|
||||
var text_area = document.createElement('textarea');
|
||||
text_area.id = miner + "-stdout_text"
|
||||
text_area.id = miner["IP"] + "-stdout_text"
|
||||
text_area.rows = "15"
|
||||
text_area.className = "form-control"
|
||||
text_area.style = "font-size: 12px"
|
||||
@@ -121,36 +129,36 @@ var ws = new WebSocket("ws://{{request.url.hostname}}:{% if request.url.port %}{
|
||||
var hr_canvas = document.createElement('canvas');
|
||||
hr_canvas.width = 125
|
||||
hr_canvas.height = 125
|
||||
hr_canvas.id = miner + "-hr"
|
||||
hr_canvas.id = miner["IP"] + "-hr"
|
||||
|
||||
var temp_canvas = document.createElement('canvas');
|
||||
temp_canvas.width = 125
|
||||
temp_canvas.height = 125
|
||||
temp_canvas.id = miner + "-temp"
|
||||
temp_canvas.id = miner["IP"] + "-temp"
|
||||
|
||||
// create fan 1 title
|
||||
var fan_1_title = document.createElement('p');
|
||||
fan_1_title.innerHTML += "Fan L: 0 RPM";
|
||||
fan_1_title.className = "text-center"
|
||||
fan_1_title.id = miner + "-fan_l"
|
||||
fan_1_title.id = miner["IP"] + "-fan_l"
|
||||
|
||||
// create fan 2 title
|
||||
var fan_2_title = document.createElement('p');
|
||||
fan_2_title.innerHTML += "Fan R: 0 RPM";
|
||||
fan_2_title.className = "text-center"
|
||||
fan_2_title.id = miner + "-fan_r"
|
||||
fan_2_title.id = miner["IP"] + "-fan_r"
|
||||
|
||||
// create fan 1 canvas
|
||||
var fan_1_canvas = document.createElement('canvas');
|
||||
fan_1_canvas.width = 100
|
||||
fan_1_canvas.height = 100
|
||||
fan_1_canvas.id = miner + "-fan-1"
|
||||
fan_1_canvas.id = miner["IP"] + "-fan-1"
|
||||
|
||||
// create fan 2 canvas
|
||||
var fan_2_canvas = document.createElement('canvas');
|
||||
fan_2_canvas.width = 100
|
||||
fan_2_canvas.height = 100
|
||||
fan_2_canvas.id = miner + "-fan-2"
|
||||
fan_2_canvas.id = miner["IP"] + "-fan-2"
|
||||
|
||||
|
||||
// create row for hr and temp data
|
||||
@@ -163,7 +171,7 @@ var ws = new WebSocket("ws://{{request.url.hostname}}:{% if request.url.port %}{
|
||||
|
||||
// create row for fan graphs
|
||||
var row_fan = document.createElement('div');
|
||||
row_fan.className = "row"
|
||||
row_fan.className = "row mb-4"
|
||||
|
||||
// create hr container
|
||||
var container_col_hr = document.createElement('div');
|
||||
@@ -207,7 +215,7 @@ var ws = new WebSocket("ws://{{request.url.hostname}}:{% if request.url.port %}{
|
||||
|
||||
// create miner graph container
|
||||
var miner_graphs = document.createElement('div');
|
||||
miner_graphs.id = miner + "-graphs"
|
||||
miner_graphs.id = miner["IP"] + "-graphs"
|
||||
miner_graphs.hidden = true
|
||||
|
||||
// append the rows to the column
|
||||
@@ -220,21 +228,27 @@ var ws = new WebSocket("ws://{{request.url.hostname}}:{% if request.url.port %}{
|
||||
// create light button container
|
||||
var container_light = document.createElement('div');
|
||||
container_light.className = "form-check form-switch d-flex justify-content-evenly"
|
||||
container_light.id = miner["IP"] + "-light_container"
|
||||
|
||||
// create light button
|
||||
var light_switch = document.createElement('input');
|
||||
light_switch.type = "checkbox"
|
||||
light_switch.id = miner + "-light"
|
||||
if (miner["Light_On"] == true) {
|
||||
light_switch.checked = true
|
||||
}
|
||||
light_switch.id = miner["IP"] + "-light"
|
||||
light_switch.className = "form-check-input"
|
||||
light_switch.addEventListener("click", function(){lightMiner(miner, light_switch);}, false);
|
||||
|
||||
|
||||
// add a light label to the button
|
||||
var label_light = document.createElement("label");
|
||||
label_light.setAttribute("for", "light_" + miner.IP);
|
||||
label_light.setAttribute("for", miner["IP"] + "-light");
|
||||
label_light.innerHTML = "Light";
|
||||
|
||||
// add the button and label to the container
|
||||
container_light.append(label_light)
|
||||
container_light.append(light_switch)
|
||||
container_light.append(label_light)
|
||||
|
||||
column.append(container_light)
|
||||
|
||||
@@ -359,14 +373,14 @@ var ws = new WebSocket("ws://{{request.url.hostname}}:{% if request.url.port %}{
|
||||
miner_stdout.innerHTML = data["text"] + miner_stdout.innerHTML
|
||||
};
|
||||
if (data.hasOwnProperty("Light")) {
|
||||
light_box = document.getElementById(data["IP"] + "-light_container")
|
||||
if (data["Light"] == "show") {
|
||||
|
||||
light_box.hidden = false
|
||||
} else {
|
||||
|
||||
light_box.hidden = true
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user