drawAllCharts();
});
+
{% endblock %}
\ No newline at end of file
diff --git a/agriculture/agriculturecore/templates/sidebar.html b/agriculture/agriculturecore/templates/sidebar.html
index 28d72f7..49b2b85 100644
--- a/agriculture/agriculturecore/templates/sidebar.html
+++ b/agriculture/agriculturecore/templates/sidebar.html
@@ -20,22 +20,7 @@
-
Simulation controls
-
-
Weather condition
-
Control the weather condition of the farm. You can change it to see different temperature and moisture values.
-
-
-
-
-
-
+
Simulation control
Time
Control how the time elapses in the farm. You can change it to see the irrigation events faster.
@@ -188,15 +173,16 @@
});
// Add 'click' callbacks to the weather and time buttons.
- $(".weather-button").click(setWeatherCondition);
$(".time-button").click(setTimeFactor);
// Check the farm connection status.
checkFarmConnectionStatus();
- // Get the weather condition and time factor from the irrigation controller.
- getWeatherCondition();
+ // Get the time factor from the irrigation controller.
getTimeFactor();
+
+ // Check farm connectivity in 5 secs.
+ setTimeout(checkFarmConnected, 5000, "schedule");
});
// Sets the selected section.
@@ -223,7 +209,7 @@
function getControllerID() {
return '{{ controller_id }}';
}
-
+
// Gets the status of the farm.
function verifyParameters() {
let url = new URL(window.location.href);
diff --git a/agriculture/agriculturecore/urls.py b/agriculture/agriculturecore/urls.py
index cfd5505..ae8a820 100644
--- a/agriculture/agriculturecore/urls.py
+++ b/agriculture/agriculturecore/urls.py
@@ -35,6 +35,9 @@
path('ajax/get_stations', views.get_irrigation_stations, name='get_irrigation_stations'),
path('ajax/set_valve', views.set_valve, name='set_valve'),
path('ajax/get_wind', views.get_wind, name="get_wind"),
+ path('ajax/get_wind_dir', views.get_wind_dir, name="get_wind_dir"),
+ path('ajax/get_luminosity', views.get_luminosity, name="get_luminosity"),
+ path('ajax/get_rain_acc', views.get_rain_acc, name="get_rain_acc"),
path('ajax/get_rain', views.get_rain, name="get_rain"),
path('ajax/get_radiation', views.get_radiation, name="get_radiation"),
path('ajax/get_temperature', views.get_temperature, name="get_temperature"),
diff --git a/agriculture/agriculturecore/views.py b/agriculture/agriculturecore/views.py
index 3c3bb80..b071816 100644
--- a/agriculture/agriculturecore/views.py
+++ b/agriculture/agriculturecore/views.py
@@ -14,6 +14,7 @@
from django.shortcuts import redirect
from django.template.response import TemplateResponse
+
from agriculturecore.drm_requests import *
PARAM_CONTROLLER_ID = "controller_id"
@@ -37,6 +38,14 @@
"agriculture demo."
+def farms_map(request):
+ if is_authenticated(request):
+ if request.method == "GET":
+ return TemplateResponse(request, 'map.html')
+ else:
+ return redirect_login(request)
+
+
def dashboard(request):
if not request_has_params(request):
return redirect("/")
@@ -73,14 +82,6 @@ def schedule(request):
return redirect_login(request)
-def farms_map(request):
- if is_authenticated(request):
- if request.method == "GET":
- return TemplateResponse(request, 'map.html')
- else:
- return redirect_login(request)
-
-
def verify_parameters(request):
"""
Verifies the URL parameters to check if the given farm name and controller
@@ -253,9 +254,7 @@ def get_smart_farms(request):
Farms within the DRM account.
"""
# Check if the AJAX request is valid.
- error = check_ajax_request(request)
- if error is not None:
- return error
+ check_error(request)
smart_farms = get_farms(request)
if len(smart_farms) > 0:
@@ -284,9 +283,7 @@ def get_irrigation_stations(request):
the request.
"""
# Check if the AJAX request is valid.
- error = check_ajax_request(request)
- if error is not None:
- return error
+ check_error(request)
# Get the controller ID from the POST request.
controller_id = request.POST[PARAM_CONTROLLER_ID]
@@ -316,9 +313,7 @@ def get_farm_status(request):
:class:`.JsonResponse`: A JSON response with the status of the farm.
"""
# Check if the AJAX request is valid.
- error = check_ajax_request(request)
- if error is not None:
- return error
+ check_error(request)
try:
# Get the controller ID from the POST request.
@@ -367,9 +362,7 @@ def set_valve(request):
:class:`.JsonResponse`: A JSON response with the set status.
"""
# Check if the AJAX request is valid.
- error = check_ajax_request(request)
- if error is not None:
- return error
+ check_error(request)
# Get the controller ID and irrigation station from the POST request.
data = json.loads(request.body.decode(request.encoding))
@@ -395,9 +388,7 @@ def set_tank_valve(request):
:class:`.JsonResponse`: A JSON response with the set status.
"""
# Check if the AJAX request is valid.
- error = check_ajax_request(request)
- if error is not None:
- return error
+ check_error(request)
# Get the controller ID and status of the valve from the POST request.
data = json.loads(request.body.decode(request.encoding))
@@ -422,9 +413,7 @@ def refill_tank(request):
:class:`.JsonResponse`: A JSON response with the set status.
"""
# Check if the AJAX request is valid.
- error = check_ajax_request(request)
- if error is not None:
- return error
+ check_error(request)
# Get the controller ID and level of the tank from the POST request.
data = json.loads(request.body.decode(request.encoding))
@@ -457,7 +446,7 @@ def get_request_data(request):
def get_wind(request):
"""
- Returns the wind data of the main controller.
+ Returns the wind speed data of the main controller.
Args:
request (:class:`.WSGIRequest`): the AJAX request.
@@ -465,13 +454,55 @@ def get_wind(request):
Returns:
A JSON with the list of data points or the error.
"""
+
return get_data_points(request, ID_WIND)
-def get_rain(request):
+def get_wind_dir(request):
+ """
+ Returns the wind direction data of the main controller.
+
+ Args:
+ request (:class:`.WSGIRequest`): the AJAX request.
+
+ Returns:
+ A JSON with the list of data points or the error.
+ """
+
+ return get_data_points(request, ID_WIND_DIR)
+
+
+def get_luminosity(request):
+ """
+ Returns the luminosity data of the main controller.
+
+ Args:
+ request (:class:`.WSGIRequest`): the AJAX request.
+
+ Returns:
+ A JSON with the list of data points or the error.
+ """
+
+ return get_data_points(request, ID_LUMINOSITY)
+
+
+def get_rain_acc(request):
"""
Returns the rain data of the main controller.
+ Args:
+ request (:class:`.WSGIRequest`): the AJAX request.
+
+ Returns:
+ A JSON with the list of data points or the error.
+ """
+ return get_data_points(request, ID_RAIN_ACC)
+
+
+def get_rain(request):
+ """
+ Returns the rain accumulated data of the main controller.
+
Args:
request (:class:`.WSGIRequest`): the AJAX request.
@@ -545,9 +576,7 @@ def check_farm_connection_status(request):
A JSON with the status of the farm or the error.
"""
# Check if the AJAX request is valid.
- error = check_ajax_request(request)
- if error is not None:
- return error
+ check_error(request)
# Get the controller ID and irrigation station from the POST request.
data = json.loads(request.body.decode(request.encoding))
@@ -587,3 +616,9 @@ def request_has_params(request):
`True` if the request has the required parameters, `False` otherwise.
"""
return request_has_id(request) and request_has_name(request)
+
+
+def check_error(request):
+ error = check_ajax_request(request)
+ if error is not None:
+ return error
diff --git a/agriculture/requirements.txt b/agriculture/requirements.txt
index a049486..5b4e5c2 100644
--- a/agriculture/requirements.txt
+++ b/agriculture/requirements.txt
@@ -1,17 +1,20 @@
-arrow==0.12.1
-asgiref==3.2.10
-backports.functools-lru-cache==1.6.1
-certifi==2018.4.16
-channels==3.0.2
-chardet==3.0.4
-devicecloud==0.5.7
-Django==3.1
-idna==2.10
-python-dateutil==2.7.5
-pytz==2020.1
-requests==2.20.1
-six==1.14.0
-sqlparse==0.3.1
-urllib3==1.25.10
-
-django-pjax~=1.7
\ No newline at end of file
+arrow==0.12.1
+asgiref==3.2.10
+backports.functools-lru-cache==1.6.1
+certifi==2018.4.16
+channels==3.0.3
+chardet==3.0.4
+devicecloud==0.5.7
+Django==2.2
+idna
+python-dateutil==2.7.5
+pytz==2020.1
+requests==2.20.1
+six==1.14.0
+sqlparse==0.3.1
+urllib3
+django-pjax~=1.7
+supervisor==4.2.2
+gunicorn==20.0.4
+daphne==3.0.1
+channels-redis==3.2.0
\ No newline at end of file
diff --git a/agriculture/login/static/css/access.css b/agriculture/static/css/access.css
similarity index 100%
rename from agriculture/login/static/css/access.css
rename to agriculture/static/css/access.css
diff --git a/agriculture/static/js/dashboard.js b/agriculture/static/js/dashboard.js
index 993e9f9..aac0d8d 100644
--- a/agriculture/static/js/dashboard.js
+++ b/agriculture/static/js/dashboard.js
@@ -63,7 +63,8 @@ const INFO_WINDOW_CONTENT_CONTROLLER = "" +
" " +
"