From 0b7f0cecae9cc8f39039c9695b2f2f6534bcf794 Mon Sep 17 00:00:00 2001 From: dk-15 Date: Mon, 22 May 2017 16:57:42 +0530 Subject: Admin testing platform in working condition --- .gitignore | 1 + myadmin/views.py | 30 +++++++++++++++--------------- sbhs.sqlite3 | Bin 120832 -> 0 bytes static/img/webcam/__placeholder__.txt | 0 templates/admin/sub_nav.html | 7 ++++--- templates/admin/testexp.html | 16 ++++++++++------ 6 files changed, 30 insertions(+), 24 deletions(-) delete mode 100644 sbhs.sqlite3 delete mode 100644 static/img/webcam/__placeholder__.txt diff --git a/.gitignore b/.gitignore index b90888a..01fe87d 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ sbhs_server/credentials.py log/ static/img/webcam/ experiments/ +sbhs.sqlite3 diff --git a/myadmin/views.py b/myadmin/views.py index b868c4f..a15770b 100644 --- a/myadmin/views.py +++ b/myadmin/views.py @@ -95,14 +95,14 @@ def reset_device(req): if usb_path is None: retVal={"status_code":400,"message":"Invalid MID"} - return HttpResponse(json.dumps(retVal)) + return HttpResponse(json.dumps(retVal),content_type='application/json') #trying to connect to device # check if SBHS device is connected if not os.path.exists(usb_path): retVal={"status_code":500,"message":"Device Not connected to defined USB Port"} - return HttpResponse(json.dumps(retVal)) + return HttpResponse(json.dumps(retVal),content_type='application/json') try: board = sbhs.Sbhs() @@ -111,13 +111,13 @@ def reset_device(req): board.status = 1 if board.reset_board(): retVal={"status_code":200,"message":board.getTemp()} - return HttpResponse(json.dumps(retVal)) + return HttpResponse(json.dumps(retVal),content_type='application/json') else: retVal={"status_code":500,"message":"Could not set the parameters.Try again."} - return HttpResponse(json.dumps(retVal)) + return HttpResponse(json.dumps(retVal),content_type='application/json') except serial.serialutil.SerialException: retVal={"status_code":500,"message":"Could not connect to the device.Try again."} - return HttpResponse(json.dumps(retVal)) + return HttpResponse(json.dumps(retVal),content_type='application/json') @csrf_exempt @@ -135,14 +135,14 @@ def set_device_params(req): if usb_path is None: retVal={"status_code":400,"message":"Invalid MID"} - return HttpResponse(json.dumps(retVal)) + return HttpResponse(json.dumps(retVal),content_type='application/json') #trying to connect to device # check if SBHS device is connected if not os.path.exists(usb_path): retVal={"status_code":500,"message":"Device Not connected to defined USB Port"} - return HttpResponse(json.dumps(retVal)) + return HttpResponse(json.dumps(retVal),content_type='application/json') try: board = sbhs.Sbhs() @@ -151,13 +151,13 @@ def set_device_params(req): board.status = 1 if board.setFan(fan) and board.setHeat(heat): retVal={"status_code":200,"message":board.getTemp()} - return HttpResponse(json.dumps(retVal)) + return HttpResponse(json.dumps(retVal),content_type='application/json') else: retVal={"status_code":500,"message":"Could not set the parameters.Try again."} - return HttpResponse(json.dumps(retVal)) + return HttpResponse(json.dumps(retVal),content_type='application/json') except serial.serialutil.SerialException: retVal={"status_code":500,"message":"Could not connect to the device.Try again."} - return HttpResponse(json.dumps(retVal)) + return HttpResponse(json.dumps(retVal),content_type='application/json') @csrf_exempt def get_device_temp(req): @@ -172,14 +172,14 @@ def get_device_temp(req): if usb_path is None: retVal={"status_code":400,"message":"Invalid MID"} - return HttpResponse(json.dumps(retVal)) + return HttpResponse(json.dumps(retVal),content_type='application/json') #trying to connect to device # check if SBHS device is connected if not os.path.exists(usb_path): retVal={"status_code":500,"message":"Device Not connected to defined USB Port"} - return HttpResponse(json.dumps(retVal)) + return HttpResponse(json.dumps(retVal),content_type='application/json') try: board = sbhs.Sbhs() @@ -189,10 +189,10 @@ def get_device_temp(req): temp=board.getTemp() if temp!=0.0: retVal={"status_code":200,"message":temp} - return HttpResponse(json.dumps(retVal)) + return HttpResponse(json.dumps(retVal),content_type='application/json') else: retVal={"status_code":500,"message":"Could not set the parameters.Try again."} - return HttpResponse(json.dumps(retVal)) + return HttpResponse(json.dumps(retVal),content_type='application/json') except serial.serialutil.SerialException: retVal={"status_code":500,"message":"Could not connect to the device.Try again."} - return HttpResponse(json.dumps(retVal)) + return HttpResponse(json.dumps(retVal),content_type='application/json') diff --git a/sbhs.sqlite3 b/sbhs.sqlite3 deleted file mode 100644 index e61f6dc..0000000 Binary files a/sbhs.sqlite3 and /dev/null differ diff --git a/static/img/webcam/__placeholder__.txt b/static/img/webcam/__placeholder__.txt deleted file mode 100644 index e69de29..0000000 diff --git a/templates/admin/sub_nav.html b/templates/admin/sub_nav.html index 29d8840..d1e0cb1 100644 --- a/templates/admin/sub_nav.html +++ b/templates/admin/sub_nav.html @@ -1,4 +1,5 @@ -Show all boards -Show all bookings -Show all images +Show all boards +Show all bookings +Show all images +Test boards

\ No newline at end of file diff --git a/templates/admin/testexp.html b/templates/admin/testexp.html index fa45cd7..aac5657 100644 --- a/templates/admin/testexp.html +++ b/templates/admin/testexp.html @@ -27,9 +27,9 @@ -
+
-
+


@@ -80,9 +80,11 @@ request.done(function(data){ if (data.status_code == 200) { document.getElementById("temp").value = data.message; + document.getElementById("fan_val").value = 100; + document.getElementById("heater_val").value = 0; } else { - alert("Some error occured. Please try again!!"); + alert(data.message); } }); } @@ -100,6 +102,7 @@ var isInputOK = !isNaN(fan_value) && fan_value >=0 && fan_value <= 250 && !isNaN(heater_value) && heater_value >=0 && heater_value; if (!isInputOK) { alert("Please enter a value between 0 and 250"); + return; } var request = $.ajax({ @@ -117,11 +120,11 @@ document.getElementById("temp").value = data.message; } else { - alert("Some error occured. Please try again!!"); + alert(data.message); } }); } - + var mydata; function getTemp() { var selected_machine = document.getElementsByClassName("highlight"); if (selected_machine.length == 0) { @@ -138,11 +141,12 @@ }); request.done(function(data){ + mydata = data; if (data.status_code == 200) { document.getElementById("temp").value = data.message; } else { - alert("Some error occured. Please try again!!"); + alert(data.message); } }); } -- cgit