Skip to content

Commit

Permalink
网页前后端修改
Browse files Browse the repository at this point in the history
  • Loading branch information
lrqq committed Aug 13, 2022
1 parent 7d00632 commit 600cd3e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 18 deletions.
51 changes: 37 additions & 14 deletions index/templates/manage.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
<button id="manual" class="sf-btn" type="default" onclick="toggle()">人工控制</button>
</div>
<div class="mb10">
<button class="sf-btn">启动系统</button>
<button class="sf-btn" onclick="start_system()">启动系统</button>
<button class="sf-btn">系统重启</button>
<button class="sf-btn">关闭系统</button>
<button class="sf-btn" onclick="halt_system()">关闭系统</button>
</div>
<div class="mb10">
<button class="sf-btn manual-btn" disabled="disabled" onclick="startCar()">开车</button>
Expand All @@ -68,23 +68,23 @@
<div id="sandKinds" class="sf-table-content-col flexbox-col">
<div class="sf-table-content-child flexbox">
<div class="label">车牌号:</div>
<div class="value">123123</div>
<div class="value"></div>
</div>
<div class="sf-table-content-child flexbox">
<div class="label">砂石种类:</div>
<div class="value">123123</div>
<div class="value"></div>
</div>
<div class="sf-table-content-child flexbox">
<div class="label">地磅重量:</div>
<div class="value">123123</div>
<div class="value"></div>
</div>
<div class="sf-table-content-child flexbox">
<div class="label">单价:</div>
<div class="value">123123</div>
<div class="value"></div>
</div>
<div class="sf-table-content-child flexbox">
<div class="label">总金额:</div>
<div class="value">123123</div>
<div class="value"></div>
</div>
</div>
</div>
Expand Down Expand Up @@ -432,13 +432,36 @@
let path=data.src;
let res="";
document.getElementById('snap_jpg').src=path
if(data.label == "0")
res="空车"
else if(data.label == "1")
res="种类1";
else if(data.label == "2")
res="种类2"
document.getElementById('sandKinds').innerHTML = "识别的砂石种类为:"+ res
}
})
}

//控制函数的定时器
var timer_control;
function start_system(){
startCar();
//清除计时器,防止重叠
clearInterval(timer_control);
timer_control = setInterval("get_information_regularly()", 1000);
}

function halt_system(){
clearInterval(timer_control);
}

function get_information_regularly() {
$.ajax({
'url': 'getInfo', //访问的url地址
'dateType': 'json', //想要获得的返回数据类型
success: function (data){
console.log(data);
var value_sequence = document.getElementsByClassName("value");
if(data.state == "ok")
{
value_sequence[0].innerHTML = data.car_id;
value_sequence[1].innerHTML = data.sand_type;
value_sequence[2].innerHTML = data.total_weight;
}
}
})
}
Expand Down
7 changes: 5 additions & 2 deletions index/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ def publishMsg(request):


def get_info(request):
return JsonResponse({"msg": global_var.get_value("msg")})

if(global_var.get_value("status") == "weight_ok"):
return JsonResponse({"state":"ok","car_id": global_var.get_value("car_id"),"sand_type":global_var.get_value("sand_type"),"total_weight":global_var.get_value("total_weight")})
else:
return JsonResponse({"state":"yet","car_id": "null","sand_type":"null","total_weight":"null"})

def manage_info(request):
if request.method == 'POST':
Expand Down Expand Up @@ -78,6 +80,7 @@ def snapImage(request):
res = subprocess.getoutput(cmd)
print(res)
print("res=", res[0])
global_var.set_value("sand_type",res[0])
return JsonResponse({"code": 200, "msg": "success", "label": res[0], "src": src})
else:
print("非linux尚未实现检测!")
Expand Down
6 changes: 4 additions & 2 deletions manage_system/mqtt_functions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# 为了能在外部脚本中调用Django ORM模型,必须配置脚本环境变量,将脚本注册到Django的环境变量中
from email import message
import os, sys
import random
import time
import django
# 引入mqtt包
Expand All @@ -24,7 +25,8 @@ def on_connect(client, userdata, flag, rc):
# 接收、处理mqtt消息
def on_message(client, userdata, msg):
out = str(msg.payload.decode('utf-8'))
global_var.set_value("msg", out)
global_var.set_value("total_weight", out)
global_var.set_value("status","weight_ok")
print(out)

def on_disconnect(client, userdata, rc):
Expand All @@ -40,7 +42,7 @@ def mqttfunction():
client.loop_forever(retry_first_connection=True)


client = mqtt.Client(client_id='client-f{random.randint(0, 1000)}', clean_session=False)
client = mqtt.Client(client_id=f'client-{random.randint(0, 1000)}', clean_session=False)


# 启动函数
Expand Down

0 comments on commit 600cd3e

Please sign in to comment.