Code cleanup and re-org

Change-Id: Ifed47cfd5113be790eb57d92d4585b1427b56464
diff --git a/person_detection/mqtt.py b/person_detection/action.py
similarity index 82%
rename from person_detection/mqtt.py
rename to person_detection/action.py
index ce40411..5cd241f 100644
--- a/person_detection/mqtt.py
+++ b/person_detection/action.py
@@ -5,6 +5,8 @@
 import threading
 import logging as log
 
+import roc
+
 mqttBroker ="localhost"
 
 resolution = {}
@@ -16,7 +18,7 @@
     timestamp[device] = time.time()
     if device in resolution and resolution[device] == "high":
         return
-    set_resolution(device, "high")
+    set_resolution_high(device)
 
 
 def start_timer(device):
@@ -29,6 +31,16 @@
     del timer[device]
 
 
+def set_resolution_high(device):
+    set_resolution(device, "high")
+    roc.set_uplink_mbr_high()
+
+
+def set_resolution_low(device):
+    set_resolution(device, "low")
+    roc.set_uplink_mbr_low()
+
+
 def set_resolution(device, level):
     log.info("Setting camera {} resolution to {}".format(device, level))
     resolution[device] = level
@@ -44,7 +56,7 @@
     diff = now - timestamp[device]
     # log.info("timer_expiry() - now:{}, timestamp:{}".format(now, timestamp[device]))
     if diff > 5.0:
-        set_resolution(device, "low")
+        set_resolution_low(device)
         remove_timer(device)
     else:
         start_timer(device)
diff --git a/person_detection/app.py b/person_detection/app.py
index 1386d63..87a2cd9 100644
--- a/person_detection/app.py
+++ b/person_detection/app.py
@@ -8,15 +8,8 @@
 from flask import Flask, render_template, Response
 from argparse import ArgumentParser, SUPPRESS
 
-# import camera driver
-if os.environ.get('CAMERA'):
-    Camera = import_module('camera_' + os.environ['CAMERA']).Camera
-else:
-    # from camera import Camera
-    from person_detection import Camera
+from person_detection import Camera
 
-# Raspberry Pi camera module (requires picamera package)
-# from camera_pi import Camera
 
 app = Flask(__name__)
 
diff --git a/person_detection/person_detection.py b/person_detection/person_detection.py
index 92a5e4a..47a3fcf 100644
--- a/person_detection/person_detection.py
+++ b/person_detection/person_detection.py
@@ -17,15 +17,11 @@
 
 from base_camera import BaseCamera
 
-import mqtt
+import action
 
 Shape = namedtuple('Shape', ['n','c','h','w'])
 
 class Camera(BaseCamera):
-    model = None
-    prob_threshold = 0.0
-    input = None
-    device = None
 
     def __init__(self, device, args):
         log.basicConfig(format="[ %(levelname)s ] %(message)s", level=log.INFO, stream=sys.stdout)
@@ -33,9 +29,7 @@
         self.model_xml = args.model
         self.input = args.input
         self.prob_threshold = args.prob_threshold
-
         self.is_async_mode = True
-
         self.device = device
 
         super(Camera, self).__init__(device, args.idle)
@@ -148,7 +142,7 @@
                         cv2.FONT_HERSHEY_COMPLEX, 0.6, black, 1)
 
                 if obj_count > 0:
-                    mqtt.person_detected(self.device, obj_count)
+                    action.person_detected(self.device, obj_count)
 
             yield cv2.imencode('.jpg', frame)[1].tobytes()
 
diff --git a/person_detection/roc.py b/person_detection/roc.py
index ecf7e77..96d4ac5 100644
--- a/person_detection/roc.py
+++ b/person_detection/roc.py
@@ -8,7 +8,8 @@
 from requests.structures import CaseInsensitiveDict
 
 
