Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vcoman/ces demo #6

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ media
# Backup files #
*.bak

# If you are using PyCharm #
# If you are using PyCharm #
.idea/*
*/.idea/*
*.iws /out/

Expand Down Expand Up @@ -103,3 +104,4 @@ GitHub.sublime-settings
!.vscode/launch.json
!.vscode/extensions.json
.history

Empty file added agriculture/.configured
Empty file.
5 changes: 5 additions & 0 deletions agriculture/.ebextensions/django.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
option_settings:
aws:elasticbeanstalk:container:python:
WSGIPath: agriculturecommon.wsgi:application
aws:elasticbeanstalk:environment:proxy:staticfiles:
/static: static
5 changes: 5 additions & 0 deletions agriculture/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

# Elastic Beanstalk Files
.elasticbeanstalk/*
!.elasticbeanstalk/*.cfg.yml
!.elasticbeanstalk/*.global.yml
4 changes: 2 additions & 2 deletions agriculture/agriculturecommon/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []
ALLOWED_HOSTS = ['*']


# Application definition
Expand Down Expand Up @@ -93,7 +93,7 @@
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}

Expand Down
3 changes: 2 additions & 1 deletion agriculture/agriculturecommon/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
<script defer src="https://cdn.sobekrepository.org/includes/gmaps-markerwithlabel/1.9.1/gmaps-markerwithlabel-1.9.1.js"></script>
<script src="https://www.gstatic.com/charts/loader.js"></script>
<script>
google.charts.load("current", {"packages":["line"]});
<!--42 is for version 42 cause there is a bug that causes the charts popups to flicker and version 42 did not have this issue.-->
google.charts.load("current", {"packages":["line", "corechart"]});
</script>
</head>
<body>
Expand Down
1 change: 1 addition & 0 deletions agriculture/agriculturecommon/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from django.urls import include, path

urlpatterns = [

path("access/", include("login.urls")),

path("", include("agriculturecore.urls")),
Expand Down
21 changes: 15 additions & 6 deletions agriculture/agriculturecore/drm_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,25 @@
DO_CMD_XBEE_DISCOVER = "<discover option='current' />"
DO_CMD_XBEE_SETTING = "<radio_command addr='{}' id='{}' format='{}' timeout='1000' />"

ID_WIND = "wind"
ID_WIND = "wind_speed"
ID_WIND_DIR = "wind_direction"
ID_RADIATION = "radiation"
ID_RAIN = "rain"
ID_RAIN_ACC = "rain_acc"
ID_RAIN = "rain_diff"
ID_LEVEL = "level"
ID_VALVE = "valve"
ID_TEMPERATURE = "temperature"
ID_PRESSURE = "pressure"
ID_LUMINOSITY = "luminosity"
ID_BATTERY = "battery"
ID_MOISTURE = "moisture"

ID_CONTROLLERS = "controllers"
ID_ERROR = "error"
ID_STATIONS = "stations"
ID_WEATHER = "weather"
ID_TANK = "tank"

ID_ERROR = "error"

REGEX_DEV_REQUEST_RESPONSE = ".*<device_request .*>(.*)<\\/device_request>.*"
REGEX_DO_CMD_RESPONSE = ".*<do_command target=[^>]*>(.*)<\\/do_command>.*"

Expand Down Expand Up @@ -150,10 +153,8 @@ def check_ajax_request(request):
"""
Checks whether the given AJAX request is valid and the user is
authenticated.

Args:
request (:class:`.WSGIRequest`): The HTTP request.

Returns:
`None` if the request is valid, or a `JsonResponse` with the error
if it is not.
Expand Down Expand Up @@ -629,10 +630,18 @@ def get_general_farm_status(request, device_id, stations):
# Weather station.
if stream_id == STREAM_FORMAT_CONTROLLER.format(device_id, ID_WIND):
status[ID_WEATHER][ID_WIND] = data
elif stream_id == STREAM_FORMAT_CONTROLLER.format(device_id, ID_WIND_DIR):
status[ID_WEATHER][ID_WIND_DIR] = data
elif stream_id == STREAM_FORMAT_CONTROLLER.format(device_id, ID_LUMINOSITY):
status[ID_WEATHER][ID_LUMINOSITY] = data
elif stream_id == STREAM_FORMAT_CONTROLLER.format(device_id, ID_RAIN_ACC):
status[ID_WEATHER][ID_RAIN_ACC] = data
elif stream_id == STREAM_FORMAT_CONTROLLER.format(device_id, ID_RAIN):
status[ID_WEATHER][ID_RAIN] = data
elif stream_id == STREAM_FORMAT_CONTROLLER.format(device_id, ID_RADIATION):
status[ID_WEATHER][ID_RADIATION] = data
elif stream_id == STREAM_FORMAT_CONTROLLER.format(device_id, ID_TEMPERATURE):
status[ID_WEATHER][ID_TEMPERATURE] = data
# Water tank.
elif stream_id == STREAM_FORMAT_CONTROLLER.format(device_id, ID_LEVEL):
status[ID_TANK][ID_LEVEL] = data
Expand Down
6 changes: 3 additions & 3 deletions agriculture/agriculturecore/templates/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ <h6 class="card-title">Weather station</h6>
<td><span class="digi-icon-color fas fa-sun fa-2x"></span></td>
</tr>
<tr>
<td><span id="wind"><i class="fas fa-circle-notch fa-spin"></i></span> km/h</td>
<td><span id="rain"><i class="fas fa-circle-notch fa-spin"></i></span> L/m²</td>
<td><span id="radiation"><i class="fas fa-circle-notch fa-spin"></i></span> W/m²</td>
<td><span id="wind_speed"><i class="fas fa-circle-notch fa-spin"></i></span> km/h (<span id="wind_direction"><i class="fas fa-circle-notch fa-spin"></i></span>)</td>
<td><span id="rain_acc"><i class="fas fa-circle-notch fa-spin"></i></span> L/m²</td>
<td><span id="luminosity"><i class="fas fa-circle-notch fa-spin"></i></span> lux</td>
</tr>
</tbody>
</table>
Expand Down
60 changes: 46 additions & 14 deletions agriculture/agriculturecore/templates/history.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
<div class="card-body">
<h5 class="card-title">Historic data: Irrigation controller</h5>
<div class="row">
<div class="col-xl-4 chart-container">
<div class="col-xl-6 chart-container">
<div class="d-flex justify-content-center align-items-center">
<span class="fas fa-wind fa-2x mr-3"></span>
<span>Wind speed</span>
<span>Wind</span>
</div>
<div class="chart-wrapper">
<div id="wind-chart" class="big-chart"></div>
Expand All @@ -36,7 +36,7 @@ <h5 class="card-title">Historic data: Irrigation controller</h5>
</label>
</div>
</div>
<div class="col-xl-4 chart-container">
<div class="col-xl-6 chart-container">
<div class="d-flex justify-content-center align-items-center">
<span class="fas fa-cloud-rain fa-2x mr-3"></span>
<span>Rain</span>
Expand All @@ -62,32 +62,58 @@ <h5 class="card-title">Historic data: Irrigation controller</h5>
</label>
</div>
</div>
<div class="col-xl-4 chart-container">
<div class="col-xl-6 chart-container">
<div class="d-flex justify-content-center align-items-center">
<span class="fas fa-sun fa-2x mr-3"></span>
<span>Solar radiation</span>
<span>Luminosity</span>
</div>
<div class="chart-wrapper">
<div id="radiation-chart" class="big-chart"></div>
<div id="radiation-chart-loading" class="chart-loading">
<div id="luminosity-chart" class="big-chart"></div>
<div id="luminosity-chart-loading" class="chart-loading">
<img class="loading-chart-image" src="{% static 'images/loading.gif' %}" alt="Loading..." />
</div>
</div>
<div class="btn-group btn-group-toggle d-flex justify-content-center" data-toggle="buttons">
<label class="btn btn-secondary btn-sm active">
<input type="radio" name="radiation-interval" value="1" checked> Hour
<input type="radio" name="luminosity-interval" value="1" checked> Hour
</label>
<label class="btn btn-secondary btn-sm">
<input type="radio" name="radiation-interval" value="24"> Day
<input type="radio" name="luminosity-interval" value="24"> Day
</label>
<label class="btn btn-secondary btn-sm">
<input type="radio" name="radiation-interval" value="168"> Week
<input type="radio" name="luminosity-interval" value="168"> Week
</label>
<label class="btn btn-secondary btn-sm">
<input type="radio" name="radiation-interval" value="720"> Month
<input type="radio" name="luminosity-interval" value="720"> Month
</label>
</div>
</div>
<div class='col-xl-6 chart-container'>
<div class='d-flex justify-content-center align-items-center'>
<span class='fas fa-thermometer-half fa-2x mr-3'></span>
<span>Temperature</span>
</div>
<div class='chart-wrapper'>
<div id='temperature-chart' class='big-chart'></div>
<div id='temperature-chart-loading' class='chart-loading'>
<img class='loading-chart-image' src='../static/images/loading.gif' alt='Loading...' />
</div>
</div>
<div class='btn-group btn-group-toggle d-flex justify-content-center' data-toggle='buttons'>
<label class='btn btn-secondary btn-sm active'>
<input type='radio' name='temperature-interval' value='1' checked> Hour
</label>
<label class='btn btn-secondary btn-sm'>
<input type='radio' name='temperature-interval' value='24'> Day
</label>
<label class='btn btn-secondary btn-sm'>
<input type='radio' name='temperature-interval' value='168'> Week
</label>
<label class='btn btn-secondary btn-sm'>
<input type='radio' name='temperature-interval' value='720'> Month
</label>
</div>
</div>
</div>
</div>
</div>
Expand All @@ -113,9 +139,14 @@ <h5 class="card-title">Historic data: Irrigation controller</h5>
drawRainChart(true, true);
});

$("input[type=radio][name=radiation-interval]").change(function() {
radiationInterval = this.value;
drawRadiationChart(true, true);
$("input[type=radio][name=luminosity-interval]").change(function() {
luminosityInterval = this.value;
drawLuminosityChart(true, true);
});

$("input[type=radio][name=temperature-interval]").change(function() {
temperatureInterval = this.value;
drawTemperatureChartG(true, true);
});
});

Expand All @@ -124,4 +155,5 @@ <h5 class="card-title">Historic data: Irrigation controller</h5>
drawAllCharts();
});
</script>
<style>div.google-visualization-tooltip { width:150px;}</style>
{% endblock %}
26 changes: 6 additions & 20 deletions agriculture/agriculturecore/templates/sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,7 @@
<img id="simulation-logo" class="banner-icon" src="{% static 'images/simulation.png' %}">
</button>
<div class="dropdown-menu shadow-sm simulation-controls-container" aria-labelledby="simulationMenuButton">
<p>Simulation controls</p>
<div class="card">
<p class="widget-title">Weather condition</p>
<p class="widget-desc">Control the weather condition of the farm. You can change it to see different temperature and moisture values.</p>
<div class="widget-button-container">
<button id="weather-sunny" class="btn widget-button weather-button" type="button" value="0">
<span id="weather-sunny-logo" class="icon-widget weather-icon fas fa-sun fa-2x" title="Change weather to sunny"></span>
</button>
<button id="weather-cloudy" class="btn widget-button weather-button" type="button" value="1">
<span id="weather-cloudy-logo" class="icon-widget weather-icon fas fa-cloud fa-2x" title="Change weather to cloudy"></span>
</button>
<button id="weather-rainy" class="btn widget-button weather-button" type="button" value="2">
<span id="weather-rainy-logo" class="icon-widget weather-icon fas fa-cloud-rain fa-2x" title="Change weather to rainy"></span>
</button>
</div>
</div>
<p>Simulation control</p>
<div class="card">
<p class="widget-title">Time</p>
<p class="widget-desc">Control how the time elapses in the farm. You can change it to see the irrigation events faster.</p>
Expand Down Expand Up @@ -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.
Expand All @@ -223,7 +209,7 @@
function getControllerID() {
return '{{ controller_id }}';
}

// Gets the status of the farm.
function verifyParameters() {
let url = new URL(window.location.href);
Expand Down
3 changes: 3 additions & 0 deletions agriculture/agriculturecore/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
Loading