def robot_router(request, core): if compare_match(request.path, "/iot_core/robot/status/"): return robot_status_router(request, core) if compare_match(request.path, "/iot_core/robot/address/"): return robot_address_router(request, core) rdict = {"Error": "Unknown request"} return JsonResponse(rdict, status=400)
def light_router(request, core): if compare_match(request.path, "/iot_core/light/spectro/"): return light_spectro_router(request, core) if compare_match(request.path, "/iot_core/light/status/"): return light_status_router(request, core) rdict = {"Error": "Unknown request"} return JsonResponse(rdict, status=400)
def iot_core_router(request): if compare_match(request.path, "/iot_core/login/"): return login(request) if request.user.is_authenticated == False: rdict = {"Error": "Not logged in"} return JsonResponse(rdict, status=400) # check core_id, cluster_id here core_id = int(request.user.username.replace("core_id_", "")) try: core = iotCore.objects.get(core_id=core_id) except: rdict = {"Error": "Server error"} return JsonResponse(rdict, status=400) rdict = check_iot_core(request) if "Error" in rdict: return JsonResponse(rdict, status=400) # see if logged in; otherwise error if compare_match(request.path, "/iot_core/air/"): return air_router(request, core) if compare_match(request.path, "/iot_core/water/"): return water_router(request, core) if compare_match(request.path, "/iot_core/light/"): return light_router(request, core) if compare_match(request.path, "/iot_core/robot/"): return robot_router(request, core) rdict = {"Error": "Unknown request"} return JsonResponse(rdict, status=400)
def water_router(request, core): if compare_match(request.path, "/iot_core/water/temp/"): return water_temp_router(request, core) if compare_match(request.path, "/iot_core/water/ph/"): return water_ph_router(request, core) if compare_match(request.path, "/iot_core/water/conduct/"): return water_conduct_router(request, core) rdict = {"Error": "Unknown request"} return JsonResponse(rdict, status=400)
def web_app_router(request): if compare_match(request.path, "/web_app/login/"): return login(request) access_token = request.META.get("HTTP_ACCESS_TOKEN") if access_token is None: rdict = {"Error": "No access-token header"} return JsonResponse(rdict, status=400) verification, user = verify_access_token(access_token) if compare_match(request.path, "/web_app/verify_token/"): return verify_token(request, verification) if verification == False: rdict = {"Error": "Not logged in"} return JsonResponse(rdict, status=400) if compare_match(request.path, "/web_app/farm_access/"): return farm_access(request, user) if compare_match(request.path, "/web_app/farm_summary/"): return farm_summary(request, user) if compare_match(request.path, "/web_app/channel_summary/"): return channel_summary(request, user) if compare_match(request.path, "/web_app/robot_summary/"): return robot_summary(request, user) if compare_match(request.path, "/web_app/channel_update/light/"): return channel_update_light(request, user) if compare_match(request.path, "/web_app/channel_update/water/"): return channel_update_water(request, user) if compare_match(request.path, "/web_app/channel_update/water_temp/"): return channel_update_water_temp(request, user) rdict = {"Error": "Unknown request type"} return JsonResponse(rdict, status=400)
def air_router(request, core): if compare_match(request.path, "/iot_core/air/temp/"): return air_temp_router(request, core) if compare_match(request.path, "/iot_core/air/co2/"): return air_co2_router(request, core) if compare_match(request.path, "/iot_core/air/tvoc/"): return air_tvoc_router(request, core) if compare_match(request.path, "/iot_core/air/pressure/"): return air_pressure_router(request, core) if compare_match(request.path, "/iot_core/air/humidity/"): return air_humidity_router(request, core) rdict = {"Error": "Unknown request"} return JsonResponse(rdict, status=400)