Skip to content

Commit cdb8ce0

Browse files
committed
agriculture: dashboard works completely without any weather condition controls.
Signed-off-by: Victor Coman <victor.coman@digi.com>
1 parent 4cb358e commit cdb8ce0

File tree

4 files changed

+29
-61
lines changed

4 files changed

+29
-61
lines changed

agriculture/agriculturecore/drm_requests.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@
5656
ID_WIND = "wind_speed"
5757
ID_WIND_DIR = "wind_direction"
5858
ID_RADIATION = "radiation"
59-
ID_RAIN = "rain"
59+
ID_RAIN_ACC = "rain_acc"
60+
ID_RAIN = "rain_diff"
6061
ID_LEVEL = "level"
6162
ID_VALVE = "valve"
6263
ID_TEMPERATURE = "temperature"
@@ -603,10 +604,14 @@ def get_general_farm_status(request, device_id, stations):
603604
status[ID_WEATHER][ID_WIND_DIR] = data
604605
elif stream_id == STREAM_FORMAT_CONTROLLER.format(device_id, ID_LUMINOSITY):
605606
status[ID_WEATHER][ID_LUMINOSITY] = data
607+
elif stream_id == STREAM_FORMAT_CONTROLLER.format(device_id, ID_RAIN_ACC):
608+
status[ID_WEATHER][ID_RAIN_ACC] = data
606609
elif stream_id == STREAM_FORMAT_CONTROLLER.format(device_id, ID_RAIN):
607610
status[ID_WEATHER][ID_RAIN] = data
608611
elif stream_id == STREAM_FORMAT_CONTROLLER.format(device_id, ID_RADIATION):
609612
status[ID_WEATHER][ID_RADIATION] = data
613+
elif stream_id == STREAM_FORMAT_CONTROLLER.format(device_id, ID_TEMPERATURE):
614+
status[ID_WEATHER][ID_TEMPERATURE] = data
610615
# Water tank.
611616
elif stream_id == STREAM_FORMAT_CONTROLLER.format(device_id, ID_LEVEL):
612617
status[ID_TANK][ID_LEVEL] = data

agriculture/agriculturecore/templates/dashboard.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ <h6 class="card-title">Weather station</h6>
8989
</tr>
9090
<tr>
9191
<td><span id="wind_speed"><i class="fas fa-circle-notch fa-spin"></i></span> km/h</td>
92-
<td><span id="rain"><i class="fas fa-circle-notch fa-spin"></i></span> L/m²</td>
92+
<td><span id="rain_diff"><i class="fas fa-circle-notch fa-spin"></i></span> L/m²</td>
9393
<td><span id="luminosity"><i class="fas fa-circle-notch fa-spin"></i></span> lux</td>
9494
</tr>
9595
</tbody>

agriculture/static/js/dashboard.js

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ const CLASS_BUTTON_STATUS_OFF = "marker-info-button-off";
8989
const ID_WIND = "wind_speed";
9090
const ID_RADIATION = "radiation";
9191
const ID_LUMINOSITY = "luminosity";
92-
const ID_RAIN = "rain";
92+
const ID_RAIN = "rain_diff";
93+
const ID_RAIN_ACC = "rain";
9394
const ID_LEVEL = "level";
9495
const ID_VALVE = "valve";
9596
const ID_TEMPERATURE = "temperature";
@@ -135,6 +136,7 @@ var controllerWind = null;
135136
var controllerRain = null;
136137
var controllerRadiation = null;
137138
var controllerLuminosity = null;
139+
var controllerTemperature = null;
138140

139141
var tankValve;
140142
var waterLevel;
@@ -148,7 +150,6 @@ var currentWeatherIcon;
148150
var currentWeatherStatus;
149151
var avgTemp = 23.0; // Define initial value for the temperature so if no stations are registered the weather forecast can be displayed.
150152

151-
152153
var bounds;
153154

154155
var markersZIndex = 0;
@@ -275,13 +276,13 @@ function processFarmStatusResponse(response, first) {
275276
updateCurrentWeather();
276277
});
277278
drawDevices(response);
278-
updateWeatherWidget();
279279
}
280280
updateStationsStatus(response);
281281
updateStationCounters(response);
282282
updateWeatherStation(response);
283283
updateWaterTank(response);
284284
updateCurrentWeather();
285+
updateWeatherWidget();
285286

286287
// Hide the station loading.
287288
loadingStationsStatus = false;
@@ -533,6 +534,13 @@ function updateWeatherStation(response) {
533534
let controllerLuminosityInfowElement = document.getElementById("infow-luminosity");
534535
if (controllerLuminosityInfowElement != null)
535536
controllerLuminosityInfowElement.innerText = weatherStationStatus[ID_LUMINOSITY];
537+
538+
// Update the temperature value.
539+
controllerTemperature = weatherStationStatus[ID_TEMPERATURE];
540+
avgTemp = weatherStationStatus[ID_TEMPERATURE];
541+
let controllerTemperatureElement = document.getElementById("current-temp");
542+
if (controllerTemperatureElement != null)
543+
controllerTemperatureElement.innerText = weatherStationStatus[ID_TEMPERATURE];
536544
}
537545

