-
Notifications
You must be signed in to change notification settings - Fork 3
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
base: master
Are you sure you want to change the base?
Changes from 10 commits
5e998f0
47f7eac
4cb358e
96697d5
cdb8ce0
6c88f65
464fdfe
971c6a9
4a20395
fcb4c35
3c8bbb9
be00e8b
43d9741
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
# Elastic Beanstalk Files | ||
.elasticbeanstalk/* | ||
!.elasticbeanstalk/*.cfg.yml | ||
!.elasticbeanstalk/*.global.yml |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
web: gunicorn --bind :8000 --workers 3 --threads 2 agriculturecommon.wsgi:application | ||
websocket: daphne -b :: -p 5000 agriculturecommon.asgi:application |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,12 +53,16 @@ | |
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" | ||
|
||
|
@@ -67,8 +71,6 @@ | |
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>.*" | ||
|
||
|
@@ -146,41 +148,6 @@ def get_device_cloud_session(session): | |
base_url=user_serialized.server) | ||
|
||
|
||
def check_ajax_request(request): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why all these changes (until line 543)? |
||
""" | ||
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. | ||
""" | ||
if is_authenticated(request): | ||
if not request.is_ajax or request.method != "POST": | ||
return JsonResponse({ID_ERROR: "AJAX request must be sent using POST"}, status=400) | ||
return None | ||
else: | ||
return JsonResponse({ID_ERROR: "Not authenticated"}, status=401) | ||
|
||
|
||
def get_exception_response(e): | ||
""" | ||
Returns the JSON response with the error contained in the given exception. | ||
|
||
Args: | ||
e (:class:`.Exception`): The exception. | ||
|
||
Returns: | ||
A JSON response with the details of the exception. | ||
""" | ||
return JsonResponse({ID_ERROR: ("Error in the DRM request: {}.".format(e.response.text) | ||
if isinstance(e, DeviceCloudHttpException) else str(e))}, | ||
status=400) | ||
|
||
|
||
def send_device_request(request, target): | ||
""" | ||
Sends a Device Request to DRM to the device with the given ID. | ||
|
@@ -192,12 +159,13 @@ def send_device_request(request, target): | |
Returns: | ||
A JSON with the response or the error. | ||
""" | ||
# Check if the AJAX request is valid. | ||
error = check_ajax_request(request) | ||
if error is not None: | ||
return error | ||
if not request.is_ajax or request.method != "POST": | ||
return JsonResponse({"error": "AJAX request must be sent using POST"}, | ||
status=400) | ||
|
||
dc = get_device_cloud(request) | ||
if dc is None: | ||
return JsonResponse({"error": "Invalid credentials."}, status=400) | ||
|
||
device_id = request.POST[views.PARAM_CONTROLLER_ID] | ||
data = request.POST[PARAM_DATA] if PARAM_DATA in request.POST else None | ||
|
@@ -208,7 +176,9 @@ def send_device_request(request, target): | |
return JsonResponse({"data": resp}, status=200) | ||
return JsonResponse({"valid": True}, status=200) | ||
except DeviceCloudHttpException as e: | ||
return get_exception_response(e) | ||
return JsonResponse( | ||
{"error": "Error in the DRM request: {}.".format(e.response.text)}, | ||
status=e.response.status_code) | ||
|
||
|
||
def send_request(dc, device_id, target, data=None): | ||
|
@@ -564,12 +534,13 @@ def get_data_points(request, stream_name): | |
Returns: | ||
A JSON with the data points or the error. | ||
""" | ||
# Check if the AJAX request is valid. | ||
error = check_ajax_request(request) | ||
if error is not None: | ||
return error | ||
if not request.is_ajax or request.method != "POST": | ||
return JsonResponse({"error": "AJAX request must be sent using POST"}, | ||
status=400) | ||
|
||
dc = get_device_cloud(request) | ||
if dc is None: | ||
return JsonResponse({"error": "Invalid credentials."}, status=400) | ||
|
||
device_id = request.POST[views.PARAM_CONTROLLER_ID] | ||
interval = int( | ||
|
@@ -629,10 +600,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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,9 +88,11 @@ <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>) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Either fill this space with the tag contained in the or put the tag right after the to avoid having this blank line. |
||
</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> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!DOCTYPE html> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file should not be committed, remove it. |
||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Title</title> | ||
</head> | ||
<body> | ||
|
||
</body> | ||
</html> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not be committed.