-TOKEN = "### A VALID TOKEN ###"
+TOKEN = "eyJhbGciOiJSUzI1NiIsImtpZCI6IjU0MzE3MDI4ZWJjNGZjNzFkNGUyZDdlODQwN2M2NTI4MWU5ZmYzYTgifQ.eyJpc3MiOiJodHRwczovL2RleC5hZXRoZXJwcm9qZWN0Lm9yZy9kZXgiLCJzdWIiOiJDaXN4TmpNNE5ERTZPRGMxWlRNeU5qY3RZakkwT1MwME9XTXdMV0V5TW1ZdE1qUmlaalUyWXprNVpEazFFZ1ZqY205M1pBIiwiYXVkIjoiYWV0aGVyLXJvYy1ndWkiLCJleHAiOjE2Mzg2MzkwNTQsImlhdCI6MTYzODU1MjY1NCwibm9uY2UiOiJkemw0TkZGb1RDMDBjVWxyVlRsMmJVTTVRekJvY3pCRVQzZEVWbWxKVlU5UVZXVlBjSFpoTm14NU1ERnIiLCJhdF9oYXNoIjoiWElONGprZzdyeWRzVVRROVBjekVZZyIsImNfaGFzaCI6IlZuSng4cklpSGRYeWFjSi0yaVgyaEEiLCJlbWFpbCI6InNoYWRAb3Blbm5ldHdvcmtpbmcub3JnIiwiZW1haWxfdmVyaWZpZWQiOnRydWUsImdyb3VwcyI6WyJBZXRoZXJST0NBZG1pbiIsIk9ORlN0YWZmIl0sIm5hbWUiOiJzaGFkIiwicHJlZmVycmVkX3VzZXJuYW1lIjoic2hhZCJ9.F6v3q5RuJVUm-4BPcj02IOoDL5grsmjlYzGJSvuM7R9lCIWXI-Qi6Xb-rgLtCBH3qGhWHuk8abd7ud2ipYDnpLybavJOB8iPr_I-lBy6MFxriTxp6OipeZ5nxAXyt9iyslNcLTTmzapsV5Blzl5xvzwOqCItV9dIRVtDNYPiU5CYEA69Eu8Gy8d_0URmI5re26LaBzJ8EHu1KHuhTh3RoExZUHyCagrTmtUnLkep9jXOTszGoKW2Qw7p2H3d-vHIAVGCx2JBERQC8zAalIaajTZ_gc8lqgzsYauSbHIVdm7o5AesL_dCOJQF1E-FTXDOdVMHVmos7BDchr9jui5_Dg"
+### A VALID TOKEN ###"
 
 URL = "https://roc.menlo.aetherproject.org/aether-roc-api/aether/v4.0.0/connectivity-service-v4/"
 #URL = "https://roc.staging.aether.onlab.us/aether-roc-api/aether/v4.0.0/connectivity-service-v4/"
@@ -16,8 +17,8 @@
 cameras = "menlo-4g-cameras"
 #cameras = "cameras-4g"
 
-MBR_HIGH = 4000000
-MBR_LOW = 2000000
+MBR_HIGH = 5000000
+MBR_LOW  = 2000000
 
 roc_headers = CaseInsensitiveDict()
 roc_headers["Content-Type"] = "application/json"
@@ -26,7 +27,9 @@
 def get_mbr(device_group):
     url = URL + "vcs/vcs/vcs-{}/slice/mbr".format(device_group)
     response = requests.get(url, headers=roc_headers)
-    assert response.status_code == 200, "Failed to get mbr"
+    if response.status_code != 200:
+        print("Failed to get mbr, status_code: {}".format(response.status_code))
+        return None
     mbr = json.loads(response.text)
     return mbr
 
@@ -34,6 +37,8 @@
     url = URL + "vcs/vcs/vcs-{}/slice/mbr".format(device_group)
     response = requests.post(url, headers=roc_headers, json=mbr)
     assert response.status_code == 201, "Failed to set mbr"
+    if response.status_code != 201:
+        print("Failed to set mbr, device_group:{}, mbr:{}, status_code: {}".format(device_group, mbr, response.status_code))
 
 def set_uplink_mbr_high():
     mbr = {'uplink' : MBR_HIGH}