538546
// Updates the water tank information based on the given response.
@@ -905,15 +913,22 @@ function updateWeatherWidget() {
905913
// Updates the current weather data (icon, temperature and status).
906914
function updateCurrentWeather() {
907915
// Calculate average temperature.
908-
calculateAvgTemp();
916+
//calculateAvgTemp();
909917

910918
// Identify the current weather icon to use.
911919
currentWeatherIcon = SUN_GREEN;
912920
currentWeatherStatus = "sunny";
913-
if ($("#weather-rainy-logo").hasClass("selected-icon-widget")) {
921+
922+
rain = document.getElementById("rain_diff").innerText;
923+
rain = parseInt(rain)
924+
luminosity = document.getElementById("luminosity").innerText;
925+
luminosity = parseInt(luminosity)
926+
927+
if(rain != 0){
914928
currentWeatherIcon = RAIN_GREEN;
915929
currentWeatherStatus = "rainy";
916-
} else if ($("#weather-cloudy-logo").hasClass("selected-icon-widget")) {
930+
}
931+
else if(rain == 0 && luminosity < 4000){
917932
currentWeatherIcon = CLOUD_GREEN;
918933
currentWeatherStatus = "cloudy";
919934
}
@@ -923,11 +938,6 @@ function updateCurrentWeather() {
923938
if (currentWeather != null)
924939
currentWeather.innerHTML = currentWeatherIcon;
925940

926-
// Update current temperature.
927-
let currentTemp = document.getElementById("current-temp");
928-
if (currentTemp != null)
929-
currentTemp.innerText = avgTemp;
930-
931941
// Update current weather status.
932942
let currentStatus = document.getElementById("current-status");
933943
if (currentStatus != null)

agriculture/static/js/widgets.js

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -14,36 +14,11 @@
1414
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1515
*/
1616

17+
1718
var currentTime;
1819
var currentTimeFactor;
1920
var timeWorker;
2021

21-
// Sets the new weather condition.
22-
function setWeatherCondition(e) {
23-
e.preventDefault();
24-
25-
var selected = $(this).attr("value");
26-
selectWeatherIcon(selected);
27-
28-
$.post("/ajax/set_condition", getJsonData(selected)).fail(function(response) {
29-
// If the operation fails, get the real condition.
30-
getWeatherCondition();
31-
}).fail(function(response) {
32-
processErrorResponse(response);
33-
});
34-
}
35-
36-
// Gets the current weather condition.
37-
function getWeatherCondition() {
38-
var data = getJsonData();
39-
40-
$.post("/ajax/get_condition", getJsonData(), function(response) {
41-
var resp = response["data"];
42-
selectWeatherIcon(resp);
43-
}).fail(function(response) {
44-
processErrorResponse(response);
45-
});
46-
}
4722

4823
// Sets the new time factor.
4924
function setTimeFactor(e) {
@@ -59,8 +34,6 @@ function setTimeFactor(e) {
5934
$.post("/ajax/set_factor", getJsonData(selected)).fail(function(response) {
6035
// If the operation fails, get the real factor.
6136
getTimeFactor();
62-
}).fail(function(response) {
63-
processErrorResponse(response);
6437
});
6538
}
6639

@@ -72,8 +45,6 @@ function getTimeFactor() {
7245
selectTimeIcon(currentTimeFactor);
7346
getCurrentTime();
7447
}
75-
}).fail(function(response) {
76-
processErrorResponse(response);
7748
});
7849
}
7950

@@ -88,27 +59,9 @@ function getCurrentTime() {
8859
};
8960
timeWorker.postMessage(currentTime + "@@@" + currentTimeFactor);
9061
}
91-
}).fail(function(response) {
92-
processErrorResponse(response);
9362
});
9463
}
9564

96-
// Marks the weather icon with the given value as selected.
97-
function selectWeatherIcon(value) {
98-
unselectWeatherIcons();
99-
if (value == document.getElementById("weather-sunny").value)
100-
$("#weather-sunny-logo").addClass("selected-icon-widget");
101-
else if (value == document.getElementById("weather-cloudy").value)
102-
$("#weather-cloudy-logo").addClass("selected-icon-widget");
103-
else if (value == document.getElementById("weather-rainy").value)
104-
$("#weather-rainy-logo").addClass("selected-icon-widget");
105-
}
106-
107-
// Unselects all the weather icons.
108-
function unselectWeatherIcons() {
109-
$(".weather-icon").removeClass("selected-icon-widget");
110-
}
111-
11265
// Marks the time icon with the given value as selected.
11366
function selectTimeIcon(value) {
11467
unselectTimeIcons();

0 commit comments

Comments
 (0)